1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
require "helper"
describe "v1 Transport Plugin" do
describe "empty v1 transport plugin" do
let(:plugin) { Class.new(Train.plugin(1)) }
let(:default_audit_log_options) {
{
enable_audit_log: false,
audit_log_location: nil,
audit_log_app_name: "train",
audit_log_size: nil,
audit_log_frequency: 0,
}
}
it "initializes an empty configuration" do
_(plugin.new.options).must_equal(default_audit_log_options)
end
it "saves the provided configuration" do
conf = default_audit_log_options.merge({ a: rand })
_(plugin.new(conf).options).must_equal(conf)
end
it "saves the provided configuration" do
conf = default_audit_log_options.merge({ a: rand })
_(plugin.new(conf).options).must_equal(conf)
end
it "provides a default logger" do
conf = { a: rand }
_(plugin.new(conf)
.method(:logger).call)
.must_be_instance_of(Logger)
end
it "can configure custom loggers" do
l = rand
_(plugin.new({ logger: l })
.method(:logger).call)
.must_equal(l)
end
it "provides a connection method" do
_ { plugin.new.connection }.must_raise Train::ClientError
end
end
describe "registered with a name" do
before do
Train::Plugins.registry.clear
end
it "doesnt have any plugins in the registry if none were configured" do
_(Train::Plugins.registry.empty?).must_equal true
end
it "is is added to the plugins registry" do
plugin_name = rand
_(Train::Plugins.registry).wont_include(plugin_name)
plugin = Class.new(Train.plugin(1)) do
name plugin_name
end
_(Train::Plugins.registry[plugin_name]).must_equal(plugin)
end
end
describe "with options" do
def train_class(opts = {})
name = rand.to_s
plugin = Class.new(Train.plugin(1)) do
option name, opts
end
[name, plugin]
end
it "exposes the parameters via api" do
name, plugin = train_class
_(plugin.default_options.keys).must_equal [name]
end
it "exposes the parameters via api" do
default = rand.to_s
name, plugin = train_class({ default: default })
_(plugin.default_options[name][:default]).must_equal default
end
it "option must be required" do
name, plugin = train_class(required: true)
_(plugin.default_options[name][:required]).must_equal true
end
it "default option must not be required" do
name, plugin = train_class
_(plugin.default_options[name][:required]).must_be_nil
end
it "can include options from another module" do
name_a, plugin_a = train_class
b = Class.new(Train.plugin(1)) do
include_options(plugin_a)
end
_(b.default_options[name_a]).wont_be_nil
end
it "overwrites existing options when including" do
old = rand.to_s
nu = rand.to_s
name_a, plugin_a = train_class({ default: nu })
b = Class.new(Train.plugin(1)) do
option name_a, default: old
include_options(plugin_a)
end
_(b.default_options[name_a][:default]).must_equal nu
end
end
end
|