This repository has been archived by the owner on Sep 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#! /usr/bin/env mruby | ||
# -*- ruby -*- | ||
|
||
# This test provider does not use our Ruby provider framework because it | ||
# needs to generate errors that the framework would shield us from | ||
|
||
def describe | ||
puts <<EOS | ||
--- | ||
provider: | ||
type: json | ||
desc: | | ||
Test provider for the JSON provider harness | ||
invoke: json | ||
actions: [set, get] | ||
suitable: true | ||
attributes: | ||
name: | ||
ensure: | ||
type: enum[absent, present] | ||
message: | ||
EOS | ||
end | ||
|
||
ALL = [ "error_no_message", | ||
"error_no_kind", "error_message_is_array" ].map do |name| | ||
r = { name: name, ensure: "present" } | ||
if name != "error_no_message" | ||
r["message"] = name | ||
end | ||
r | ||
end | ||
|
||
ERRORS = { | ||
"error_no_message" => { error: { kind: "failed" } }, | ||
"error_no_kind" => { error: { message: "error_no_kind" } }, | ||
"error_message_is_array" => { error: | ||
{ message: [ "error_message_is_array", "more stuff" ], | ||
kind: "failed" } } | ||
} | ||
|
||
def get(names) | ||
if names.size > 0 | ||
name = names[0] | ||
if err = ERRORS[name] | ||
return err | ||
else | ||
return { resources: [ { name: name, ensure: "present" } ] } | ||
end | ||
else | ||
{ resources: ALL } | ||
end | ||
end | ||
|
||
def set(upds) | ||
upd=upds[0] | ||
name = upd.name.sub("set_", "") | ||
if err = ERRORS[name] | ||
return err | ||
end | ||
end | ||
|
||
# main | ||
action=ARGV[0].split("=").last | ||
|
||
if action == "describe" | ||
describe | ||
elsif action == "get" | ||
inp = JSON.load($stdin) | ||
puts JSON.dump(get(inp["names"])) | ||
elsif action == "set" | ||
inp = JSON.load($stdin) | ||
upds = inp["updates"].map do |upd| | ||
Ral::Update.new(upd["name"], upd["is"], upd["should"]) | ||
end | ||
puts JSON.dump(set(upds)) | ||
else | ||
puts JSON.dump({ error: { message: "Unknown action #{action}" } }) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <catch.hpp> | ||
#include <libral/ral.hpp> | ||
#include <iostream> | ||
#include <memory> | ||
|
||
#include <boost/optional/optional_io.hpp> | ||
#include "boost/filesystem.hpp" | ||
|
||
#include "fixtures.hpp" | ||
|
||
namespace libral { | ||
SCENARIO("json_provider harness") { | ||
auto aral = ral::create({ TEST_DATA_DIR }); | ||
auto json_type = *aral->find_type("json"); | ||
|
||
SECTION("behaves with invalid error messages") { | ||
auto all = json_type->instances(); | ||
REQUIRE(all.is_ok()); | ||
|
||
for(const auto &r0 : all.ok()) { | ||
auto res = json_type->find(r0.name()); | ||
REQUIRE(res.is_err()); | ||
|
||
// Every error message needs to contain the provider name | ||
REQUIRE_THAT(res.err().detail, Catch::Contains("[json::json]")); | ||
// The resources tell us in "message" if there are specific things | ||
// we should look for in the error message | ||
auto msg = r0.lookup<std::string>("message"); | ||
if (msg) { | ||
REQUIRE_THAT(res.err().detail, Catch::Contains(*msg)); | ||
} | ||
} | ||
|
||
// Now tickle the same error via an update | ||
for(const auto &r0 : all.ok()) { | ||
// The resource names for set need to be prefixed with 'set_' so we | ||
// do not trip the provider's get which happens before set is | ||
// called | ||
auto should = json_type->prov().create("set_" + r0.name()); | ||
should["ensure"] = "absent"; | ||
auto res = json_type->set(should); | ||
REQUIRE(res.is_err()); | ||
REQUIRE_THAT(res.err().detail, Catch::Contains("[json::json]")); | ||
auto msg = r0.lookup<std::string>("message"); | ||
if (msg) { | ||
REQUIRE_THAT(res.err().detail, Catch::Contains(*msg)); | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |