Class: NamespaceMiddlewareTest

Inherits:
Minitest::Test
  • Object
show all
Defined in:
lib/kube/cluster/middleware/namespace.rb

Constant Summary collapse

Middleware =
Kube::Cluster::Middleware

Instance Method Summary collapse

Instance Method Details

#test_overwrites_existing_namespaceObject



84
85
86
87
88
89
90
91
92
93
# File 'lib/kube/cluster/middleware/namespace.rb', line 84

def test_overwrites_existing_namespace
  m = manifest(Kube::Cluster["ConfigMap"].new {
    .name = "test"
    .namespace = "old"
  })

  Middleware::Namespace.new("new").call(m)

  assert_equal "new", m.resources.first.to_h.dig(:metadata, :namespace)
end

#test_returns_new_resource_instanceObject



95
96
97
98
99
100
101
102
# File 'lib/kube/cluster/middleware/namespace.rb', line 95

def test_returns_new_resource_instance
  resource = Kube::Cluster["ConfigMap"].new { .name = "test" }
  m = manifest(resource)

  Middleware::Namespace.new("production").call(m)

  refute_same resource, m.resources.first
end

#test_sets_namespace_on_configmapObject



44
45
46
47
48
49
50
# File 'lib/kube/cluster/middleware/namespace.rb', line 44

def test_sets_namespace_on_configmap
  m = manifest(Kube::Cluster["ConfigMap"].new { .name = "test" })

  Middleware::Namespace.new("production").call(m)

  assert_equal "production", m.resources.first.to_h.dig(:metadata, :namespace)
end

#test_sets_namespace_on_deploymentObject



52
53
54
55
56
57
58
# File 'lib/kube/cluster/middleware/namespace.rb', line 52

def test_sets_namespace_on_deployment
  m = manifest(Kube::Cluster["Deployment"].new { .name = "web" })

  Middleware::Namespace.new("staging").call(m)

  assert_equal "staging", m.resources.first.to_h.dig(:metadata, :namespace)
end

#test_skips_cluster_roleObject



68
69
70
71
72
73
74
# File 'lib/kube/cluster/middleware/namespace.rb', line 68

def test_skips_cluster_role
  m = manifest(Kube::Cluster["ClusterRole"].new { .name = "admin" })

  Middleware::Namespace.new("production").call(m)

  assert_nil m.resources.first.to_h.dig(:metadata, :namespace)
end

#test_skips_cluster_role_bindingObject



76
77
78
79
80
81
82
# File 'lib/kube/cluster/middleware/namespace.rb', line 76

def test_skips_cluster_role_binding
  m = manifest(Kube::Cluster["ClusterRoleBinding"].new { .name = "admin-binding" })

  Middleware::Namespace.new("production").call(m)

  assert_nil m.resources.first.to_h.dig(:metadata, :namespace)
end

#test_skips_namespace_resourceObject



60
61
62
63
64
65
66
# File 'lib/kube/cluster/middleware/namespace.rb', line 60

def test_skips_namespace_resource
  m = manifest(Kube::Cluster["Namespace"].new { .name = "my-ns" })

  Middleware::Namespace.new("production").call(m)

  assert_nil m.resources.first.to_h.dig(:metadata, :namespace)
end