Skip to content

Commit

Permalink
Update specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthomas committed Jun 11, 2022
1 parent e0fdde6 commit a096830
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cosmos/lib/cosmos/models/interface_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions cosmos/lib/cosmos/models/tool_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions cosmos/spec/models/interface_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions cosmos/spec/models/microservice_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
16 changes: 14 additions & 2 deletions cosmos/spec/models/tool_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit a096830

Please sign in to comment.