2021-09-28 13:11:36 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require_relative '../../test_helper'
|
|
|
|
|
|
|
|
class Test < ChartTest
|
|
|
|
@@chart = Chart.new('charts/library/common-test')
|
|
|
|
|
|
|
|
describe @@chart.name do
|
|
|
|
describe 'ingress' do
|
2021-09-28 22:11:52 +00:00
|
|
|
baseValues = {
|
|
|
|
ingress: {
|
|
|
|
main: {
|
|
|
|
enabled: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
service: {
|
|
|
|
main: {
|
|
|
|
ports: {
|
|
|
|
http: {
|
|
|
|
port: 8080
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-28 13:11:36 +00:00
|
|
|
it 'disabled when ingress.main.enabled: false' do
|
2021-09-28 22:11:52 +00:00
|
|
|
values = baseValues.deep_merge_override({
|
2021-09-28 13:11:36 +00:00
|
|
|
ingress: {
|
|
|
|
main: {
|
|
|
|
enabled: false
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 22:11:52 +00:00
|
|
|
})
|
2021-09-28 13:11:36 +00:00
|
|
|
chart.value values
|
2021-09-28 22:11:52 +00:00
|
|
|
|
2021-09-28 13:11:36 +00:00
|
|
|
assert_nil(resource('Ingress'))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'enabled when ingress.main.enabled: true' do
|
2021-09-28 22:11:52 +00:00
|
|
|
values = baseValues
|
2021-09-28 13:11:36 +00:00
|
|
|
chart.value values
|
2021-09-28 22:11:52 +00:00
|
|
|
|
2021-09-28 13:11:36 +00:00
|
|
|
refute_nil(resource('Ingress'))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'tls can be provided' do
|
|
|
|
expectedPath = 'common-test.path'
|
2021-09-28 22:11:52 +00:00
|
|
|
values = baseValues.deep_merge_override({
|
2021-09-28 13:11:36 +00:00
|
|
|
ingress: {
|
|
|
|
main: {
|
|
|
|
tls: [
|
|
|
|
{
|
|
|
|
hosts: [ 'hostname' ],
|
|
|
|
secretName: 'secret-name'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 22:11:52 +00:00
|
|
|
})
|
2021-09-28 13:11:36 +00:00
|
|
|
chart.value values
|
2021-09-28 22:11:52 +00:00
|
|
|
|
|
|
|
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test" }
|
2021-09-28 13:11:36 +00:00
|
|
|
refute_nil(ingress)
|
|
|
|
assert_equal(values[:ingress][:main][:tls][0][:hosts][0], ingress["spec"]["tls"][0]["hosts"][0])
|
|
|
|
assert_equal(values[:ingress][:main][:tls][0][:secretName], ingress["spec"]["tls"][0]["secretName"])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'tls secret can be left empty' do
|
|
|
|
expectedPath = 'common-test.path'
|
2021-09-28 22:11:52 +00:00
|
|
|
values = baseValues.deep_merge_override({
|
2021-09-28 13:11:36 +00:00
|
|
|
ingress: {
|
2021-09-28 22:11:52 +00:00
|
|
|
main:{
|
2021-09-28 13:11:36 +00:00
|
|
|
tls: [
|
|
|
|
{
|
|
|
|
hosts: [ 'hostname' ]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 22:11:52 +00:00
|
|
|
})
|
2021-09-28 13:11:36 +00:00
|
|
|
chart.value values
|
2021-09-28 22:11:52 +00:00
|
|
|
|
|
|
|
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test" }
|
2021-09-28 13:11:36 +00:00
|
|
|
refute_nil(ingress)
|
|
|
|
assert_equal(values[:ingress][:main][:tls][0][:hosts][0], ingress["spec"]["tls"][0]["hosts"][0])
|
|
|
|
assert_equal(false, ingress["spec"]["tls"][0].key?("secretName"))
|
|
|
|
assert_nil(ingress["spec"]["tls"][0]["secretName"])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'tls secret template can be provided' do
|
|
|
|
expectedPath = 'common-test.path'
|
2021-09-28 22:11:52 +00:00
|
|
|
values = baseValues.deep_merge_override({
|
2021-09-28 13:11:36 +00:00
|
|
|
ingress: {
|
|
|
|
main: {
|
|
|
|
tls: [
|
|
|
|
{
|
2021-09-28 22:11:52 +00:00
|
|
|
secretName: '{{ .Release.Name }}-secret'
|
2021-09-28 13:11:36 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 22:11:52 +00:00
|
|
|
})
|
2021-09-28 13:11:36 +00:00
|
|
|
chart.value values
|
2021-09-28 22:11:52 +00:00
|
|
|
|
|
|
|
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test" }
|
2021-09-28 13:11:36 +00:00
|
|
|
refute_nil(ingress)
|
|
|
|
assert_equal('common-test-secret', ingress["spec"]["tls"][0]["secretName"])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'path template can be provided' do
|
|
|
|
expectedPath = 'common-test.path'
|
2021-09-28 22:11:52 +00:00
|
|
|
values = baseValues.deep_merge_override({
|
2021-09-28 13:11:36 +00:00
|
|
|
ingress: {
|
|
|
|
main: {
|
|
|
|
hosts: [
|
|
|
|
{
|
2021-09-28 22:11:52 +00:00
|
|
|
host: 'test.local',
|
2021-09-28 13:11:36 +00:00
|
|
|
paths: [
|
|
|
|
{
|
2021-09-28 22:11:52 +00:00
|
|
|
path: '{{ .Release.Name }}.path'
|
2021-09-28 13:11:36 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 22:11:52 +00:00
|
|
|
})
|
2021-09-28 13:11:36 +00:00
|
|
|
chart.value values
|
2021-09-28 22:11:52 +00:00
|
|
|
|
|
|
|
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test" }
|
2021-09-28 13:11:36 +00:00
|
|
|
refute_nil(ingress)
|
|
|
|
assert_equal(expectedPath, ingress["spec"]["rules"][0]["http"]["paths"][0]["path"])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'hosts can be provided' do
|
2021-09-28 22:11:52 +00:00
|
|
|
values = baseValues.deep_merge_override({
|
2021-09-28 13:11:36 +00:00
|
|
|
ingress: {
|
|
|
|
main: {
|
|
|
|
hosts: [
|
|
|
|
{
|
2021-09-28 22:11:52 +00:00
|
|
|
host: 'hostname',
|
|
|
|
paths: [
|
|
|
|
{
|
|
|
|
path: "/"
|
|
|
|
}
|
|
|
|
]
|
2021-09-28 13:11:36 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 22:11:52 +00:00
|
|
|
})
|
2021-09-28 13:11:36 +00:00
|
|
|
chart.value values
|
2021-09-28 22:11:52 +00:00
|
|
|
|
|
|
|
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test" }
|
2021-09-28 13:11:36 +00:00
|
|
|
refute_nil(ingress)
|
|
|
|
assert_equal(values[:ingress][:main][:hosts][0][:host], ingress["spec"]["rules"][0]["host"])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'hosts template can be provided' do
|
|
|
|
expectedHostName = 'common-test.hostname'
|
2021-09-28 22:11:52 +00:00
|
|
|
values = baseValues.deep_merge_override({
|
2021-09-28 13:11:36 +00:00
|
|
|
ingress: {
|
|
|
|
main: {
|
|
|
|
hosts: [
|
|
|
|
{
|
2021-09-28 22:11:52 +00:00
|
|
|
host: '{{ .Release.Name }}.hostname',
|
|
|
|
paths: [
|
|
|
|
{
|
|
|
|
path: "/"
|
|
|
|
}
|
|
|
|
]
|
2021-09-28 13:11:36 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 22:11:52 +00:00
|
|
|
})
|
2021-09-28 13:11:36 +00:00
|
|
|
chart.value values
|
2021-09-28 22:11:52 +00:00
|
|
|
|
|
|
|
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test" }
|
2021-09-28 13:11:36 +00:00
|
|
|
refute_nil(ingress)
|
|
|
|
assert_equal(expectedHostName, ingress["spec"]["rules"][0]["host"])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'custom service name / port can optionally be set on path level' do
|
2021-09-28 22:11:52 +00:00
|
|
|
values = baseValues.deep_merge_override({
|
2021-09-28 13:11:36 +00:00
|
|
|
ingress: {
|
|
|
|
main: {
|
|
|
|
hosts: [
|
|
|
|
{
|
2021-09-28 22:11:52 +00:00
|
|
|
host: 'test.local',
|
2021-09-28 13:11:36 +00:00
|
|
|
paths: [
|
|
|
|
{
|
|
|
|
path: '/'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/second',
|
2021-09-28 22:11:52 +00:00
|
|
|
service: {
|
|
|
|
name: 'pathService',
|
|
|
|
port: 1234
|
|
|
|
}
|
2021-09-28 13:11:36 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 22:11:52 +00:00
|
|
|
})
|
2021-09-28 13:11:36 +00:00
|
|
|
chart.value values
|
2021-09-28 22:11:52 +00:00
|
|
|
|
|
|
|
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test" }
|
2021-09-28 13:11:36 +00:00
|
|
|
firstPath = ingress["spec"]["rules"][0]["http"]["paths"][0]
|
|
|
|
secondPath = ingress["spec"]["rules"][0]["http"]["paths"][1]
|
|
|
|
assert_equal("common-test", firstPath["backend"]["service"]["name"])
|
|
|
|
assert_equal(8080, firstPath["backend"]["service"]["port"]["number"])
|
|
|
|
assert_equal("pathService", secondPath["backend"]["service"]["name"])
|
|
|
|
assert_equal(1234, secondPath["backend"]["service"]["port"]["number"])
|
|
|
|
end
|
|
|
|
|
2021-09-28 22:11:52 +00:00
|
|
|
it 'multiple ingress objects can be specified' do
|
|
|
|
values = baseValues.deep_merge_override({
|
|
|
|
ingress: {
|
|
|
|
main: {
|
2021-09-28 13:11:36 +00:00
|
|
|
enabled: true,
|
2021-09-28 22:11:52 +00:00
|
|
|
primary: true
|
|
|
|
},
|
|
|
|
secondary: {
|
|
|
|
enabled: true
|
2021-09-28 13:11:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
chart.value values
|
|
|
|
|
2021-09-28 22:11:52 +00:00
|
|
|
ingressMain = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test" }
|
|
|
|
ingressExtra = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test-secondary" }
|
|
|
|
refute_nil(ingressMain)
|
|
|
|
refute_nil(ingressExtra)
|
2021-09-28 13:11:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|