Mohammed Naser | c6e431b | 2024-03-15 01:21:44 -0400 | [diff] [blame] | 1 | package testutils |
| 2 | |
| 3 | import ( |
Mohammed Naser | 60bb74c | 2025-02-10 10:52:10 -0500 | [diff] [blame] | 4 | "strings" |
Mohammed Naser | c6e431b | 2024-03-15 01:21:44 -0400 | [diff] [blame] | 5 | "testing" |
| 6 | |
| 7 | "github.com/stretchr/testify/assert" |
Jason Hall | dea3c67 | 2025-02-12 10:33:39 -0600 | [diff] [blame] | 8 | "github.com/stretchr/testify/require" |
Mohammed Naser | c6e431b | 2024-03-15 01:21:44 -0400 | [diff] [blame] | 9 | |
| 10 | "github.com/vexxhost/atmosphere/internal/openstack_helm" |
| 11 | ) |
| 12 | |
| 13 | func TestDatabaseConf(t *testing.T, config *openstack_helm.DatabaseConf) { |
Oleksandr K. | 99651a6 | 2024-10-30 04:41:51 +0100 | [diff] [blame] | 14 | assert.Equal(t, 600, config.ConnectionRecycleTime) |
| 15 | assert.Equal(t, 5, config.MaxPoolSize) |
Mohammed Naser | c6e431b | 2024-03-15 01:21:44 -0400 | [diff] [blame] | 16 | assert.Equal(t, -1, config.MaxRetries) |
| 17 | } |
Mohammed Naser | 60bb74c | 2025-02-10 10:52:10 -0500 | [diff] [blame] | 18 | |
| 19 | func 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 | |
| 34 | func 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 | |
| 41 | func 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 Hall | dea3c67 | 2025-02-12 10:33:39 -0600 | [diff] [blame] | 47 | |
| 48 | func 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 | } |