|
5 | 5 | package util |
6 | 6 |
|
7 | 7 | import ( |
8 | | - "context" |
9 | 8 | "testing" |
10 | 9 |
|
11 | 10 | "gotest.tools/v3/assert" |
12 | 11 |
|
13 | | - "github.com/crunchydata/postgres-operator/internal/kubernetes" |
14 | 12 | "github.com/crunchydata/postgres-operator/internal/testing/cmp" |
15 | 13 | ) |
16 | 14 |
|
17 | 15 | func TestPodSecurityContext(t *testing.T) { |
18 | | - ctx := context.Background() |
19 | | - assert.Assert(t, cmp.MarshalMatches(PodSecurityContext(ctx, 2, []int64{}), ` |
| 16 | + t.Run("Non-Openshift", func(t *testing.T) { |
| 17 | + assert.Assert(t, cmp.MarshalMatches(PodSecurityContext(2, []int64{}, false), ` |
20 | 18 | fsGroup: 2 |
21 | 19 | fsGroupChangePolicy: OnRootMismatch |
22 | 20 | `)) |
23 | 21 |
|
24 | | - supplementalGroups := []int64{3, 4} |
25 | | - assert.Assert(t, cmp.MarshalMatches(PodSecurityContext(ctx, 26, supplementalGroups), ` |
| 22 | + supplementalGroups := []int64{3, 4} |
| 23 | + assert.Assert(t, cmp.MarshalMatches(PodSecurityContext(26, supplementalGroups, false), ` |
26 | 24 | fsGroup: 26 |
27 | 25 | fsGroupChangePolicy: OnRootMismatch |
28 | 26 | supplementalGroups: |
29 | 27 | - 3 |
30 | 28 | - 4 |
31 | 29 | `)) |
| 30 | + }) |
32 | 31 |
|
33 | | - ctx = kubernetes.NewAPIContext(ctx, kubernetes.NewAPISet(kubernetes.API{ |
34 | | - Group: "security.openshift.io", Version: "v1", |
35 | | - Kind: "SecurityContextConstraints", |
36 | | - })) |
37 | | - assert.Assert(t, cmp.MarshalMatches(PodSecurityContext(ctx, 2, []int64{}), |
38 | | - `fsGroupChangePolicy: OnRootMismatch`)) |
| 32 | + t.Run("OpenShift", func(t *testing.T) { |
| 33 | + assert.Assert(t, cmp.MarshalMatches(PodSecurityContext(2, []int64{}, true), |
| 34 | + `fsGroupChangePolicy: OnRootMismatch`)) |
39 | 35 |
|
40 | | - assert.Assert(t, cmp.MarshalMatches(PodSecurityContext(ctx, 2, supplementalGroups), ` |
| 36 | + supplementalGroups := []int64{3, 4} |
| 37 | + assert.Assert(t, cmp.MarshalMatches(PodSecurityContext(2, supplementalGroups, true), ` |
41 | 38 | fsGroupChangePolicy: OnRootMismatch |
42 | 39 | supplementalGroups: |
43 | 40 | - 3 |
44 | 41 | - 4 |
45 | 42 | `)) |
| 43 | + }) |
46 | 44 |
|
47 | 45 | t.Run("NoRootGID", func(t *testing.T) { |
48 | | - supplementalGroups = []int64{999, 0, 100, 0} |
49 | | - assert.DeepEqual(t, []int64{999, 100}, PodSecurityContext(ctx, 2, supplementalGroups).SupplementalGroups) |
| 46 | + supplementalGroups := []int64{999, 0, 100, 0} |
| 47 | + assert.DeepEqual(t, []int64{999, 100}, PodSecurityContext(2, supplementalGroups, false).SupplementalGroups) |
50 | 48 |
|
51 | 49 | supplementalGroups = []int64{0} |
52 | | - assert.Assert(t, PodSecurityContext(ctx, 2, supplementalGroups).SupplementalGroups == nil) |
| 50 | + assert.Assert(t, PodSecurityContext(2, supplementalGroups, false).SupplementalGroups == nil) |
53 | 51 | }) |
54 | 52 | } |
0 commit comments