blob: 3a9159d24d25bc54d787c1525d6d37949ad7bc3d [file] [log] [blame]
Mohammed Naserc6e431b2024-03-15 01:21:44 -04001package testutils
2
3import (
Mohammed Naser60bb74c2025-02-10 10:52:10 -05004 "strings"
Mohammed Naserc6e431b2024-03-15 01:21:44 -04005 "testing"
6
7 "github.com/stretchr/testify/assert"
Jason Halldea3c672025-02-12 10:33:39 -06008 "github.com/stretchr/testify/require"
Mohammed Naserc6e431b2024-03-15 01:21:44 -04009
10 "github.com/vexxhost/atmosphere/internal/openstack_helm"
11)
12
13func TestDatabaseConf(t *testing.T, config *openstack_helm.DatabaseConf) {
Oleksandr K.99651a62024-10-30 04:41:51 +010014 assert.Equal(t, 600, config.ConnectionRecycleTime)
15 assert.Equal(t, 5, config.MaxPoolSize)
Mohammed Naserc6e431b2024-03-15 01:21:44 -040016 assert.Equal(t, -1, config.MaxRetries)
17}
Mohammed Naser60bb74c2025-02-10 10:52:10 -050018
19func podNameForClass(pod string) string {
20 // There are a few pods which are built/created inside "helm-toolkit" so
21 // we cannot refer to them by their full name or the code will get real
22 // messy.
23 if strings.HasSuffix(pod, "db_init") {
24 return "db_init"
25 } else if strings.HasSuffix(pod, "db_sync") {
26 return "db_sync"
27 } else if strings.HasSuffix(pod, "_bootstrap") {
28 return "bootstrap"
29 }
30
31 return pod
32}
33
34func TestAllPodsHaveRuntimeClass(t *testing.T, vals *openstack_helm.HelmValues) {
35 for pod := range vals.Pod.Mounts {
36 podName := podNameForClass(pod)
37 assert.Contains(t, vals.Pod.RuntimeClass, podName)
38 }
39}
40
41func TestAllPodsHavePriorityClass(t *testing.T, vals *openstack_helm.HelmValues) {
42 for pod := range vals.Pod.Mounts {
43 podName := podNameForClass(pod)
44 assert.Contains(t, vals.Pod.PriorityClass, podName)
45 }
46}
Jason Halldea3c672025-02-12 10:33:39 -060047
48func TestAllPodsHaveAntiAffinityType(t *testing.T, vals *openstack_helm.HelmValues) {
49 for pod := range vals.Pod.AntiAffinityType {
50 podName := podNameForClass(pod)
51
52 expected := "requiredDuringSchedulingIgnoredDuringExecution"
53
54 defaultRaw, ok := vals.Pod.AntiAffinityType["default"]
55 require.True(t, ok, "default key not found in affinity.anti.type block")
56
57 actual, ok := defaultRaw.(string)
58 require.True(t, ok, "default anti affinity type is not a string")
59
60 assert.Equal(t, expected, actual, "anti affinity type does not match expected value")
61 assert.Contains(t, vals.Pod.AntiAffinityType, podName)
62 }
63}