docker-api 1.31.0 → 1.32.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.
@@ -1,97 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Docker::Messages do
4
- shared_examples_for "two equal messages" do
5
- it "has the same messages as we expect" do
6
- expect(messages.all_messages).to eq(expected.all_messages)
7
- expect(messages.stdout_messages).to eq(expected.stdout_messages)
8
- expect(messages.stderr_messages).to eq(expected.stderr_messages)
9
- expect(messages.buffer).to eq(expected.buffer)
10
- end
11
- end
12
-
13
- describe '.decipher_messages' do
14
- shared_examples_for "decipher_messages of raw_test" do
15
- let(:messages) {
16
- subject.decipher_messages(raw_text)
17
- }
18
-
19
- it_behaves_like "two equal messages"
20
- end
21
-
22
- context 'given both standard out and standard error' do
23
- let(:raw_text) {
24
- "\x01\x00\x00\x00\x00\x00\x00\x01a\x02\x00\x00\x00\x00\x00\x00\x01b"
25
- }
26
- let(:expected) {
27
- Docker::Messages.new(["a"], ["b"], ["a","b"], "")
28
- }
29
-
30
- it_behaves_like "decipher_messages of raw_test"
31
- end
32
-
33
- context 'given a single header' do
34
- let(:raw_text) { "\x01\x00\x00\x00\x00\x00\x00\x01a" }
35
- let(:expected) {
36
- Docker::Messages.new(["a"], [], ["a"], "")
37
- }
38
-
39
- it_behaves_like "decipher_messages of raw_test"
40
- end
41
-
42
- context 'given two headers' do
43
- let(:raw_text) {
44
- "\x01\x00\x00\x00\x00\x00\x00\x01a\x01\x00\x00\x00\x00\x00\x00\x01b"
45
- }
46
-
47
- let(:expected) {
48
- Docker::Messages.new(["a", "b"], [], ["a","b"], "")
49
- }
50
-
51
- it_behaves_like "decipher_messages of raw_test"
52
- end
53
-
54
- context 'given a header for text longer then 255 characters' do
55
- let(:raw_text) {
56
- "\x01\x00\x00\x00\x00\x00\x01\x01" + ("a" * 257)
57
- }
58
- let(:expected) {
59
- Docker::Messages.new([("a" * 257)], [], [("a" * 257)], "")
60
- }
61
-
62
- it_behaves_like "decipher_messages of raw_test"
63
- end
64
- end
65
-
66
- describe "#append" do
67
- context "appending one set of messages on another" do
68
- let(:messages) {
69
- Docker::Messages.new([], [], [], "")
70
- }
71
-
72
- before do
73
- messages.append(new_messages)
74
- end
75
-
76
- context "with a buffer" do
77
- let(:new_messages) {
78
- Docker::Messages.new(["a"], [], ["a"], "b")
79
- }
80
- let(:expected) {
81
- Docker::Messages.new(["a"], [], ["a"], "")
82
- }
83
- it_behaves_like "two equal messages"
84
- end
85
-
86
- context "without a buffer" do
87
- let(:new_messages) {
88
- Docker::Messages.new(["a"], [], ["a"], "")
89
- }
90
- let(:expected) {
91
- Docker::Messages.new(["a"], [], ["a"], "")
92
- }
93
- it_behaves_like "two equal messages"
94
- end
95
- end
96
- end
97
- end
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Docker::MessagesStack do
4
-
5
- describe '#append' do
6
- context 'without limits' do |variable|
7
- it 'does not limit stack size by default' do
8
- data = ['foo', 'bar']
9
- msg = Docker::Messages.new(data, [], data)
10
- expect(subject.messages).not_to receive(:shift)
11
- 1000.times { subject.append(msg) }
12
- end
13
- end
14
-
15
- context 'with size limit' do
16
- let(:subject) { described_class.new(100) }
17
-
18
- it 'limits stack to given size' do
19
- data = ['foo', 'bar']
20
- msg = Docker::Messages.new(data, [], data)
21
- expect(subject.messages).to receive(:shift).exactly(1900).times
22
- 1000.times { subject.append(msg) }
23
- end
24
- end
25
- end
26
- end
@@ -1,150 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Docker::Network, docker_1_9: true do
4
- let(:name) do |example|
5
- example.description.downcase.gsub('\s', '-')
6
- end
7
-
8
- describe '#to_s' do
9
- subject { described_class.new(Docker.connection, info) }
10
- let(:connection) { Docker.connection }
11
-
12
- let(:id) do
13
- 'a6c5ffd25e07a6c906accf804174b5eb6a9d2f9e07bccb8f5aa4f4de5be6d01d'
14
- end
15
-
16
- let(:info) do
17
- {
18
- 'Name' => 'bridge',
19
- 'Scope' => 'local',
20
- 'Driver' => 'bridge',
21
- 'IPAM' => {
22
- 'Driver' => 'default',
23
- 'Config' => [{ 'Subnet' => '172.17.0.0/16' }]
24
- },
25
- 'Containers' => {},
26
- 'Options' => {
27
- 'com.docker.network.bridge.default_bridge' => 'true',
28
- 'com.docker.network.bridge.enable_icc' => 'true',
29
- 'com.docker.network.bridge.enable_ip_masquerade' => 'true',
30
- 'com.docker.network.bridge.host_binding_ipv4' => '0.0.0.0',
31
- 'com.docker.network.bridge.name' => 'docker0',
32
- 'com.docker.network.driver.mtu' => '1500'
33
- },
34
- 'id' => id
35
- }
36
- end
37
-
38
- let(:expected_string) do
39
- "Docker::Network { :id => #{id}, :info => #{info.inspect}, "\
40
- ":connection => #{connection} }"
41
- end
42
-
43
- its(:to_s) { should == expected_string }
44
- end
45
-
46
- describe '.create' do
47
- let!(:id) { subject.id }
48
- subject { described_class.create(name) }
49
- after { described_class.remove(id) }
50
-
51
- it 'creates a Network' do
52
- expect(Docker::Network.all.map(&:id)).to include(id)
53
- end
54
- end
55
-
56
- describe '.remove' do
57
- let(:id) { subject.id }
58
- subject { described_class.create(name) }
59
-
60
- it 'removes the Network' do
61
- described_class.remove(id)
62
- expect(Docker::Network.all.map(&:id)).to_not include(id)
63
- end
64
- end
65
-
66
- describe '.get' do
67
- after do
68
- described_class.remove(name)
69
- end
70
-
71
- let!(:network) { described_class.create(name) }
72
-
73
- it 'returns a network' do
74
- expect(Docker::Network.get(name).id).to eq(network.id)
75
- end
76
- end
77
-
78
- describe '.all' do
79
- let!(:networks) do
80
- 5.times.map { |i| described_class.create("#{name}-#{i}") }
81
- end
82
-
83
- after do
84
- networks.each(&:remove)
85
- end
86
-
87
- it 'should return all networks' do
88
- expect(Docker::Network.all.map(&:id)).to include(*networks.map(&:id))
89
- end
90
- end
91
-
92
- describe '#connect' do
93
- let!(:container) do
94
- Docker::Container.create(
95
- 'Cmd' => %w(sleep 10),
96
- 'Image' => 'debian:wheezy'
97
- )
98
- end
99
- subject { described_class.create(name) }
100
-
101
- before(:each) { container.start }
102
- after(:each) do
103
- container.kill!.remove
104
- subject.remove
105
- end
106
-
107
- it 'connects a container to a network' do
108
- subject.connect(container.id)
109
- expect(subject.info['Containers']).to include(container.id)
110
- end
111
- end
112
-
113
- describe '#disconnect' do
114
- let!(:container) do
115
- Docker::Container.create(
116
- 'Cmd' => %w(sleep 10),
117
- 'Image' => 'debian:wheezy'
118
- )
119
- end
120
-
121
- subject { described_class.create(name) }
122
-
123
- before(:each) do
124
- container.start
125
- sleep 1
126
- subject.connect(container.id)
127
- end
128
-
129
- after(:each) do
130
- container.kill!.remove
131
- subject.remove
132
- end
133
-
134
- it 'connects a container to a network' do
135
- subject.disconnect(container.id)
136
- expect(subject.info['Containers']).not_to include(container.id)
137
- end
138
- end
139
-
140
- describe '#remove' do
141
- let(:id) { subject.id }
142
- let(:name) { 'test-network-remove' }
143
- subject { described_class.create(name) }
144
-
145
- it 'removes the Network' do
146
- subject.remove
147
- expect(Docker::Network.all.map(&:id)).to_not include(id)
148
- end
149
- end
150
- end
@@ -1,170 +0,0 @@
1
- require 'spec_helper'
2
- require 'tempfile'
3
-
4
- describe Docker::Util do
5
- subject { described_class }
6
-
7
- describe '.parse_json' do
8
- subject { described_class.parse_json(arg) }
9
-
10
- context 'when the argument is nil' do
11
- let(:arg) { nil }
12
-
13
- it { should be_nil }
14
- end
15
-
16
- context 'when the argument is empty' do
17
- let(:arg) { '' }
18
-
19
- it { should be_nil }
20
- end
21
-
22
- context 'when the argument is \'null\'' do
23
- let(:arg) { 'null' }
24
-
25
- it { should be_nil }
26
- end
27
-
28
- context 'when the argument is not valid JSON' do
29
- let(:arg) { '~~lol not valid json~~' }
30
-
31
- it 'raises an error' do
32
- expect { subject }.to raise_error Docker::Error::UnexpectedResponseError
33
- end
34
- end
35
-
36
- context 'when the argument is valid JSON' do
37
- let(:arg) { '{"yolo":"swag"}' }
38
-
39
- it 'parses the JSON into a Hash' do
40
- expect(subject).to eq 'yolo' => 'swag'
41
- end
42
- end
43
- end
44
-
45
- describe '.fix_json' do
46
- let(:response) { '{"this":"is"}{"not":"json"}' }
47
- subject { Docker::Util.fix_json(response) }
48
-
49
- it 'fixes the "JSON" response that Docker returns' do
50
- expect(subject).to eq [
51
- {
52
- 'this' => 'is'
53
- },
54
- {
55
- 'not' => 'json'
56
- }
57
- ]
58
- end
59
- end
60
-
61
- describe '.create_dir_tar' do
62
- attr_accessor :tmpdir
63
-
64
- around do |example|
65
- Dir.mktmpdir do |tmpdir|
66
- self.tmpdir = tmpdir
67
- example.call
68
- end
69
- end
70
-
71
- specify do
72
- tar = subject.create_dir_tar tmpdir
73
- expect { FileUtils.rm tar }.to_not raise_error
74
- end
75
- end
76
-
77
- describe '.build_auth_header' do
78
- subject { described_class }
79
-
80
- let(:credentials) {
81
- {
82
- :username => 'test',
83
- :password => 'password',
84
- :email => 'test@example.com',
85
- :serveraddress => 'https://registry.com/'
86
- }
87
- }
88
- let(:credential_string) { credentials.to_json }
89
- let(:encoded_creds) { Base64.encode64(credential_string).gsub(/\n/, '') }
90
- let(:expected_header) {
91
- {
92
- 'X-Registry-Auth' => encoded_creds
93
- }
94
- }
95
-
96
-
97
- context 'given credentials as a Hash' do
98
- it 'returns an X-Registry-Auth header encoded' do
99
- expect(subject.build_auth_header(credentials)).to eq(expected_header)
100
- end
101
- end
102
-
103
- context 'given credentials as a String' do
104
- it 'returns an X-Registry-Auth header encoded' do
105
- expect(
106
- subject.build_auth_header(credential_string)
107
- ).to eq(expected_header)
108
- end
109
- end
110
- end
111
-
112
- describe '.build_config_header' do
113
- subject { described_class }
114
-
115
- let(:credentials) {
116
- {
117
- :username => 'test',
118
- :password => 'password',
119
- :email => 'test@example.com',
120
- :serveraddress => 'https://registry.com/'
121
- }
122
- }
123
-
124
- let(:credentials_object) {
125
- {
126
- :'https://registry.com/' => {
127
- :username => 'test',
128
- :password => 'password',
129
- :email => 'test@example.com',
130
- }
131
- }.to_json
132
- }
133
-
134
- let(:encoded_creds) { Base64.encode64(credentials_object).gsub(/\n/, '') }
135
- let(:expected_header) {
136
- {
137
- 'X-Registry-Config' => encoded_creds
138
- }
139
- }
140
-
141
- context 'given credentials as a Hash' do
142
- it 'returns an X-Registry-Config header encoded' do
143
- expect(subject.build_config_header(credentials)).to eq(expected_header)
144
- end
145
- end
146
-
147
- context 'given credentials as a String' do
148
- it 'returns an X-Registry-Config header encoded' do
149
- expect(
150
- subject.build_config_header(credentials.to_json)
151
- ).to eq(expected_header)
152
- end
153
- end
154
- end
155
-
156
- describe '.filesystem_permissions' do
157
- it 'returns the permissions on a file' do
158
- file = Tempfile.new('test_file')
159
- file.close
160
- expected_permissions = 0600
161
- File.chmod(expected_permissions, file.path)
162
-
163
- actual_permissions = subject.filesystem_permissions(file.path)
164
-
165
- file.unlink
166
- expect(actual_permissions).to eql(expected_permissions)
167
- end
168
- end
169
-
170
- end
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
-
3
- # Volume requests are actually slow enough to occasionally not work
4
- # Use sleep statements to manage that
5
- describe Docker::Volume, :docker_1_9 do
6
- let(:name) { "ArbitraryNameForTheRakeTestVolume" }
7
-
8
- describe '.create' do
9
- let(:volume) { Docker::Volume.create(name) }
10
-
11
- after { volume.remove }
12
-
13
- it 'creates a volume' do
14
- expect(volume.id).to eq(name)
15
- end
16
- end
17
-
18
- describe '.get' do
19
- let(:volume) { Docker::Volume.get(name) }
20
-
21
- before { Docker::Volume.create(name); sleep 1 }
22
- after { volume.remove }
23
-
24
- it 'gets volume details' do
25
- expect(volume.id).to eq(name)
26
- expect(volume.info).to_not be_empty
27
- end
28
- end
29
-
30
- describe '.all' do
31
- after { Docker::Volume.get(name).remove }
32
-
33
- it 'gets a list of volumes' do
34
- expect { Docker::Volume.create(name); sleep 1 }.to change { Docker::Volume.all.length }.by(1)
35
- end
36
- end
37
-
38
- describe '#remove' do
39
- it 'removes a volume' do
40
- volume = Docker::Volume.create(name)
41
- sleep 1
42
- expect { volume.remove }.to change { Docker::Volume.all.length }.by(-1)
43
- end
44
- end
45
-
46
- end