Skip to content

Commit 48e531d

Browse files
spuiukanoopcs9
authored andcommitted
integration tests: Move smbclient pod creation to util_test
Signed-off-by: Sachin Prabhu <[email protected]>
1 parent becc9bb commit 48e531d

File tree

2 files changed

+47
-42
lines changed

2 files changed

+47
-42
lines changed

tests/integration/share_access_test.go

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ package integration
44

55
import (
66
"context"
7-
"path"
8-
"time"
97

108
"github.com/stretchr/testify/suite"
119

@@ -25,46 +23,7 @@ func (s *ShareAccessSuite) SetupSuite() {
2523
s.clientPod = "smbclient"
2624

2725
// ensure the smbclient test pod is configured
28-
tc := kube.NewTestClient("")
29-
_, err := tc.CreateFromFileIfMissing(
30-
context.TODO(),
31-
kube.FileSource{
32-
Path: path.Join(testFilesDir, "data1.yaml"),
33-
Namespace: testNamespace,
34-
})
35-
s.Require().NoError(err)
36-
_, err = tc.CreateFromFileIfMissing(
37-
context.TODO(),
38-
kube.FileSource{
39-
Path: path.Join(testFilesDir, "client-test-pod.yaml"),
40-
Namespace: testNamespace,
41-
})
42-
s.Require().NoError(err)
43-
44-
// ensure the smbclient test pod exists and is ready
45-
ctx, cancel := context.WithDeadline(
46-
context.TODO(),
47-
time.Now().Add(120*time.Second))
48-
defer cancel()
49-
l := "app=samba-operator-test-smbclient"
50-
s.Require().NoError(kube.WaitForAnyPodExists(
51-
ctx,
52-
kube.NewTestClient(""),
53-
kube.PodFetchOptions{
54-
Namespace: testNamespace,
55-
LabelSelector: l,
56-
}),
57-
"smbclient pod does not exist",
58-
)
59-
s.Require().NoError(kube.WaitForAnyPodReady(
60-
ctx,
61-
kube.NewTestClient(""),
62-
kube.PodFetchOptions{
63-
Namespace: testNamespace,
64-
LabelSelector: l,
65-
}),
66-
"smbclient pod not ready",
67-
)
26+
createSMBClientIfMissing(s.Require(), kube.NewTestClient(""))
6827
}
6928

7029
// TestLogin verifies that users can log into the share.

tests/integration/util_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ package integration
44

55
import (
66
"context"
7+
"path"
78
"time"
89

910
"github.com/samba-in-kubernetes/samba-operator/tests/utils/kube"
11+
"github.com/stretchr/testify/require"
1012
)
1113

1214
var (
@@ -88,3 +90,47 @@ func waitForAllPodReady(s podTestClient) error {
8890
s.getPodFetchOptions(),
8991
)
9092
}
93+
94+
func createSMBClientIfMissing(require *require.Assertions, tc *kube.TestClient) {
95+
// ---
96+
_, err := tc.CreateFromFileIfMissing(
97+
context.TODO(),
98+
kube.FileSource{
99+
Path: path.Join(testFilesDir, "data1.yaml"),
100+
Namespace: testNamespace,
101+
})
102+
require.NoError(err)
103+
104+
_, err = tc.CreateFromFileIfMissing(
105+
context.TODO(),
106+
kube.FileSource{
107+
Path: path.Join(testFilesDir, "client-test-pod.yaml"),
108+
Namespace: testNamespace,
109+
})
110+
require.NoError(err)
111+
112+
// ensure the smbclient test pod exists and is ready
113+
ctx, cancel := context.WithDeadline(
114+
context.TODO(),
115+
time.Now().Add(120*time.Second))
116+
defer cancel()
117+
l := "app=samba-operator-test-smbclient"
118+
require.NoError(kube.WaitForAnyPodExists(
119+
ctx,
120+
kube.NewTestClient(""),
121+
kube.PodFetchOptions{
122+
Namespace: testNamespace,
123+
LabelSelector: l,
124+
}),
125+
"smbclient pod does not exist",
126+
)
127+
require.NoError(kube.WaitForAnyPodReady(
128+
ctx,
129+
kube.NewTestClient(""),
130+
kube.PodFetchOptions{
131+
Namespace: testNamespace,
132+
LabelSelector: l,
133+
}),
134+
"smbclient pod not ready",
135+
)
136+
}

0 commit comments

Comments
 (0)