Skip to content

Commit 4b24993

Browse files
phlogistonjohnobnoxxx
authored andcommitted
integration tests: make the group name unique when grouping shares
To avoid various name caching issues existing tests were adding a unique suffix to smb shares. However, now with explicitly named share groups the `spec.scaling.group` field determines what the name of generated resources will be. Increase test reliability by adding the unique suffix to the name of the group too. Signed-off-by: John Mulligan <[email protected]>
1 parent 91e8015 commit 4b24993

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

tests/integration/util_test.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
corev1 "k8s.io/api/core/v1"
13+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1314
"k8s.io/apimachinery/pkg/types"
1415
krand "k8s.io/apimachinery/pkg/util/rand"
1516

@@ -90,10 +91,15 @@ func createFromFilesWithSuffix(
9091
for _, fs := range srcs {
9192
nn, err := tc.CreateFromFileIfMissing(
9293
ctx,
93-
kube.FileSource{
94-
Path: fs.Path,
95-
Namespace: fs.Namespace,
96-
NameSuffix: setSuffix(fs.NameSuffix, suffix),
94+
kube.MutatingSource{
95+
Source: kube.FileSource{
96+
Path: fs.Path,
97+
Namespace: fs.Namespace,
98+
NameSuffix: setSuffix(fs.NameSuffix, suffix),
99+
},
100+
Mutate: func(u *unstructured.Unstructured) error {
101+
return mutateSmbShare(u, suffix)
102+
},
97103
},
98104
)
99105
require.NoError(err)
@@ -243,3 +249,26 @@ func getAnyPodIP(ctx context.Context, ptc podTestClient) (string, error) {
243249
}
244250
return pod.Status.PodIP, nil
245251
}
252+
253+
func mutateSmbShare(u *unstructured.Unstructured, suffix string) error {
254+
// for now we just assume anything with a spec.scaling.group property
255+
// is an SmbShare. If we really need to, in the future we can verify
256+
// the GVK of the unstructured obj.
257+
v, ok, err := unstructured.NestedString(
258+
u.Object,
259+
"spec",
260+
"scaling",
261+
"group")
262+
if err != nil {
263+
return err
264+
}
265+
if ok && v != "" {
266+
err = unstructured.SetNestedField(
267+
u.Object,
268+
setSuffix(v, suffix),
269+
"spec",
270+
"scaling",
271+
"group")
272+
}
273+
return err
274+
}

0 commit comments

Comments
 (0)