File: test_namespace.rb

package info (click to toggle)
ruby-kubeclient 4.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,112 kB
  • sloc: ruby: 4,225; makefile: 6
file content (61 lines) | stat: -rw-r--r-- 1,995 bytes parent folder | download
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
# frozen_string_literal: true

require_relative 'test_helper'

# Namespace entity tests
class TestNamespace < Minitest::Test
  def test_get_namespace_v1
    stub_core_api_list
    stub_request(:get, %r{/namespaces})
      .to_return(body: open_test_file('namespace.json'), status: 200)

    client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
    namespace = client.get_namespace('staging')

    assert_instance_of(Kubeclient::Resource, namespace)
    assert_equal('e388bc10-c021-11e4-a514-3c970e4a436a', namespace.metadata.uid)
    assert_equal('staging', namespace.metadata.name)
    assert_equal('1168', namespace.metadata.resourceVersion)
    assert_equal('v1', namespace.apiVersion)

    assert_requested(
      :get,
      'http://localhost:8080/api/v1/namespaces/staging',
      times: 1
    )
  end

  def test_delete_namespace_v1
    our_namespace = Kubeclient::Resource.new
    our_namespace.metadata = {}
    our_namespace.metadata.name = 'staging'

    stub_core_api_list
    stub_request(:delete, %r{/namespaces})
      .to_return(body: open_test_file('namespace.json'), status: 200)
    client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
    our_namespace = client.delete_namespace(our_namespace.metadata.name)
    assert_kind_of(RecursiveOpenStruct, our_namespace)

    assert_requested(
      :delete,
      'http://localhost:8080/api/v1/namespaces/staging',
      times: 1
    )
  end

  def test_create_namespace
    stub_core_api_list
    stub_request(:post, %r{/namespaces})
      .to_return(body: open_test_file('created_namespace.json'), status: 201)

    namespace = Kubeclient::Resource.new
    namespace.metadata = {}
    namespace.metadata.name = 'development'

    client = Kubeclient::Client.new('http://localhost:8080/api/')
    created_namespace = client.create_namespace(namespace)
    assert_instance_of(Kubeclient::Resource, created_namespace)
    assert_equal(namespace.metadata.name, created_namespace.metadata.name)
  end
end