dumbwaiter 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d02466f683759df1f7d27af7a349ce83de12c41c
4
- data.tar.gz: 5ecab858e33074f2788bbeff38b7c0851bb63599
3
+ metadata.gz: 94944ee58a46b0164e4f7937fcc3b066213f042c
4
+ data.tar.gz: 50cdfe19a328a832ff374dc68cbe50900e090b0e
5
5
  SHA512:
6
- metadata.gz: d14fed084083d8192e0ea94905a1088260e74f297775ea8253327d613ba74ea83e846f5a621f76e406e5a522212720248adaa08b693a0634bcb3bf1f3c48923b
7
- data.tar.gz: 77196fefac097ad52c90d365f64c3de61182f6f5f90913bd21cc2aac92cd5f6856c4aab9e6318bb55b0818b9b8c14b71bbd75a33f43d9c9c12360f6eba7e0743
6
+ metadata.gz: 0ca9bbc6e30aa1b6dee2a134d419c7180c5586979f83f7c633971de0800eb2f8e2966bb8252f13627b07e082ee5dcef1a95338b9f1359dff34adb90eea7ee9cd
7
+ data.tar.gz: fdedb2834345c6a697cf7ff8664473bfd494fc100a396afe13d8e4969c70f294da1269cd7965647da53a998146737e5faa44ff1271534061cba82a39123a2888
data/dumbwaiter.gemspec CHANGED
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "bundler", "~> 1.3"
26
26
  spec.add_development_dependency "gem-release"
27
27
  spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "faker"
28
29
  end
@@ -35,6 +35,14 @@ class Dumbwaiter::App
35
35
  opsworks_app.app_id
36
36
  end
37
37
 
38
+ def url
39
+ opsworks_app.app_source.url
40
+ end
41
+
42
+ def revision
43
+ opsworks_app.app_source.revision || "master"
44
+ end
45
+
38
46
  def deploy(revision = nil)
39
47
  deployment = as_deployment("deploy", args: {migrate: ["true"]})
40
48
  unless revision.nil?
@@ -2,13 +2,14 @@ require "dumbwaiter/deployment_custom_json"
2
2
  require "dumbwaiter/user_profile"
3
3
 
4
4
  class Dumbwaiter::Deployment
5
- attr_reader :opsworks_deployment, :opsworks
5
+ attr_reader :stack, :opsworks_deployment, :opsworks
6
6
 
7
7
  def self.all(stack, opsworks = Aws::OpsWorks.new(region: "us-east-1"))
8
- opsworks.describe_deployments(stack_id: stack.id).deployments.map { |d| new(d, opsworks) }
8
+ opsworks.describe_deployments(stack_id: stack.id).deployments.map { |d| new(stack, d, opsworks) }
9
9
  end
10
10
 
11
- def initialize(opsworks_deployment, opsworks = Aws::OpsWorks.new(region: "us-east-1"))
11
+ def initialize(stack, opsworks_deployment, opsworks = Aws::OpsWorks.new(region: "us-east-1"))
12
+ @stack = stack
12
13
  @opsworks_deployment = opsworks_deployment
13
14
  @opsworks = opsworks
14
15
  end
@@ -30,23 +31,31 @@ class Dumbwaiter::Deployment
30
31
  end
31
32
 
32
33
  def user_name
33
- if opsworks_deployment.iam_user_arn.nil?
34
- "?"
34
+ if opsworks_deployment.iam_user_arn.nil? || user_profile.nil?
35
+ "OpsWorks"
35
36
  else
36
37
  user_profile.name
37
38
  end
38
39
  end
39
40
 
40
- def git_ref
41
- deployment_custom_json.git_ref
41
+ def revision
42
+ deployment_custom_json.revision || "#{app.revision}@{#{created_at}}"
42
43
  end
43
44
 
44
45
  def to_log
45
- "#{created_at} - #{user_name} - #{command_name} - #{status} - #{git_ref}"
46
+ if command_name == "deploy"
47
+ "#{created_at} - #{user_name} - #{command_name} - #{status} - #{revision}"
48
+ else
49
+ "#{created_at} - #{user_name} - #{command_name} - #{status}"
50
+ end
46
51
  end
47
52
 
48
53
  protected
49
54
 
55
+ def app
56
+ Dumbwaiter::App.find_by_id(stack, opsworks_deployment.app_id, opsworks)
57
+ end
58
+
50
59
  def user_profile
51
60
  Dumbwaiter::UserProfile.find(opsworks_deployment.iam_user_arn, opsworks)
52
61
  end
@@ -1,7 +1,7 @@
1
1
  require "hashie"
2
2
  require "json"
3
3
 
4
- class Dumbwaiter::DeploymentCustomJson < Hashie::Mash
4
+ class Dumbwaiter::DeploymentCustomJson
5
5
  def self.from_json(json_string)
6
6
  new(JSON.parse(json_string))
7
7
  end
@@ -10,15 +10,19 @@ class Dumbwaiter::DeploymentCustomJson < Hashie::Mash
10
10
  {deploy: {name => {scm: {revision: ref}}}}
11
11
  end
12
12
 
13
+ def initialize(params)
14
+ @params = params
15
+ end
16
+
17
+ def params
18
+ Hashie::Mash.new(@params)
19
+ end
20
+
13
21
  def app_name
14
- self.deploy.keys.first unless self.deploy.nil?
22
+ params.deploy.keys.first if params.deploy?
15
23
  end
16
24
 
17
- def git_ref
18
- if self.app_name.nil?
19
- "HEAD"
20
- else
21
- self.deploy[self.app_name].scm.revision
22
- end
25
+ def revision
26
+ params.deploy[app_name].scm.revision unless app_name.nil?
23
27
  end
24
28
  end
@@ -0,0 +1,84 @@
1
+ require "faker"
2
+
3
+ class Dumbwaiter::Mock
4
+ attr_reader :stacks, :deployments, :apps, :layers, :instances, :user_profiles
5
+
6
+ def opsworks; self; end
7
+ def describe_stacks(*_); OpenStruct.new(stacks: stacks); end
8
+ def describe_deployments(*_); OpenStruct.new(deployments: deployments); end
9
+ def describe_apps(*_); OpenStruct.new(apps: apps); end
10
+ def describe_layers(*_); OpenStruct.new(layers: layers); end
11
+ def describe_instances(*_); OpenStruct.new(instances: instances); end
12
+ def describe_user_profiles(*_); OpenStruct.new(user_profiles: user_profiles); end
13
+
14
+ def clear
15
+ @stacks = []
16
+ @deployments = []
17
+ @apps = []
18
+ @layers = []
19
+ @instances = []
20
+ @user_profiles = []
21
+ end
22
+
23
+ def initialize
24
+ super
25
+ clear
26
+ end
27
+
28
+ def make_stack(id = make_id, name = Faker::Name.first_name, color = make_color)
29
+ stack = OpenStruct.new(stack_id: id, name: name, attributes: {"Color" => color})
30
+ stacks << stack
31
+ stack
32
+ end
33
+
34
+ def make_app(stack = make_stack, id = make_id, name = Faker::Name.first_name, url = Faker::Internet.url, revision = make_revision)
35
+ app = OpenStruct.new(stack_id: stack.stack_id, app_id: id, name: name, app_source: make_app_source(url, revision))
36
+ apps << app
37
+ app
38
+ end
39
+
40
+ def make_layer(stack = make_stack, id = make_id, shortname = Faker::Name.first_name.downcase)
41
+ layer = OpenStruct.new(stack_id: stack.stack_id, layer_id: id, shortname: shortname)
42
+ layers << layer
43
+ layer
44
+ end
45
+
46
+ def make_deployment(stack = make_stack, app = make_app, id = make_id, command_name = Faker::Name.first_name.downcase, status = Faker::Name.first_name, custom_json = "{}", at = Time.now.to_s, arn = Faker::Name.first_name, comment = Faker::Company.bs)
47
+ command = OpenStruct.new(name: command_name)
48
+ deployment = OpenStruct.new(stack_id: stack.stack_id, app_id: app.app_id, deployment_id: id, command: command, created_at: at, status: status, comment: comment, iam_user_arn: arn, custom_json: custom_json)
49
+ deployments << deployment
50
+ deployment
51
+ end
52
+
53
+ def make_instance(stack = make_stack, layer = make_layer, id = make_id)
54
+ instance = OpenStruct.new(layer_id: layer.layer_id, stack_id: stack.stack_id, instance_id: id)
55
+ instances << instance
56
+ instance
57
+ end
58
+
59
+ def make_user_profile(id = Faker::Name.last_name.downcase, name = Faker::Name.first_name)
60
+ user_profile = OpenStruct.new(aws_iam_arn: id, name: name)
61
+ user_profiles << user_profile
62
+ user_profile
63
+ end
64
+
65
+ protected
66
+
67
+ def make_app_source(url, revision)
68
+ OpenStruct.new(url: url, revision: revision)
69
+ end
70
+
71
+ def make_revision
72
+ "%06x" % (rand * 0xffffff)
73
+ end
74
+
75
+ def make_color
76
+ "rgb(#{rand(255)},#{rand(255)},#{rand(255)})"
77
+ end
78
+
79
+ def make_id
80
+ @id ||= 0
81
+ @id += 1
82
+ "taco-#{@id}"
83
+ end
84
+ end
@@ -1,3 +1,3 @@
1
1
  module Dumbwaiter
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
data/lib/dumbwaiter.rb CHANGED
@@ -1,4 +1,2 @@
1
- module Dumbwaiter; end
2
-
3
- require "dumbwaiter/cli"
4
1
  require "dumbwaiter/version"
2
+ require "dumbwaiter/cli"
@@ -1,17 +1,30 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Dumbwaiter::App do
4
- let(:fake_stack) { double(:stack, id: "pancakes") }
5
- let(:fake_app) { double(:app, name: "goose", app_id: "amazing") }
6
- let(:fake_apps) { double(:apps, apps: [fake_app]) }
7
- let(:fake_opsworks) { double(:opsworks, describe_apps: fake_apps) }
4
+ let(:fake_opsworks) { Dumbwaiter::Mock.new }
5
+ let(:fake_stack) { fake_opsworks.make_stack("pancakes") }
6
+ let!(:fake_app) { fake_opsworks.make_app(fake_stack, "amazing", "goose", "git@example.com:tacos/great.git") }
7
+ let(:real_stack) { Dumbwaiter::Stack.new(fake_stack, fake_opsworks) }
8
8
 
9
- subject(:app) { Dumbwaiter::App.new(fake_stack, fake_app, fake_opsworks) }
9
+ subject(:app) { Dumbwaiter::App.new(real_stack, fake_app, fake_opsworks) }
10
10
 
11
- its(:stack) { should == fake_stack }
12
- its(:opsworks_app) { should == fake_app }
13
11
  its(:id) { should == "amazing" }
14
12
  its(:name) { should == "goose" }
13
+ its(:url) { should == "git@example.com:tacos/great.git" }
14
+
15
+ describe "#revision" do
16
+ context "when there is no revision specified" do
17
+ let(:fake_app) { fake_opsworks.make_app(fake_stack, "amazing", "goose", "git@example.com:tacos/great.git", nil) }
18
+
19
+ its(:revision) { should == "master" }
20
+ end
21
+
22
+ context "when a revision is specified" do
23
+ let(:fake_app) { fake_opsworks.make_app(fake_stack, "amazing", "goose", "git@example.com:tacos/great.git", "wat") }
24
+
25
+ its(:revision) { should == "wat" }
26
+ end
27
+ end
15
28
 
16
29
  describe "#deploy" do
17
30
  context "when no revision is specified" do
@@ -48,22 +61,22 @@ describe Dumbwaiter::App do
48
61
 
49
62
  describe ".all" do
50
63
  it "fetches all the apps" do
51
- fake_opsworks.should_receive(:describe_apps).with(stack_id: "pancakes")
52
- Dumbwaiter::App.all(fake_stack, fake_opsworks).should have(1).app
64
+ fake_opsworks.should_receive(:describe_apps).with(stack_id: "pancakes").and_call_original
65
+ Dumbwaiter::App.all(real_stack, fake_opsworks).should have(1).app
53
66
  end
54
67
  end
55
68
 
56
69
  describe ".find" do
57
70
  context "when the app exists" do
58
71
  it "finds the app by name" do
59
- Dumbwaiter::App.find(fake_stack, "goose", fake_opsworks).id.should == "amazing"
72
+ Dumbwaiter::App.find(real_stack, "goose", fake_opsworks).id.should == "amazing"
60
73
  end
61
74
  end
62
75
 
63
76
  context "when the app does not exist" do
64
77
  it "blows up" do
65
78
  expect {
66
- Dumbwaiter::App.find(fake_stack, "teeth", fake_opsworks)
79
+ Dumbwaiter::App.find(real_stack, "teeth", fake_opsworks)
67
80
  }.to raise_error(Dumbwaiter::App::NotFound)
68
81
  end
69
82
  end
@@ -72,14 +85,14 @@ describe Dumbwaiter::App do
72
85
  describe ".find" do
73
86
  context "when the app exists" do
74
87
  it "finds the app by id" do
75
- Dumbwaiter::App.find_by_id(fake_stack, "amazing", fake_opsworks).name.should == "goose"
88
+ Dumbwaiter::App.find_by_id(real_stack, "amazing", fake_opsworks).name.should == "goose"
76
89
  end
77
90
  end
78
91
 
79
92
  context "when the app does not exist" do
80
93
  it "blows up" do
81
94
  expect {
82
- Dumbwaiter::App.find_by_id(fake_stack, "teeth", fake_opsworks)
95
+ Dumbwaiter::App.find_by_id(real_stack, "teeth", fake_opsworks)
83
96
  }.to raise_error(Dumbwaiter::App::NotFound)
84
97
  end
85
98
  end
@@ -1,23 +1,20 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Dumbwaiter::Cli do
4
- let(:fake_app) { double(:app, name: "reifel") }
5
- let(:fake_layer) { double(:layer, shortname: "beans") }
6
- let(:fake_stack) { double(:stack, name: "ducks", id: "wat", apps: [fake_app]) }
4
+ let(:fake_opsworks) { Dumbwaiter::Mock.new }
5
+ let!(:fake_stack) { fake_opsworks.make_stack("amazing", "ducks") }
6
+ let!(:fake_layer) { fake_opsworks.make_layer(fake_stack, "mighty", "beans") }
7
+ let!(:fake_app) { fake_opsworks.make_app(fake_stack, "delightful", "reifel") }
7
8
 
8
9
  subject(:cli) { Dumbwaiter::Cli.new }
9
10
 
10
- before do
11
- Dumbwaiter::Stack.stub(all: [fake_stack])
12
- Dumbwaiter::App.stub(all: [fake_app])
13
- Dumbwaiter::Layer.stub(all: [fake_layer])
14
- end
11
+ before { Aws::OpsWorks.stub(new: fake_opsworks) }
15
12
 
16
13
  describe "#deploy" do
17
14
  context "when the stack exists" do
18
15
  context "when the app exists" do
19
16
  it "deploys the stack with the resolved id" do
20
- fake_app.should_receive(:deploy).with("corn")
17
+ Dumbwaiter::App.any_instance.should_receive(:deploy).with("corn")
21
18
  cli.deploy("ducks", "reifel", "corn")
22
19
  end
23
20
  end
@@ -40,7 +37,7 @@ describe Dumbwaiter::Cli do
40
37
  context "when the stack exists" do
41
38
  context "when the app exists" do
42
39
  it "deploys the stack with the resolved id" do
43
- fake_app.should_receive(:rollback)
40
+ Dumbwaiter::App.any_instance.should_receive(:rollback)
44
41
  cli.rollback("ducks", "reifel")
45
42
  end
46
43
  end
@@ -61,40 +58,38 @@ describe Dumbwaiter::Cli do
61
58
 
62
59
  describe "#list" do
63
60
  context "when the stack exists" do
64
- before { fake_stack.stub(deployments: [fake_deployment]) }
65
-
66
61
  context "when the deployment is a rollback" do
67
- let(:fake_deployment) { double(:deployment, command_name: "rollback", to_log: "oops!") }
62
+ before { fake_opsworks.make_deployment(fake_stack, fake_app, "jello", "rollback") }
68
63
 
69
64
  it "lists the deployment" do
70
- Kernel.should_receive(:puts).with("oops!")
65
+ Kernel.should_receive(:puts) { |m| m.should =~ /rollback/ }
71
66
  cli.list("ducks")
72
67
  end
73
68
  end
74
69
 
75
70
  context "when the deployment is a deploy" do
76
- let(:fake_deployment) { double(:deployment, command_name: "deploy", to_log: "whee!") }
71
+ before { fake_opsworks.make_deployment(fake_stack, fake_app, "jello", "deploy") }
77
72
 
78
73
  it "lists the deployment" do
79
- Kernel.should_receive(:puts).with("whee!")
74
+ Kernel.should_receive(:puts) { |m| m.should =~ /deploy/ }
80
75
  cli.list("ducks")
81
76
  end
82
77
  end
83
78
 
84
79
  context "when the deployment is a custom cookbook update" do
85
- let(:fake_deployment) { double(:deployment, command_name: "update_custom_cookbooks", to_log: "whee!") }
80
+ before { fake_opsworks.make_deployment(fake_stack, fake_app, "jello", "update_custom_cookbooks") }
86
81
 
87
82
  it "lists the deployment" do
88
- Kernel.should_receive(:puts).with("whee!")
83
+ Kernel.should_receive(:puts) { |m| m.should =~ /update_custom_cookbooks/ }
89
84
  cli.list("ducks")
90
85
  end
91
86
  end
92
87
 
93
88
  context "when the deployment is a recipe execution" do
94
- let(:fake_deployment) { double(:deployment, command_name: "execute_recipes", to_log: "whee!") }
89
+ before { fake_opsworks.make_deployment(fake_stack, fake_app, "jello", "execute_recipes") }
95
90
 
96
91
  it "lists the deployment" do
97
- Kernel.should_receive(:puts).with("whee!")
92
+ Kernel.should_receive(:puts) { |m| m.should =~ /execute_recipes/ }
98
93
  cli.list("ducks")
99
94
  end
100
95
  end
@@ -118,10 +113,8 @@ describe Dumbwaiter::Cli do
118
113
 
119
114
  describe "#layers" do
120
115
  context "when the stack exists" do
121
- before { fake_stack.stub(layers: [fake_layer]) }
122
-
123
116
  it "lists the layers" do
124
- Kernel.should_receive(:puts).with("beans")
117
+ Kernel.should_receive(:puts).with(fake_layer.shortname)
125
118
  cli.layers("ducks")
126
119
  end
127
120
  end
@@ -136,7 +129,7 @@ describe Dumbwaiter::Cli do
136
129
  describe "#rechef" do
137
130
  context "when the stack exists" do
138
131
  it "deploys the stack with the resolved id" do
139
- fake_stack.should_receive(:rechef)
132
+ Dumbwaiter::Stack.any_instance.should_receive(:rechef)
140
133
  cli.rechef("ducks")
141
134
  end
142
135
  end
@@ -152,7 +145,7 @@ describe Dumbwaiter::Cli do
152
145
  context "when the stack exists" do
153
146
  context "when the layer exists" do
154
147
  it "runs the recipe on the layer" do
155
- fake_layer.should_receive(:run_recipe).with("meatballs")
148
+ Dumbwaiter::Layer.any_instance.should_receive(:run_recipe).with("meatballs")
156
149
  cli.run_recipe("ducks", "beans", "meatballs")
157
150
  end
158
151
  end
@@ -7,14 +7,14 @@ describe Dumbwaiter::DeploymentCustomJson do
7
7
  let(:custom_json) { {} }
8
8
 
9
9
  its(:app_name) { should be_nil }
10
- its(:git_ref) { should == "HEAD" }
10
+ its(:revision) { should be_nil }
11
11
  end
12
12
 
13
13
  context "when the custom json contains a revision" do
14
14
  let(:custom_json) { {deploy: {"reifel" => {scm: {revision: "corn"}}}} }
15
15
 
16
16
  its(:app_name) { should == "reifel" }
17
- its(:git_ref) { should == "corn" }
17
+ its(:revision) { should == "corn" }
18
18
  end
19
19
 
20
20
  describe ".create" do
@@ -28,6 +28,6 @@ describe Dumbwaiter::DeploymentCustomJson do
28
28
  subject(:json) { Dumbwaiter::DeploymentCustomJson.from_json(json_string) }
29
29
 
30
30
  its(:app_name) { should == "toes" }
31
- its(:git_ref) { should == "jam" }
31
+ its(:revision) { should == "jam" }
32
32
  end
33
33
  end
@@ -1,67 +1,58 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Dumbwaiter::Deployment do
4
- let(:fake_command) { double(:command, name: "deplode") }
4
+ let(:fake_opsworks) { Dumbwaiter::Mock.new }
5
+ let(:fake_stack) { fake_opsworks.make_stack("pancakes") }
6
+ let(:fake_app) { fake_opsworks.make_app(fake_stack, "yo") }
7
+ let!(:fake_user_profile) { fake_opsworks.make_user_profile("ie", "goose") }
5
8
  let(:custom_json) { JSON.dump(deploy: {"hockey" => {scm: {revision: "eh-buddy"}}}) }
6
- let(:fake_deployment) do
7
- double(:deployment,
8
- created_at: "last Tuesday",
9
- command: fake_command,
10
- status: "badical",
11
- custom_json: custom_json,
12
- iam_user_arn: "ie",
13
- comment: "i love sports"
14
- )
15
- end
16
- let(:fake_deployments) { double(:deployments, deployments: [fake_deployment]) }
17
- let(:fake_user_profile) { double(:user_profile, name: "goose") }
18
- let(:fake_user_profiles) { double(:user_profiles, user_profiles: [fake_user_profile]) }
19
- let(:fake_opsworks) { double(:opsworks, describe_deployments: fake_deployments, describe_user_profiles: fake_user_profiles) }
9
+ let!(:fake_deployment) { fake_opsworks.make_deployment(fake_stack, fake_app, "jello", "deploy", "badical", custom_json, DateTime.parse("last Tuesday").to_s, "ie", "i love sports") }
10
+ let(:real_stack) { Dumbwaiter::Stack.new(fake_stack, fake_opsworks) }
20
11
 
21
- subject(:deployment) { Dumbwaiter::Deployment.new(fake_deployment, fake_opsworks) }
12
+ subject(:deployment) { Dumbwaiter::Deployment.new(real_stack, fake_deployment, fake_opsworks) }
22
13
 
23
- its(:opsworks_deployment) { should == fake_deployment }
24
14
  its(:created_at) { should == DateTime.parse("last Tuesday") }
25
- its(:command_name) { should == "deplode" }
15
+ its(:command_name) { should == "deploy" }
26
16
  its(:status) { should == "badical" }
27
17
  its(:comment) { should == "i love sports" }
28
- its(:git_ref) { should == "eh-buddy" }
29
- its(:to_log) { should == "#{DateTime.parse("last Tuesday")} - goose - deplode - badical - eh-buddy" }
18
+ its(:revision) { should == "eh-buddy" }
30
19
  its(:user_name) { should == "goose" }
31
20
 
21
+ context "when the command name is deploy" do
22
+ its(:to_log) { should == "#{DateTime.parse("last Tuesday")} - goose - deploy - badical - eh-buddy" }
23
+ end
24
+
25
+ context "when the command name is not deploy" do
26
+ let!(:fake_deployment) { fake_opsworks.make_deployment(fake_stack, fake_app, "jello", "floss", "badical", custom_json, DateTime.parse("last Tuesday").to_s, "ie", "i love sports") }
27
+
28
+ its(:to_log) { should == "#{DateTime.parse("last Tuesday")} - goose - floss - badical" }
29
+ end
30
+
32
31
  context "when the iam user arn is nil" do
33
- let(:fake_deployment) do
34
- double(:deployment,
35
- created_at: "last Tuesday",
36
- command: fake_command,
37
- status: "badical",
38
- custom_json: custom_json,
39
- iam_user_arn: nil
40
- )
41
- end
32
+ let!(:fake_deployment) { fake_opsworks.make_deployment(fake_stack, fake_app, "jello", "deploy", "badical", custom_json, DateTime.parse("last Tuesday").to_s, nil, "i love sports") }
42
33
 
43
- its(:user_name) { should == "?" }
34
+ its(:user_name) { should == "OpsWorks" }
35
+ end
36
+
37
+ context "when the iam user arn does not exist" do
38
+ let!(:fake_deployment) { fake_opsworks.make_deployment(fake_stack, fake_app, "jello", "deploy", "badical", custom_json, DateTime.parse("last Tuesday").to_s, "wait which user is this", "i love sports") }
39
+
40
+ before { fake_opsworks.clear }
41
+
42
+ its(:user_name) { should == "OpsWorks" }
44
43
  end
45
44
 
46
45
  context "when custom_json is nil" do
47
- let(:fake_deployment) do
48
- double(:deployment,
49
- created_at: "yo",
50
- command: fake_command,
51
- status: "badical",
52
- custom_json: nil
53
- )
54
- end
46
+ let(:real_app) { Dumbwaiter::App.new(real_stack, fake_app, fake_opsworks) }
47
+ let!(:fake_deployment) { fake_opsworks.make_deployment(fake_stack, fake_app, "jello", "deploy", "badical", nil, DateTime.parse("last Tuesday").to_s, "ie", "i love sports") }
55
48
 
56
- its(:git_ref) { should == "HEAD" }
49
+ its(:revision) { should == "#{real_app.revision}@{#{DateTime.parse("last Tuesday")}}" }
57
50
  end
58
51
 
59
52
  describe ".all" do
60
- let(:fake_stack) { double(:stack, id: "pancakes") }
61
-
62
53
  it "fetches all the deployments" do
63
- fake_opsworks.should_receive(:describe_deployments).with(stack_id: "pancakes")
64
- Dumbwaiter::Deployment.all(fake_stack, fake_opsworks).should have(1).app
54
+ fake_opsworks.should_receive(:describe_deployments).with(stack_id: "pancakes").and_call_original
55
+ Dumbwaiter::Deployment.all(real_stack, fake_opsworks).should have(1).deployment
65
56
  end
66
57
  end
67
58
  end
@@ -1,22 +1,21 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Dumbwaiter::Instance do
4
- let(:fake_stack) { double(:stack, id: "pancakes") }
5
- let(:fake_layer) { double(:layer, id: "pinto", stack: fake_stack) }
6
-
7
- let(:fake_instance) { double(:instance, instance_id: "dragons") }
8
- let(:fake_instances) { double(:instances, instances: [fake_instance]) }
9
- let(:fake_opsworks) { double(:opsworks, describe_instances: fake_instances) }
4
+ let(:fake_opsworks) { Dumbwaiter::Mock.new }
5
+ let(:fake_stack) { fake_opsworks.make_stack }
6
+ let(:fake_layer) { fake_opsworks.make_layer(fake_stack) }
7
+ let!(:fake_instance) { fake_opsworks.make_instance(fake_stack, fake_layer) }
10
8
 
11
9
  subject(:instance) { Dumbwaiter::Instance.new(fake_layer, fake_instance, fake_opsworks) }
12
10
 
13
- its(:opsworks_instance) { should == fake_instance }
14
- its(:id) { should == "dragons" }
11
+ its(:id) { should == fake_instance.instance_id }
15
12
 
16
13
  describe ".all" do
14
+ let(:real_layer) { Dumbwaiter::Layer.new(fake_stack, fake_layer, fake_opsworks) }
15
+
17
16
  it "fetches all the instances" do
18
- fake_opsworks.should_receive(:describe_instances).with(layer_id: "pinto")
19
- Dumbwaiter::Instance.all(fake_layer, fake_opsworks).should have(1).instance
17
+ fake_opsworks.should_receive(:describe_instances).with(layer_id: fake_layer.layer_id).and_call_original
18
+ Dumbwaiter::Instance.all(real_layer, fake_opsworks).should have(1).instance
20
19
  end
21
20
  end
22
21
  end
@@ -1,43 +1,41 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Dumbwaiter::Layer do
4
- let(:fake_stack) { double(:stack, id: "pancakes") }
5
- let(:fake_layer) { double(:layer, shortname: "meaty", layer_id: "pinto") }
6
- let(:fake_layers) { double(:layers, layers: [fake_layer]) }
7
- let(:fake_instance) { double(:instance, id: "dragons") }
8
- let(:fake_instances) { double(:instances, instances: [fake_instance]) }
9
- let(:fake_opsworks) { double(:opsworks, describe_layers: fake_layers, describe_instances: fake_instances) }
10
-
11
- before do
12
- Dumbwaiter::Instance.stub(all: [fake_instance])
13
- end
4
+ let(:fake_opsworks) { Dumbwaiter::Mock.new }
5
+ let(:fake_stack) { fake_opsworks.make_stack("pancakes") }
6
+ let(:fake_layer) { fake_opsworks.make_layer(fake_stack, "pinto", "meaty") }
7
+ let!(:fake_instance) { fake_opsworks.make_instance(fake_layer, fake_stack, "dragons") }
8
+
9
+ let(:real_stack) { Dumbwaiter::Stack.new(fake_stack, fake_opsworks) }
14
10
 
15
- subject(:layer) { Dumbwaiter::Layer.new(fake_stack, fake_layer, fake_opsworks) }
11
+ subject(:layer) { Dumbwaiter::Layer.new(real_stack, fake_layer, fake_opsworks) }
16
12
 
17
13
  its(:opsworks_layer) { should == fake_layer }
18
14
  its(:id) { should == "pinto" }
19
15
  its(:shortname) { should == "meaty" }
20
16
 
21
- its(:instances) { should == [fake_instance] }
17
+ it { should have(1).instances }
22
18
 
23
19
  describe ".all" do
20
+ let(:real_stack) { Dumbwaiter::Stack.new(fake_stack, fake_opsworks) }
21
+
24
22
  it "fetches all the deployments" do
25
- fake_opsworks.should_receive(:describe_layers).with(stack_id: "pancakes")
26
- Dumbwaiter::Layer.all(fake_stack, fake_opsworks).should have(1).layer
23
+ fake_opsworks.should_receive(:describe_layers).with(stack_id: "pancakes").and_call_original
24
+ Dumbwaiter::Layer.all(real_stack, fake_opsworks).should have(1).layer
27
25
  end
28
26
  end
29
27
 
30
28
  describe ".find" do
31
29
  context "when the layer exists" do
32
30
  it "finds the layer by name" do
33
- Dumbwaiter::Layer.find(fake_stack, "meaty", fake_opsworks).shortname.should == "meaty"
31
+ Dumbwaiter::Layer.find(real_stack, "meaty", fake_opsworks).shortname.should == "meaty"
34
32
  end
35
33
  end
36
34
 
37
35
  context "when the layer does not exist" do
38
36
  it "blows up" do
39
37
  expect {
40
- Dumbwaiter::Layer.find(fake_stack, "brick", fake_opsworks)
38
+ Dumbwaiter::Layer.find(real_stack, "brick", fake_opsworks)
41
39
  }.to raise_error(Dumbwaiter::Layer::NotFound)
42
40
  end
43
41
  end
@@ -1,30 +1,22 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Dumbwaiter::Stack do
4
- let(:fake_stack) { double(:stack, name: "ducks", stack_id: "cool", attributes: {"Color" => "hot pink"}) }
5
- let(:fake_stacks) { double(:stacks, stacks: [fake_stack]) }
6
- let(:fake_opsworks) { double(:opsworks, describe_stacks: fake_stacks) }
7
- let(:fake_app) { double(:app) }
8
- let(:fake_deployment) { double(:deployment) }
9
- let(:fake_layer) { double(:layer) }
4
+ let(:fake_opsworks) { Dumbwaiter::Mock.new }
5
+ let!(:fake_stack) { fake_opsworks.make_stack("cool", "ducks", "hot pink") }
6
+ let!(:fake_app) { fake_opsworks.make_app(fake_stack) }
7
+ let!(:fake_deployment) { fake_opsworks.make_deployment(fake_stack, fake_app) }
8
+ let!(:fake_layer) { fake_opsworks.make_layer(fake_stack) }
10
9
 
11
10
  subject(:stack) { Dumbwaiter::Stack.new(fake_stack, fake_opsworks) }
12
11
 
13
- before do
14
- Dumbwaiter::App.stub(all: [fake_app])
15
- Dumbwaiter::Deployment.stub(all: [fake_deployment])
16
- Dumbwaiter::Layer.stub(all: [fake_layer])
17
- end
12
+ it { should have(1).apps }
13
+ it { should have(1).deployments }
14
+ it { should have(1).layers }
18
15
 
19
- its(:opsworks_stack) { should == fake_stack }
20
16
  its(:id) { should == "cool" }
21
17
  its(:name) { should == "ducks" }
22
18
  its(:color) { should == "hot pink" }
23
19
 
24
- its(:apps) { should == [fake_app] }
25
- its(:deployments) { should == [fake_deployment] }
26
- its(:layers) { should == [fake_layer] }
27
-
28
20
  describe ".all" do
29
21
  it "fetches all the stacks" do
30
22
  Dumbwaiter::Stack.all(fake_opsworks).should have(1).stack
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ lib = File.expand_path("../lib", __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  require "dumbwaiter"
5
+ require "dumbwaiter/mock"
5
6
 
6
7
  Aws.config = {access_key_id: "tacos", secret_access_key: "secret chocolate"}
7
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dumbwaiter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doc Ritezel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-21 00:00:00.000000000 Z
11
+ date: 2013-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-core
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: faker
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Hoist your code up to Opsworks
98
112
  email:
99
113
  - doc@ministryofvelocity.com
@@ -120,6 +134,7 @@ files:
120
134
  - lib/dumbwaiter/deployment_custom_json.rb
121
135
  - lib/dumbwaiter/instance.rb
122
136
  - lib/dumbwaiter/layer.rb
137
+ - lib/dumbwaiter/mock.rb
123
138
  - lib/dumbwaiter/stack.rb
124
139
  - lib/dumbwaiter/user_profile.rb
125
140
  - lib/dumbwaiter/version.rb