ey_resolver 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+
3
+ describe EY::Resolver::AppEnvResolver do
4
+
5
+ def app_resolver(*args)
6
+ EY::Resolver.app_resolver(user, to_query(args))
7
+ end
8
+
9
+ def apps(*models)
10
+ models.map { |model| model[:app] }
11
+ end
12
+
13
+ describe "#matches" do
14
+ it "returns none if the conditions are empty" do
15
+ app_resolver( ).matches.should == []
16
+ app_resolver(nil, nil, nil, []).matches.should == []
17
+ app_resolver('', '', '', [''] ).matches.should == []
18
+ end
19
+
20
+ it "returns none if the conditions do not include an app or remotes" do
21
+ app_resolver(nil, nil, 'app_dup' ).matches.should == []
22
+ app_resolver('ey', nil, nil ).matches.should == []
23
+ app_resolver('ey', nil, 'app_dup', []).matches.should == []
24
+ end
25
+
26
+ it "returns empty when there is no account match" do
27
+ app_resolver('gibberish', 'app', 'production').matches.should == []
28
+ end
29
+
30
+ it "returns empty when there is no app match" do
31
+ app_resolver(nil, 'gibberish', 'app_dup').matches.should == []
32
+ end
33
+
34
+ it "finds apps that don't have environments" do
35
+ app_resolver(nil, 'noenv').matches.should == apps(@noenv)
36
+ end
37
+
38
+ it "returns more matches when there is more than one match" do
39
+ app_resolver(nil, nil, nil, ["git://github.com/repo/dup.git"]).matches.should == apps(@ey_dup, @me_dup)
40
+ app_resolver(nil, nil, nil, ["git://github.com/repo/hug.git", "git://github.com/repo/big.git"]).matches.should == apps(@hugeprod, @big)
41
+ end
42
+
43
+ it "returns one deployment whene there is only one match" do
44
+ app_resolver(nil, "app" ).matches.should == apps(@production)
45
+ app_resolver("ey", "app" ).matches.should == apps(@production)
46
+ app_resolver(nil, 'bigapp').matches.should == apps(@big)
47
+ app_resolver("ey", "big" ).matches.should == apps(@big)
48
+ app_resolver(nil, nil, nil, ["git://github.com/repo/app.git"]).matches.should == apps(@production)
49
+ app_resolver(nil, nil, nil, ["git://github.com/repo/big.git"]).matches.should == apps(@big)
50
+ app_resolver('me', nil, nil, ["git://github.com/repo/dup.git"]).matches.should == apps(@me_dup)
51
+ end
52
+
53
+ it "doesn't care about case" do
54
+ app_resolver("EY", "big").matches.should == apps(@big)
55
+ app_resolver("ey", "BiG").matches.should == apps(@big)
56
+ end
57
+
58
+ it "returns the match when an app is specified even when there is a repo" do
59
+ app_resolver("ey", "bigapp", nil, ["git://github.com/repo/app.git"]).matches.should == apps(@big)
60
+ end
61
+
62
+ it "returns the specific match even if there is a partial match" do
63
+ app_resolver(nil, 'app').matches.should == apps(@production)
64
+ end
65
+
66
+ it "scopes searches under the correct account" do
67
+ app_resolver("ey", "dup").matches.should == apps(@ey_dup)
68
+ app_resolver("me", "dup").matches.should == apps(@me_dup)
69
+ app_resolver("ey", nil, nil, ["git://github.com/repo/dup.git"]).matches.should == apps(@ey_dup)
70
+ app_resolver("me", nil, nil, ["git://github.com/repo/dup.git"]).matches.should == apps(@me_dup)
71
+ end
72
+ end
73
+
74
+ describe "#errors" do
75
+ it "no account" do
76
+ app_resolver('gibberish', 'app', 'production').errors.should ==
77
+ [%|No account found matching "gibberish".|]
78
+ end
79
+
80
+ it "no app" do
81
+ app_resolver(nil, 'gibberish', 'app_dup').errors.should ==
82
+ [%|No application found matching "gibberish".|]
83
+ end
84
+
85
+ it "app found, but not on account" do
86
+ app_resolver('no', 'bigapp', 'app_dup').errors.should == [
87
+ %|Application "bigapp" found, but does not exist in account "no".|,
88
+ %|Environment "app_dup" found, but does not exist in account "no".|,
89
+ ]
90
+ end
91
+
92
+ it "no env" do
93
+ app_resolver('ey', 'app', 'gibberish').errors.should ==
94
+ [%|No environment found matching "gibberish".|]
95
+ end
96
+
97
+ it "no env on account" do
98
+ app_resolver('me', 'other', 'production').errors.should ==
99
+ [%|Environment "production" found, but does not exist in account "me".|]
100
+ end
101
+
102
+ it "no account or app" do
103
+ app_resolver('gibberish', 'gibberish', nil).errors.should == [
104
+ %|No account found matching "gibberish".|,
105
+ %|No application found matching "gibberish".|,
106
+ ]
107
+ end
108
+
109
+ it "no account or app or env" do
110
+ app_resolver('gibberish', 'gibberish', 'gibberish').errors.should == [
111
+ %|No account found matching "gibberish".|,
112
+ %|No application found matching "gibberish".|,
113
+ %|No environment found matching "gibberish".|,
114
+ ]
115
+ end
116
+
117
+ it "repo not found" do
118
+ app_resolver(nil, nil, nil, ["git://fake.com/fake/fake.git"]).errors.should ==
119
+ [%|No application found matching remotes:\n\tgit://fake.com/fake/fake.git|]
120
+ end
121
+
122
+ it "repo not found in account" do
123
+ app_resolver('ey', nil, nil, ["git://github.com/repo/oth.git"]).errors.should ==
124
+ [%|Application "other" found, but does not exist in account "ey".|]
125
+ end
126
+
127
+ end
128
+ end
@@ -0,0 +1,166 @@
1
+ require 'spec_helper'
2
+
3
+ describe EY::Resolver::EnvironmentResolver do
4
+
5
+ def env_resolver(*args)
6
+ EY::Resolver.environment_resolver(user, to_query(args))
7
+ end
8
+
9
+ def envs(*models)
10
+ models.map { |model| model[:env] }
11
+ end
12
+
13
+ describe "#matches" do
14
+ it "raises if the conditions are empty" do
15
+ env_resolver( ).matches.should == []
16
+ env_resolver(nil, nil, nil, [] ).matches.should == []
17
+ env_resolver('', '', '', ['']).matches.should == []
18
+ end
19
+
20
+ it "finds matches that would raise for app_env_resolver" do
21
+ env_resolver(nil, nil, 'app_dup').matches.should == envs(@ey_dup, @me_dup)
22
+ env_resolver('ey', nil, 'app_dup').matches.should == envs(@ey_dup)
23
+ env_resolver('ey', nil, 'noapp' ).matches.should == envs(@noapp)
24
+ end
25
+
26
+ it "returns empty when there is no account match" do
27
+ env_resolver('gibberish', 'app', 'production').matches.should == []
28
+ end
29
+
30
+ it "returns empty when there is no app match" do
31
+ env_resolver(nil, 'gibberish', 'app_dup').matches.should == []
32
+ end
33
+
34
+ it "returns empty when there is no remote match and env name is not specified" do
35
+ env_resolver(nil, nil, nil, ["git://github.com/repo/noe.git"]).matches.should == []
36
+ end
37
+
38
+ it "returns empty when there is no environment match" do
39
+ env_resolver(nil, nil, 'gibberish').matches.should == []
40
+ env_resolver(nil, 'app', 'gibberish').matches.should == []
41
+ end
42
+
43
+ it "returns empty because app doesn't match even when the environment exists" do
44
+ env_resolver(nil, 'bigapp', 'app_dup').matches.should == []
45
+ end
46
+
47
+ it "returns more matches when there is more than one match" do
48
+ env_resolver(nil, "app", nil, nil ).matches.should == envs(@production, @staging)
49
+ env_resolver("ey", "app", nil, nil ).matches.should == envs(@production, @staging)
50
+ env_resolver(nil, nil, nil, ["git://github.com/repo/app.git"]).matches.should == envs(@production, @staging)
51
+ env_resolver(nil, nil, nil, ["git://github.com/repo/hug.git", "git://github.com/repo/big.git"]).matches.should == envs(@hugeprod, @big)
52
+ env_resolver(nil, nil, nil, ["git://github.com/repo/dup.git"]).matches.should == envs(@ey_dup, @sumo, @me_dup)
53
+ env_resolver(nil, nil, 'app_dup', ["git://github.com/repo/app.git"]).matches.should == envs(@ey_dup, @me_dup)
54
+ end
55
+
56
+ it "finds matches that don't match the remotes" do
57
+ env_resolver(nil, nil, 'production', ["git://github.com/repo/app.git"]).matches.should == envs(@production, @hugeprod)
58
+ env_resolver(nil, nil, 'staging', ["git://github.com/repo/noe.git"]).matches.should == envs(@staging, @big)
59
+ end
60
+
61
+ it "scopes by app name when specified" do
62
+ env_resolver("ey", "big", nil, nil ).matches.should == envs(@big)
63
+ env_resolver(nil, 'app', "production", nil ).matches.should == envs(@production)
64
+ end
65
+
66
+ it "returns one deployment whene there is only one match" do
67
+ env_resolver(nil, nil, 'staging', ["git://github.com/repo/app.git"]).matches.should == envs(@staging)
68
+ env_resolver(nil, nil, nil, ["git://github.com/repo/big.git"]).matches.should == envs(@big)
69
+ end
70
+
71
+ it "doesn't care about case" do
72
+ env_resolver("EY", "big").matches.should == envs(@big)
73
+ env_resolver("ey", "BiG").matches.should == envs(@big)
74
+ end
75
+
76
+ it "returns the match when an app is specified even when there is a repo" do
77
+ env_resolver("ey", "bigapp", nil, ["git://github.com/repo/app.git"]).matches.should == envs(@big)
78
+ end
79
+
80
+ it "returns the specific match even if there is a partial match" do
81
+ env_resolver(nil, 'app', 'app_staging').matches.should == envs(@staging)
82
+ env_resolver(nil, "app", "staging" ).matches.should == envs(@staging)
83
+ end
84
+
85
+ it "scopes searches under the correct account" do
86
+ env_resolver("ey", "dup", "dup", nil ).matches.should == envs(@ey_dup)
87
+ env_resolver("me", nil, "dup", ["git://github.com/repo/dup.git"]).matches.should == envs(@me_dup)
88
+ env_resolver("me", nil, nil, ["git://github.com/repo/dup.git"]).matches.should == envs(@me_dup)
89
+ env_resolver("me", "dup", nil, nil ).matches.should == envs(@me_dup)
90
+ end
91
+ end
92
+
93
+ describe "#errors" do
94
+ it "no account" do
95
+ env_resolver('gibberish', 'app', 'production').errors.should ==
96
+ [%|No account found matching "gibberish".|]
97
+ end
98
+
99
+ it "no app" do
100
+ env_resolver(nil, 'gibberish', 'app_dup').errors.should ==
101
+ [%|No application found matching "gibberish".|]
102
+ end
103
+
104
+ it "app found, but not on account" do
105
+ env_resolver('no', 'bigapp', 'app_dup').errors.should == [
106
+ %|Application "bigapp" found, but does not exist in account "no".|,
107
+ %|Environment "app_dup" found, but does not exist in account "no".|,
108
+ ]
109
+ end
110
+
111
+ it "no env" do
112
+ env_resolver('ey', nil, 'gibberish').errors.should ==
113
+ [%|No environment found matching "gibberish".|]
114
+ end
115
+
116
+ it "no env on account" do
117
+ env_resolver('no', nil, 'app_dup').errors.should ==
118
+ [%|Environment "app_dup" found, but does not exist in account "no".|]
119
+ end
120
+
121
+ it "no account or app" do
122
+ env_resolver('gibberish', 'gibberish', nil).errors.should == [
123
+ %|No account found matching "gibberish".|,
124
+ %|No application found matching "gibberish".|,
125
+ ]
126
+ end
127
+
128
+ it "no account or app or env" do
129
+ env_resolver('gibberish', 'gibberish', 'gibberish').errors.should == [
130
+ %|No account found matching "gibberish".|,
131
+ %|No application found matching "gibberish".|,
132
+ %|No environment found matching "gibberish".|,
133
+ ]
134
+ end
135
+
136
+ it "repo not found" do
137
+ env_resolver(nil, nil, nil, ["git://fake.com/fake/fake.git"]).errors.should ==
138
+ [%|No application found matching remotes:\n\tgit://fake.com/fake/fake.git|]
139
+ end
140
+
141
+ it "repo found but env doesn't exist on it" do
142
+ env_resolver(nil, nil, nil, ["git://github.com/repo/noe.git"]).errors.should ==
143
+ [%|No environment found for applications matching remotes:\n\tgit://github.com/repo/noe.git|]
144
+ end
145
+
146
+ it "repo not found in account" do
147
+ env_resolver('ey', nil, nil, ["git://github.com/repo/oth.git"]).errors.should ==
148
+ [%|Application "other" found, but does not exist in account "ey".|]
149
+ end
150
+
151
+ it "app and environment not associated" do
152
+ env_resolver('ey', 'bigapp', 'app_dup').errors.should ==
153
+ [%|Application "bigapp" and environment "app_dup" are not associated.|]
154
+ end
155
+
156
+ it "app (by repo) and environment not associated" do
157
+ env_resolver(nil, nil, 'app_dup', ["git://github.com/repo/app.git"]).errors.should ==
158
+ [%|Application "app" and environment "app_dup" are not associated.|]
159
+ end
160
+
161
+ it "app (by repo) does not have an environment" do
162
+ env_resolver(nil, nil, nil, ["git://github.com/repo/noe.git"]).errors.should ==
163
+ [%|No environment found for applications matching remotes:\n\tgit://github.com/repo/noe.git|]
164
+ end
165
+ end
166
+ end
@@ -0,0 +1,84 @@
1
+ if ENV['COVERAGE']
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+ end
5
+
6
+ require 'bundler/setup'
7
+
8
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
+ require 'ey_resolver'
10
+ require 'ey_resolver/mock'
11
+
12
+ # Spec stuff
13
+ require 'rspec'
14
+ require 'pp'
15
+
16
+ # Hack to allow datamapper style :name.like without including datamapper.
17
+ # Pretty nasty :(
18
+
19
+ module Helpers
20
+
21
+ def user
22
+ @user ||= User.create(:name => 'user')
23
+ end
24
+
25
+ def mock_models(acc_name, app_name = nil, env_name = nil, repo = nil)
26
+ unless acc_name
27
+ raise "Must have an account"
28
+ end
29
+
30
+ if !!app_name != !!repo # both or neither (XNOR)
31
+ raise "app_name and repo must be supplied together"
32
+ end
33
+
34
+ account = Account.first(:user => user, :name => acc_name)
35
+ account ||= Account.create(:user => user, :name => acc_name)
36
+
37
+ app = nil
38
+ if app_name
39
+ app = App.first( :account_id => account.id, :name => app_name, :repository_uri => repo)
40
+ app ||= App.create(:account_id => account.id, :name => app_name, :repository_uri => repo)
41
+ end
42
+
43
+ env = nil
44
+ if env_name
45
+ env = Environment.first( :account_id => account.id, :name => env_name)
46
+ env ||= Environment.create(:account_id => account.id, :name => env_name)
47
+ end
48
+
49
+ app_env = nil
50
+ if app_name && env_name
51
+ app_env = AppEnvironment.first( :app => app, :environment => env)
52
+ app_env ||= AppEnvironment.create(:app => app, :environment => env)
53
+ end
54
+
55
+ {
56
+ :account => account,
57
+ :app => app,
58
+ :env => env,
59
+ :app_env => app_env,
60
+ }
61
+ end
62
+
63
+ def to_query(args)
64
+ Hash[%w[account_name app_name environment_name remotes].zip(args)]
65
+ end
66
+ end
67
+
68
+ RSpec.configure do |config|
69
+ config.include Helpers
70
+
71
+ config.before(:all) do
72
+ @production = mock_models('ey', "app", "app_production", "git://github.com/repo/app.git")
73
+ @staging = mock_models('ey', "app", "app_staging", "git://github.com/repo/app.git")
74
+ @hugeprod = mock_models('ey', "huge", "production", "git://github.com/repo/hug.git")
75
+ @big = mock_models('ey', "bigapp", "bigapp_staging", "git://github.com/repo/big.git")
76
+ @ey_dup = mock_models('ey', "app_dup", "app_dup", "git://github.com/repo/dup.git")
77
+ @sumo = mock_models('ey', "app_dup", "sumo_wrestler", "git://github.com/repo/dup.git")
78
+ @me_dup = mock_models('me', "app_dup", "app_dup", "git://github.com/repo/dup.git")
79
+ @me_other = mock_models('me', "other", "app_dup", "git://github.com/repo/oth.git")
80
+ @noapp = mock_models('ey', nil, "noapp", nil)
81
+ @noenv = mock_models('ey', "noenv", nil, "git://github.com/repo/noe.git")
82
+ @account = mock_models('no', nil, nil, nil)
83
+ end
84
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ey_resolver
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Martin Emde
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-13 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ prerelease: false
22
+ type: :runtime
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 17
29
+ segments:
30
+ - 0
31
+ - 2
32
+ - 3
33
+ version: 0.2.3
34
+ name: gitable
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ prerelease: false
38
+ type: :development
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ name: rake
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ prerelease: false
52
+ type: :development
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 2
61
+ - 0
62
+ version: "2.0"
63
+ name: rspec
64
+ version_requirements: *id003
65
+ description: Resolves apps, environments, app_environments and accounts using a set of constraints
66
+ email:
67
+ - martin.emde@gmail.com
68
+ executables: []
69
+
70
+ extensions: []
71
+
72
+ extra_rdoc_files: []
73
+
74
+ files:
75
+ - .gitignore
76
+ - Gemfile
77
+ - README.md
78
+ - Rakefile
79
+ - ey_resolver.gemspec
80
+ - lib/ey_resolver.rb
81
+ - lib/ey_resolver/abstract_resolver.rb
82
+ - lib/ey_resolver/account_resolver.rb
83
+ - lib/ey_resolver/app_env_resolver.rb
84
+ - lib/ey_resolver/app_resolver.rb
85
+ - lib/ey_resolver/environment_resolver.rb
86
+ - lib/ey_resolver/examiner.rb
87
+ - lib/ey_resolver/mock.rb
88
+ - lib/ey_resolver/mock/models.rb
89
+ - lib/ey_resolver/mock/models/account.rb
90
+ - lib/ey_resolver/mock/models/app.rb
91
+ - lib/ey_resolver/mock/models/app_environment.rb
92
+ - lib/ey_resolver/mock/models/environment.rb
93
+ - lib/ey_resolver/mock/models/user.rb
94
+ - lib/ey_resolver/query.rb
95
+ - lib/ey_resolver/version.rb
96
+ - spec/account_resolver_spec.rb
97
+ - spec/app_env_resolver_spec.rb
98
+ - spec/app_resolver_spec.rb
99
+ - spec/environment_resolver_spec.rb
100
+ - spec/spec_helper.rb
101
+ homepage: ""
102
+ licenses: []
103
+
104
+ post_install_message:
105
+ rdoc_options: []
106
+
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 3
124
+ segments:
125
+ - 0
126
+ version: "0"
127
+ requirements: []
128
+
129
+ rubyforge_project: ey_resolver
130
+ rubygems_version: 1.8.15
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: Resolves awsm models given constraints
134
+ test_files:
135
+ - spec/account_resolver_spec.rb
136
+ - spec/app_env_resolver_spec.rb
137
+ - spec/app_resolver_spec.rb
138
+ - spec/environment_resolver_spec.rb
139
+ - spec/spec_helper.rb