docker-api 1.28.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,154 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Docker::Util do
4
- subject { described_class }
5
-
6
- describe '.parse_json' do
7
- subject { described_class.parse_json(arg) }
8
-
9
- context 'when the argument is nil' do
10
- let(:arg) { nil }
11
-
12
- it { should be_nil }
13
- end
14
-
15
- context 'when the argument is empty' do
16
- let(:arg) { '' }
17
-
18
- it { should be_nil }
19
- end
20
-
21
- context 'when the argument is \'null\'' do
22
- let(:arg) { 'null' }
23
-
24
- it { should be_nil }
25
- end
26
-
27
- context 'when the argument is not valid JSON' do
28
- let(:arg) { '~~lol not valid json~~' }
29
-
30
- it 'raises an error' do
31
- expect { subject }.to raise_error Docker::Error::UnexpectedResponseError
32
- end
33
- end
34
-
35
- context 'when the argument is valid JSON' do
36
- let(:arg) { '{"yolo":"swag"}' }
37
-
38
- it 'parses the JSON into a Hash' do
39
- expect(subject).to eq 'yolo' => 'swag'
40
- end
41
- end
42
- end
43
-
44
- describe '.fix_json' do
45
- let(:response) { '{"this":"is"}{"not":"json"}' }
46
- subject { Docker::Util.fix_json(response) }
47
-
48
- it 'fixes the "JSON" response that Docker returns' do
49
- expect(subject).to eq [
50
- {
51
- 'this' => 'is'
52
- },
53
- {
54
- 'not' => 'json'
55
- }
56
- ]
57
- end
58
- end
59
-
60
- describe '.create_dir_tar' do
61
- attr_accessor :tmpdir
62
-
63
- around do |example|
64
- Dir.mktmpdir do |tmpdir|
65
- self.tmpdir = tmpdir
66
- example.call
67
- end
68
- end
69
-
70
- specify do
71
- tar = subject.create_dir_tar tmpdir
72
- expect { FileUtils.rm tar }.to_not raise_error
73
- end
74
- end
75
-
76
- describe '.build_auth_header' do
77
- subject { described_class }
78
-
79
- let(:credentials) {
80
- {
81
- :username => 'test',
82
- :password => 'password',
83
- :email => 'test@example.com',
84
- :serveraddress => 'https://registry.com/'
85
- }
86
- }
87
- let(:credential_string) { credentials.to_json }
88
- let(:encoded_creds) { Base64.encode64(credential_string).gsub(/\n/, '') }
89
- let(:expected_header) {
90
- {
91
- 'X-Registry-Auth' => encoded_creds
92
- }
93
- }
94
-
95
-
96
- context 'given credentials as a Hash' do
97
- it 'returns an X-Registry-Auth header encoded' do
98
- expect(subject.build_auth_header(credentials)).to eq(expected_header)
99
- end
100
- end
101
-
102
- context 'given credentials as a String' do
103
- it 'returns an X-Registry-Auth header encoded' do
104
- expect(
105
- subject.build_auth_header(credential_string)
106
- ).to eq(expected_header)
107
- end
108
- end
109
- end
110
-
111
- describe '.build_config_header' do
112
- subject { described_class }
113
-
114
- let(:credentials) {
115
- {
116
- :username => 'test',
117
- :password => 'password',
118
- :email => 'test@example.com',
119
- :serveraddress => 'https://registry.com/'
120
- }
121
- }
122
-
123
- let(:credentials_object) {
124
- {
125
- :'https://registry.com/' => {
126
- :username => 'test',
127
- :password => 'password',
128
- :email => 'test@example.com',
129
- }
130
- }.to_json
131
- }
132
-
133
- let(:encoded_creds) { Base64.encode64(credentials_object).gsub(/\n/, '') }
134
- let(:expected_header) {
135
- {
136
- 'X-Registry-Config' => encoded_creds
137
- }
138
- }
139
-
140
- context 'given credentials as a Hash' do
141
- it 'returns an X-Registry-Config header encoded' do
142
- expect(subject.build_config_header(credentials)).to eq(expected_header)
143
- end
144
- end
145
-
146
- context 'given credentials as a String' do
147
- it 'returns an X-Registry-Config header encoded' do
148
- expect(
149
- subject.build_config_header(credentials.to_json)
150
- ).to eq(expected_header)
151
- end
152
- end
153
- end
154
- 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