tunnelbroker 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,84 @@
1
+ # -*- coding: UTF-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe TunnelBroker::Configuration do
5
+ describe '::FIELDS' do
6
+ subject { TunnelBroker::Configuration::FIELDS }
7
+
8
+ it { should be_an_instance_of Array }
9
+
10
+ it 'should contain only symbols' do
11
+ subject.each do |f|
12
+ expect(f).to be_an_instance_of Symbol
13
+ end
14
+ end
15
+
16
+ it { should eql [:url, :ip4addr, :username, :update_key, :tunnelid] }
17
+ end
18
+
19
+ describe '.set_default_values' do
20
+ context 'when given more than one arg' do
21
+ it 'should raise ArgumentError' do
22
+ expect do
23
+ subject.send(:set_default_values, nil)
24
+ end.to raise_error ArgumentError
25
+ end
26
+ end
27
+
28
+ context 'when called after changing values' do
29
+ before(:each) do
30
+ subject.ip4addr = ''
31
+ subject.tunnelid = ''
32
+ subject.username = ''
33
+ subject.update_key = ''
34
+ end
35
+
36
+ it 'should set ip to nil' do
37
+ subject.send(:set_default_values)
38
+
39
+ expect(subject.ip4addr).to be_nil
40
+ end
41
+
42
+ it 'should set tunnnelid to nil' do
43
+ subject.send(:set_default_values)
44
+
45
+ expect(subject.tunnelid).to be_nil
46
+ end
47
+
48
+ it 'should set username to nil' do
49
+ subject.send(:set_default_values)
50
+
51
+ expect(subject.username).to be_nil
52
+ end
53
+
54
+ it 'should set update_key to nil' do
55
+ subject.send(:set_default_values)
56
+
57
+ expect(subject.update_key).to be_nil
58
+ end
59
+ end
60
+ end
61
+
62
+ describe '#new' do
63
+ context 'when given more than one arg' do
64
+ it 'should raise ArgumentError' do
65
+ expect do
66
+ TunnelBroker::Configuration.new(nil)
67
+ end.to raise_error ArgumentError
68
+ end
69
+ end
70
+
71
+ context 'under normal conditions' do
72
+ subject { TunnelBroker::Configuration.new }
73
+
74
+ it { should be_an_instance_of TunnelBroker::Configuration }
75
+
76
+ it 'should set the default configuration options' do
77
+ expect(subject.ip4addr).to be_nil
78
+ expect(subject.tunnelid).to be_nil
79
+ expect(subject.username).to be_nil
80
+ expect(subject.update_key).to be_nil
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,194 @@
1
+ # -*- coding: UTF-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe TunnelBroker::Messenger do
5
+ before do
6
+ @opts = {
7
+ url: 'test1', username: 'test2', update_key: 'test3', tunnelid: 'test4'
8
+ }
9
+ @messenger = TunnelBroker::Messenger.new(@opts)
10
+ end
11
+
12
+ describe '.opts_to_inst' do
13
+ context 'when given more than one arg' do
14
+ it 'should raise ArgumentError' do
15
+ expect do
16
+ @messenger.send(:opts_to_inst, nil, nil)
17
+ end.to raise_error ArgumentError
18
+ end
19
+ end
20
+
21
+ context 'when given less than one arg' do
22
+ it 'should raise ArgumentError' do
23
+ expect do
24
+ @messenger.send(:opts_to_inst)
25
+ end.to raise_error ArgumentError
26
+ end
27
+ end
28
+
29
+ context 'when given an option hash and inst_vars do not exist' do
30
+ before do
31
+ @messenger.remove_instance_variable(:@url)
32
+ @messenger.remove_instance_variable(:@username)
33
+ @messenger.remove_instance_variable(:@update_key)
34
+ @messenger.remove_instance_variable(:@tunnelid)
35
+ end
36
+
37
+ it 'should properly convert the hash to instance variables' do
38
+ t_opts = { url: 't', username: 'u', update_key: 'k', tunnelid: 'ti' }
39
+ @messenger.send(:opts_to_inst, t_opts)
40
+
41
+ m = @messenger.instance_variable_get(:@url)
42
+ expect(m).to eql t_opts[:url]
43
+
44
+ m = @messenger.instance_variable_get(:@username)
45
+ expect(m).to eql t_opts[:username]
46
+
47
+ m = @messenger.instance_variable_get(:@update_key)
48
+ expect(m).to eql t_opts[:update_key]
49
+
50
+ m = @messenger.instance_variable_get(:@tunnelid)
51
+ expect(m).to eql t_opts[:tunnelid]
52
+ end
53
+ end
54
+
55
+ context 'when given an option hash and inst_vars do exist' do
56
+ it 'should properly convert the hash to instance variables' do
57
+ t_opts = { url: 'w', username: 'x', update_key: 'y', tunnelid: 'z' }
58
+ @messenger.send(:opts_to_inst, t_opts)
59
+
60
+ m = @messenger.instance_variable_get(:@url)
61
+ expect(m).to eql t_opts[:url]
62
+
63
+ m = @messenger.instance_variable_get(:@username)
64
+ expect(m).to eql t_opts[:username]
65
+
66
+ m = @messenger.instance_variable_get(:@update_key)
67
+ expect(m).to eql t_opts[:update_key]
68
+
69
+ m = @messenger.instance_variable_get(:@tunnelid)
70
+ expect(m).to eql t_opts[:tunnelid]
71
+ end
72
+ end
73
+ end
74
+
75
+ describe '.call_endpoint' do
76
+ context 'when given more than one arg' do
77
+ it 'should raise ArgumentError' do
78
+ expect do
79
+ @messenger.send(:call_endpoint, nil)
80
+ end.to raise_error ArgumentError
81
+ end
82
+ end
83
+
84
+ context 'when called with no arguments and no @ipv4addr' do
85
+ before do
86
+ allow(TunnelBroker::Messenger).to receive(:get).with(
87
+ 'test1',
88
+ basic_auth: {
89
+ username: @opts[:username], password: @opts[:update_key]
90
+ },
91
+ query: { hostname: @opts[:tunnelid] }
92
+ ).and_return('success!')
93
+ end
94
+
95
+ subject { @messenger.send(:call_endpoint) }
96
+
97
+ it { should eql 'success!' }
98
+ end
99
+
100
+ context 'when called with no arguments and with non-nil @ipv4addr' do
101
+ before do
102
+ @opts1 = {
103
+ url: 'test1', username: 'test2', update_key: 'test3',
104
+ tunnelid: 'test4', ip4addr: 'test5'
105
+ }
106
+ @messenger1 = TunnelBroker::Messenger.new(@opts1)
107
+ allow(TunnelBroker::Messenger).to receive(:get).with(
108
+ 'test1',
109
+ basic_auth: {
110
+ username: @opts1[:username], password: @opts1[:update_key]
111
+ },
112
+ query: { hostname: @opts1[:tunnelid], myip: 'test5' }
113
+ ).and_return('success2!')
114
+ end
115
+
116
+ subject { @messenger1.send(:call_endpoint) }
117
+
118
+ it { should eql 'success2!' }
119
+ end
120
+
121
+ context 'when called with no arguments and with nil @ipv4addr' do
122
+ before do
123
+ @opts2 = {
124
+ url: 'test1', username: 'test2', update_key: 'test3',
125
+ tunnelid: 'test4', ip4addr: nil
126
+ }
127
+ @messenger2 = TunnelBroker::Messenger.new(@opts2)
128
+ allow(TunnelBroker::Messenger).to receive(:get).with(
129
+ 'test1',
130
+ basic_auth: {
131
+ username: @opts2[:username], password: @opts2[:update_key]
132
+ },
133
+ query: { hostname: @opts2[:tunnelid] }
134
+ ).and_return('success3!')
135
+ end
136
+
137
+ subject { @messenger2.send(:call_endpoint) }
138
+
139
+ it { should eql 'success3!' }
140
+ end
141
+ end
142
+
143
+ describe '.call_api' do
144
+ before do
145
+ allow(TunnelBroker::Messenger).to receive(:get).with(
146
+ 'test1',
147
+ basic_auth: {
148
+ username: @opts[:username], password: @opts[:update_key]
149
+ },
150
+ query: { hostname: @opts[:tunnelid] }
151
+ ).and_return('more practice, more success!')
152
+
153
+ allow(TunnelBroker::APIResponse).to receive(:new) do |arg1|
154
+ arg1
155
+ end
156
+ end
157
+
158
+ context 'when given more than one arg' do
159
+ it 'should raise ArgumentError' do
160
+ expect { @messenger.call_api(nil) }.to raise_error ArgumentError
161
+ end
162
+ end
163
+
164
+ context 'when passed on args' do
165
+ subject { @messenger.call_api }
166
+
167
+ it { should eql 'more practice, more success!' }
168
+ end
169
+ end
170
+
171
+ describe '#new' do
172
+ context 'when given more than one arg' do
173
+ it 'should raise ArgumentError' do
174
+ expect do
175
+ TunnelBroker::Messenger.new(nil, nil)
176
+ end.to raise_error ArgumentError
177
+ end
178
+ end
179
+
180
+ context 'when given less than one arg' do
181
+ it 'should raise ArgumentError' do
182
+ expect do
183
+ TunnelBroker::Messenger.new
184
+ end.to raise_error ArgumentError
185
+ end
186
+ end
187
+
188
+ context 'when given an option Hash' do
189
+ subject { @messenger }
190
+
191
+ it { should be_an_instance_of TunnelBroker::Messenger }
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,11 @@
1
+ # -*- coding: UTF-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe TunnelBroker::VERSION do
5
+ it { should be_an_instance_of String }
6
+
7
+ it 'should match a semantic version regex check' do
8
+ m = /^\d+\.\d+\.\d+$/
9
+ expect(m.match(subject)).not_to be_nil
10
+ end
11
+ end
@@ -0,0 +1,32 @@
1
+ # -*- coding: UTF-8 -*-
2
+ require 'English'
3
+
4
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
5
+
6
+ require 'tunnelbroker/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'tunnelbroker'
10
+ spec.version = TunnelBroker::VERSION
11
+ spec.date = Time.now.strftime('%Y-%m-%d')
12
+ spec.description = 'Hurricane Electric IPv6 TunnelBroker API client'
13
+ spec.summary = 'HE TunnelBroker API Client'
14
+ spec.authors = ['Tim Heckman']
15
+ spec.email = 'tim@timheckman.net'
16
+ spec.homepage = 'https://github.com/theckman/tunnelbroker'
17
+ spec.license = 'MIT'
18
+ spec.required_ruby_version = '>= 2.0.0'
19
+
20
+ spec.test_files = %x(git ls-files spec/*).split
21
+ spec.files = %x(git ls-files).split
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.5'
24
+ spec.add_development_dependency 'rake', '~> 10.2', '>= 10.2.2'
25
+ spec.add_development_dependency 'rubocop', '~> 0.20'
26
+ spec.add_development_dependency 'rspec', '>= 3.0.0.beta2'
27
+ spec.add_development_dependency 'fuubar', '~> 1.3', '>= 1.3.2'
28
+ spec.add_development_dependency 'coveralls', '~> 0.7'
29
+ spec.add_development_dependency 'simplecov', '~> 0.8', '>= 0.8.2'
30
+
31
+ spec.add_runtime_dependency 'httparty', '~> 0.13'
32
+ end
metadata ADDED
@@ -0,0 +1,199 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tunnelbroker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Heckman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.2'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 10.2.2
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '10.2'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 10.2.2
47
+ - !ruby/object:Gem::Dependency
48
+ name: rubocop
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.20'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.20'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 3.0.0.beta2
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 3.0.0.beta2
75
+ - !ruby/object:Gem::Dependency
76
+ name: fuubar
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.3'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 1.3.2
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '1.3'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 1.3.2
95
+ - !ruby/object:Gem::Dependency
96
+ name: coveralls
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '0.7'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '0.7'
109
+ - !ruby/object:Gem::Dependency
110
+ name: simplecov
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '0.8'
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: 0.8.2
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '0.8'
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: 0.8.2
129
+ - !ruby/object:Gem::Dependency
130
+ name: httparty
131
+ requirement: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - "~>"
134
+ - !ruby/object:Gem::Version
135
+ version: '0.13'
136
+ type: :runtime
137
+ prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - "~>"
141
+ - !ruby/object:Gem::Version
142
+ version: '0.13'
143
+ description: Hurricane Electric IPv6 TunnelBroker API client
144
+ email: tim@timheckman.net
145
+ executables: []
146
+ extensions: []
147
+ extra_rdoc_files: []
148
+ files:
149
+ - ".gitignore"
150
+ - ".rspec"
151
+ - ".travis.yml"
152
+ - Gemfile
153
+ - LICENSE
154
+ - README.md
155
+ - Rakefile
156
+ - lib/tunnelbroker.rb
157
+ - lib/tunnelbroker/api_response.rb
158
+ - lib/tunnelbroker/client.rb
159
+ - lib/tunnelbroker/configuration.rb
160
+ - lib/tunnelbroker/messenger.rb
161
+ - lib/tunnelbroker/version.rb
162
+ - spec/spec_helper.rb
163
+ - spec/unit/tunnelbroker/api_response_spec.rb
164
+ - spec/unit/tunnelbroker/client_spec.rb
165
+ - spec/unit/tunnelbroker/configuration_spec.rb
166
+ - spec/unit/tunnelbroker/messenger_spec.rb
167
+ - spec/unit/tunnelbroker/version_spec.rb
168
+ - tunnelbroker.gemspec
169
+ homepage: https://github.com/theckman/tunnelbroker
170
+ licenses:
171
+ - MIT
172
+ metadata: {}
173
+ post_install_message:
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: 2.0.0
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ requirements: []
188
+ rubyforge_project:
189
+ rubygems_version: 2.2.2
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: HE TunnelBroker API Client
193
+ test_files:
194
+ - spec/spec_helper.rb
195
+ - spec/unit/tunnelbroker/api_response_spec.rb
196
+ - spec/unit/tunnelbroker/client_spec.rb
197
+ - spec/unit/tunnelbroker/configuration_spec.rb
198
+ - spec/unit/tunnelbroker/messenger_spec.rb
199
+ - spec/unit/tunnelbroker/version_spec.rb