From a09683079850ee9e9306829de630c96dfc8f5ddb Mon Sep 17 00:00:00 2001 From: "Thomas, Jason (Software)" Date: Sat, 11 Jun 2022 12:28:23 -0600 Subject: [PATCH] Update specs --- cosmos/lib/cosmos/models/interface_model.rb | 4 ++-- cosmos/lib/cosmos/models/tool_model.rb | 2 ++ cosmos/spec/models/interface_model_spec.rb | 11 +++++++++++ cosmos/spec/models/microservice_model_spec.rb | 16 ++++++++++++++-- cosmos/spec/models/tool_model_spec.rb | 16 ++++++++++++++-- 5 files changed, 43 insertions(+), 6 deletions(-) diff --git a/cosmos/lib/cosmos/models/interface_model.rb b/cosmos/lib/cosmos/models/interface_model.rb index ed2536461..de1c24ede 100644 --- a/cosmos/lib/cosmos/models/interface_model.rb +++ b/cosmos/lib/cosmos/models/interface_model.rb @@ -252,7 +252,7 @@ def deploy(gem_path, variables, validate_only: false) unless validate_only microservice.create microservice.deploy(gem_path, variables) - ConfigTopic.write({ kind: 'created', type: type.downcase, name: microservice_name, plugin: @plugin }, scope: @scope) + ConfigTopic.write({ kind: 'created', type: type.downcase, name: @name, plugin: @plugin }, scope: @scope) Logger.info "Configured #{type.downcase} microservice #{microservice_name}" end microservice @@ -267,7 +267,7 @@ def undeploy model = MicroserviceModel.get_model(name: name, scope: @scope) if model model.destroy - ConfigTopic.write({ kind: 'deleted', type: type.downcase, name: name, plugin: @plugin }, scope: @scope) + ConfigTopic.write({ kind: 'deleted', type: type.downcase, name: @name, plugin: @plugin }, scope: @scope) end if type == 'INTERFACE' diff --git a/cosmos/lib/cosmos/models/tool_model.rb b/cosmos/lib/cosmos/models/tool_model.rb index a8c7c91f2..07ea4ceb9 100644 --- a/cosmos/lib/cosmos/models/tool_model.rb +++ b/cosmos/lib/cosmos/models/tool_model.rb @@ -230,6 +230,7 @@ def deploy(gem_path, variables, validate_only: false) unless validate_only cache_control = Cosmos::S3Utilities.get_cache_control(filename) Aws::S3::Client.new.put_object(bucket: 'tools', content_type: content_type, cache_control: cache_control, key: key, body: data) + ConfigTopic.write({ kind: 'created', type: 'tool', name: @folder_name, plugin: @plugin }, scope: @scope) end end end @@ -240,6 +241,7 @@ def undeploy prefix = "#{@folder_name}/" rubys3_client.list_objects(bucket: 'tools', prefix: prefix).contents.each do |object| rubys3_client.delete_object(bucket: 'tools', key: object.key) + ConfigTopic.write({ kind: 'deleted', type: 'tool', name: @folder_name, plugin: @plugin }, scope: @scope) end end end diff --git a/cosmos/spec/models/interface_model_spec.rb b/cosmos/spec/models/interface_model_spec.rb index 13238ffda..020fce554 100644 --- a/cosmos/spec/models/interface_model_spec.rb +++ b/cosmos/spec/models/interface_model_spec.rb @@ -233,7 +233,18 @@ module Cosmos model = InterfaceModel.new(name: "TEST_INT", scope: "DEFAULT", plugin: "PLUG") model.create model.deploy(dir, variables) + config = ConfigTopic.read(scope: 'DEFAULT') + expect(config[0][1]['kind']).to eql 'created' + expect(config[0][1]['type']).to eql 'interface' + expect(config[0][1]['name']).to eql 'TEST_INT' + expect(config[0][1]['plugin']).to eql 'PLUG' + model.undeploy + config = ConfigTopic.read(scope: 'DEFAULT') + expect(config[0][1]['kind']).to eql 'deleted' + expect(config[0][1]['type']).to eql 'interface' + expect(config[0][1]['name']).to eql 'TEST_INT' + expect(config[0][1]['plugin']).to eql 'PLUG' end end end diff --git a/cosmos/spec/models/microservice_model_spec.rb b/cosmos/spec/models/microservice_model_spec.rb index 7bcdae03c..8b75c0ee8 100644 --- a/cosmos/spec/models/microservice_model_spec.rb +++ b/cosmos/spec/models/microservice_model_spec.rb @@ -190,9 +190,15 @@ module Cosmos dir = File.join(SPEC_DIR, "install") expect(s3).to receive(:put_object).with(bucket: 'config', key: "#{scope}/microservices/#{name}/example_target.rb", body: anything) - model = MicroserviceModel.new(folder_name: folder, name: name, scope: scope) + model = MicroserviceModel.new(folder_name: folder, name: name, scope: scope, plugin: 'PLUGIN') model.create model.deploy(dir, {}) + + config = ConfigTopic.read(scope: 'DEFAULT') + expect(config[0][1]['kind']).to eql 'created' + expect(config[0][1]['type']).to eql 'microservice' + expect(config[0][1]['name']).to eql name + expect(config[0][1]['plugin']).to eql 'PLUGIN' end end @@ -210,8 +216,14 @@ module Cosmos expect(s3).to receive(:list_objects).with(bucket: 'config', prefix: "#{scope}/microservices/#{name}/").and_return(objs) expect(s3).to receive(:delete_object).with(bucket: 'config', key: "blah") - model = MicroserviceModel.new(folder_name: folder, name: name, scope: scope) + model = MicroserviceModel.new(folder_name: folder, name: name, scope: scope, plugin: 'PLUGIN') model.undeploy + + config = ConfigTopic.read(scope: 'DEFAULT') + expect(config[0][1]['kind']).to eql 'deleted' + expect(config[0][1]['type']).to eql 'microservice' + expect(config[0][1]['name']).to eql name + expect(config[0][1]['plugin']).to eql 'PLUGIN' end end end diff --git a/cosmos/spec/models/tool_model_spec.rb b/cosmos/spec/models/tool_model_spec.rb index 2afac6ae1..fd0ca24ff 100644 --- a/cosmos/spec/models/tool_model_spec.rb +++ b/cosmos/spec/models/tool_model_spec.rb @@ -172,9 +172,15 @@ module Cosmos expect(s3).to receive(:head_bucket) expect(s3).to receive(:put_object).with(bucket: 'tools', key: "#{name}/index.html", body: anything, cache_control: "no-cache", content_type: "text/html") - model = ToolModel.new(folder_name: folder, name: name, scope: scope) + model = ToolModel.new(folder_name: folder, name: name, scope: scope, plugin: 'PLUGIN') model.create model.deploy(dir, {}) + + config = ConfigTopic.read(scope: 'DEFAULT') + expect(config[0][1]['kind']).to eql 'created' + expect(config[0][1]['type']).to eql 'tool' + expect(config[0][1]['name']).to eql name + expect(config[0][1]['plugin']).to eql 'PLUGIN' end end @@ -192,8 +198,14 @@ module Cosmos expect(s3).to receive(:list_objects).with(bucket: 'tools', prefix: "#{name}/").and_return(objs) expect(s3).to receive(:delete_object).with(bucket: 'tools', key: "blah") - model = ToolModel.new(folder_name: folder, name: name, scope: scope) + model = ToolModel.new(folder_name: folder, name: name, scope: scope, plugin: 'PLUGIN') model.undeploy + + config = ConfigTopic.read(scope: 'DEFAULT') + expect(config[0][1]['kind']).to eql 'deleted' + expect(config[0][1]['type']).to eql 'tool' + expect(config[0][1]['name']).to eql name + expect(config[0][1]['plugin']).to eql 'PLUGIN' end end end