Skip to content

Commit 08a06d6

Browse files
committed
Fix unit tests.
1 parent 4d56211 commit 08a06d6

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

kubernetes/spec/config/incluster_config_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
require 'spec_helper'
1616
require 'config/matchers'
17+
require 'helpers/file_fixtures'
1718

1819
require 'kubernetes/config/incluster_config'
1920

@@ -27,16 +28,16 @@
2728
Kubernetes::InClusterConfig::SERVICE_HOST_ENV_NAME => 'localhost',
2829
Kubernetes::InClusterConfig::SERVICE_PORT_ENV_NAME => '443',
2930
})
30-
c.instance_variable_set(:@ca_cert, file_fixture('certs/ca.crt').to_s)
31-
c.instance_variable_set(:@token_file, file_fixture('tokens/token').to_s)
31+
c.instance_variable_set(:@ca_cert, Kubernetes::Testing::file_fixture('certs/ca.crt').to_s)
32+
c.instance_variable_set(:@token_file, Kubernetes::Testing::file_fixture('tokens/token').to_s)
3233
end
3334
end
3435

3536
it 'should configure configuration' do
3637
expected = Kubernetes::Configuration.new do |c|
3738
c.scheme = 'https'
3839
c.host = 'localhost:443'
39-
c.ssl_ca_cert = file_fixture('certs/ca.crt').to_s
40+
c.ssl_ca_cert = Kubernetes::Testing::file_fixture('certs/ca.crt').to_s
4041
c.api_key['authorization'] = 'Bearer token1'
4142
end
4243
actual = Kubernetes::Configuration.new
@@ -53,8 +54,8 @@
5354
Kubernetes::InClusterConfig::SERVICE_HOST_ENV_NAME => 'localhost',
5455
Kubernetes::InClusterConfig::SERVICE_PORT_ENV_NAME => '443',
5556
})
56-
c.instance_variable_set(:@ca_cert, file_fixture('certs/ca.crt').to_s)
57-
c.instance_variable_set(:@token_file, file_fixture('tokens/token').to_s)
57+
c.instance_variable_set(:@ca_cert, Kubernetes::Testing::file_fixture('certs/ca.crt').to_s)
58+
c.instance_variable_set(:@token_file, Kubernetes::Testing::file_fixture('tokens/token').to_s)
5859
end
5960
end
6061

kubernetes/spec/config/kube_config_spec.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
require 'spec_helper'
1717
require 'config/matchers'
1818
require 'fixtures/config/kube_config_hash'
19+
require 'helpers/file_fixtures'
1920

2021
require 'kubernetes/config/kube_config'
2122

2223

2324
describe Kubernetes::KubeConfig do
24-
let(:kube_config) { Kubernetes::KubeConfig.new(file_fixture('config/config').to_s, TEST_KUBE_CONFIG) }
25+
let(:kube_config) { Kubernetes::KubeConfig.new(Kubernetes::Testing::file_fixture('config/config').to_s, TEST_KUBE_CONFIG) }
2526

2627
context '#configure' do
2728
context 'if non user context is given' do
@@ -42,9 +43,9 @@
4243
expected = Kubernetes::Configuration.new do |c|
4344
c.scheme = 'https'
4445
c.host = 'test-host:443'
45-
c.ssl_ca_cert = file_fixture('certs/ca.crt').to_s
46-
c.cert_file = file_fixture('certs/client.crt').to_s
47-
c.key_file = file_fixture('certs/client.key').to_s
46+
c.ssl_ca_cert = Kubernetes::Testing::file_fixture('certs/ca.crt').to_s
47+
c.cert_file = Kubernetes::Testing::file_fixture('certs/client.crt').to_s
48+
c.key_file = Kubernetes::Testing::file_fixture('certs/client.key').to_s
4849
end
4950
actual = Kubernetes::Configuration.new
5051

@@ -58,7 +59,7 @@
5859
expected = Kubernetes::Configuration.new do |c|
5960
c.scheme = 'https'
6061
c.host = 'test-host:443'
61-
c.ssl_ca_cert = file_fixture('certs/ca.crt').to_s
62+
c.ssl_ca_cert = Kubernetes::Testing::file_fixture('certs/ca.crt').to_s
6263
c.api_key['authorization'] = "Bearer #{TEST_DATA_BASE64}"
6364
end
6465
actual = Kubernetes::Configuration.new
@@ -71,15 +72,15 @@
7172

7273
context '#config' do
7374
context 'if config hash is not given when it is initialized' do
74-
let(:kube_config) { Kubernetes::KubeConfig.new(file_fixture('config/empty').to_s) }
75+
let(:kube_config) { Kubernetes::KubeConfig.new(Kubernetes::Testing::file_fixture('config/empty').to_s) }
7576
it 'should load config' do
7677
expect(kube_config.config).to eq({})
7778
end
7879
end
7980

8081
context 'if config hash is given when it is initialized' do
8182
let(:given_hash) { {given: 'hash'} }
82-
let(:kube_config) { Kubernetes::KubeConfig.new(file_fixture('config/empty').to_s, given_hash) }
83+
let(:kube_config) { Kubernetes::KubeConfig.new(Kubernetes::Testing::file_fixture('config/empty').to_s, given_hash) }
8384

8485
it 'should not load config' do
8586
expect(kube_config.config).to eq(given_hash)

kubernetes/spec/fixtures/config/kube_config_hash.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
require 'base64'
16+
require 'helpers/file_fixtures'
1617

1718

1819
TEST_TOKEN_FILE = Kubernetes::Testing.file_fixture('tokens/token')

kubernetes/spec/helpers/file_fixtures.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313

14+
require 'pathname'
15+
1416
module Kubernetes
1517
module Testing
1618
module FileFixtures

kubernetes/spec/utils_spec.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
require 'spec_helper'
1616
require 'config/matchers'
1717
require 'fixtures/config/kube_config_hash'
18+
require 'helpers/file_fixtures'
1819

1920
require 'kubernetes/utils'
2021

@@ -28,8 +29,8 @@
2829
Kubernetes::InClusterConfig::SERVICE_HOST_ENV_NAME => 'localhost',
2930
Kubernetes::InClusterConfig::SERVICE_PORT_ENV_NAME => '443',
3031
})
31-
c.instance_variable_set(:@ca_cert, file_fixture('certs/ca.crt').to_s)
32-
c.instance_variable_set(:@token_file, file_fixture('tokens/token').to_s)
32+
c.instance_variable_set(:@ca_cert, Kubernetes::Testing::file_fixture('certs/ca.crt').to_s)
33+
c.instance_variable_set(:@token_file, Kubernetes::Testing::file_fixture('tokens/token').to_s)
3334
end
3435
end
3536

@@ -38,7 +39,7 @@
3839
expected = Kubernetes::Configuration.new do |c|
3940
c.scheme = 'https'
4041
c.host = 'localhost:443'
41-
c.ssl_ca_cert = file_fixture('certs/ca.crt').to_s
42+
c.ssl_ca_cert = Kubernetes::Testing::file_fixture('certs/ca.crt').to_s
4243
c.api_key['authorization'] = 'Bearer token1'
4344
end
4445
actual = Kubernetes::Configuration.new
@@ -49,17 +50,17 @@
4950
end
5051

5152
describe '.load_kube_config' do
52-
let(:kube_config) { Kubernetes::KubeConfig.new(file_fixture('config/config').to_s, TEST_KUBE_CONFIG) }
53+
let(:kube_config) { Kubernetes::KubeConfig.new(Kubernetes::Testing::file_fixture('config/config').to_s, TEST_KUBE_CONFIG) }
5354

5455
it 'should configure client configuration from kube_config' do
5556
kubeconfig_path = 'kubeconfig/path'
5657
allow(Kubernetes::KubeConfig).to receive(:new).with(kubeconfig_path).and_return(kube_config)
5758
expected = Kubernetes::Configuration.new do |c|
5859
c.scheme = 'https'
5960
c.host = 'test-host:443'
60-
c.ssl_ca_cert = file_fixture('certs/ca.crt').to_s
61-
c.cert_file = file_fixture('certs/client.crt').to_s
62-
c.key_file = file_fixture('certs/client.key').to_s
61+
c.ssl_ca_cert = Kubernetes::Testing::file_fixture('certs/ca.crt').to_s
62+
c.cert_file = Kubernetes::Testing::file_fixture('certs/client.crt').to_s
63+
c.key_file = Kubernetes::Testing::file_fixture('certs/client.key').to_s
6364
end
6465
actual = Kubernetes::Configuration.new
6566

0 commit comments

Comments
 (0)