Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test_pod.rb « test « kubeclient « gems « vendor - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: afad1774f5ef42f830c10de45c352bdc5516da42 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
require_relative 'test_helper'

# Pod entity tests
class TestPod < MiniTest::Test
  def test_get_from_json_v1
    stub_core_api_list
    stub_request(:get, %r{/pods})
      .to_return(body: open_test_file('pod.json'), status: 200)

    client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
    pod = client.get_pod('redis-master-pod', 'default')

    assert_instance_of(Kubeclient::Resource, pod)
    assert_equal('redis-master3', pod.metadata.name)
    assert_equal('dockerfile/redis', pod.spec.containers[0]['image'])

    assert_requested(
      :get,
      'http://localhost:8080/api/v1',
      times: 1
    )
    assert_requested(
      :get,
      'http://localhost:8080/api/v1/namespaces/default/pods/redis-master-pod',
      times: 1
    )
  end

  def test_get_chunks
    stub_core_api_list
    stub_request(:get, %r{/pods})
      .to_return(body: open_test_file('pods_1.json'), status: 200)

    client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
    pods = client.get_pods(limit: 2)

    assert_equal(2, pods.count)
    assert_equal('eyJ2IjoibWV0YS5rOHMua', pods.continue)

    continue = pods.continue

    stub_request(:get, %r{/pods})
      .to_return(body: open_test_file('pods_2.json'), status: 200)

    pods = client.get_pods(limit: 2, continue: continue)
    assert_equal(2, pods.count)
    assert_nil(pods.continue)

    assert_requested(
      :get,
      'http://localhost:8080/api/v1',
      times: 1
    )
    assert_requested(
      :get,
      'http://localhost:8080/api/v1/pods?limit=2',
      times: 1
    )
    assert_requested(
      :get,
      "http://localhost:8080/api/v1/pods?continue=#{continue}&limit=2",
      times: 1
    )
  end

  def test_get_chunks_410_gone
    stub_core_api_list
    stub_request(:get, %r{/pods})
      .to_return(body: open_test_file('pods_410.json'), status: 410)

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

    err = assert_raises Kubeclient::HttpError do
      client.get_pods(limit: 2, continue: 'eyJ2IjoibWV0YS5')
    end

    assert_equal(err.message,
                 "The provided from parameter is too old to display a consistent list result. \
You must start a new list without the from.")
  end
end