summaryrefslogtreecommitdiff
path: root/vendor/gems/kubeclient/test/test_secret.rb
blob: ec129075a143c2a4b3536d319c3a497b3017c0d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require_relative 'test_helper'

# Namespace entity tests
class TestSecret < MiniTest::Test
  def test_get_secret_v1
    stub_core_api_list
    stub_request(:get, %r{/secrets})
      .to_return(body: open_test_file('created_secret.json'),
                 status: 200)

    client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
    secret = client.get_secret('test-secret', 'dev')

    assert_instance_of(Kubeclient::Resource, secret)
    assert_equal('4e38a198-2bcb-11e5-a483-0e840567604d', secret.metadata.uid)
    assert_equal('test-secret', secret.metadata.name)
    assert_equal('v1', secret.apiVersion)
    assert_equal('Y2F0J3MgYXJlIGF3ZXNvbWUK', secret.data['super-secret'])

    assert_requested(:get,
                     'http://localhost:8080/api/v1/namespaces/dev/secrets/test-secret',
                     times: 1)
  end

  def test_delete_secret_v1
    stub_core_api_list
    stub_request(:delete, %r{/secrets})
      .to_return(status: 200, body: open_test_file('created_secret.json'))

    client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
    secret = client.delete_secret('test-secret', 'dev')
    assert_kind_of(RecursiveOpenStruct, secret)

    assert_requested(:delete,
                     'http://localhost:8080/api/v1/namespaces/dev/secrets/test-secret',
                     times: 1)
  end

  def test_create_secret_v1
    stub_core_api_list
    stub_request(:post, %r{/secrets})
      .to_return(body: open_test_file('created_secret.json'),
                 status: 201)

    secret = Kubeclient::Resource.new
    secret.metadata = {}
    secret.metadata.name = 'test-secret'
    secret.metadata.namespace = 'dev'
    secret.data = {}
    secret.data['super-secret'] = 'Y2F0J3MgYXJlIGF3ZXNvbWUK'

    client = Kubeclient::Client.new('http://localhost:8080/api/')
    created_secret = client.create_secret(secret)
    assert_instance_of(Kubeclient::Resource, created_secret)
    assert_equal(secret.metadata.name, created_secret.metadata.name)
    assert_equal(secret.metadata.namespace, created_secret.metadata.namespace)
    assert_equal(
      secret.data['super-secret'],
      created_secret.data['super-secret']
    )
  end
end