Skip to content

Commit 29c29b9

Browse files
integration tests: add a test to verify common config network external
Add a test case that sets up a share referencing a common config that sets network/publish=external. This performs the standard checks for share (regression) as well as adding a check that the service is created with a type=LoadBalancer. Signed-off-by: John Mulligan <jmulligan@redhat.com>
1 parent a3baed8 commit 29c29b9

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

tests/files/commonconfig1.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
apiVersion: samba-operator.samba.org/v1alpha1
3+
kind: SmbCommonConfig
4+
metadata:
5+
name: commonext1
6+
spec:
7+
network:
8+
publish: external

tests/files/smbshare4.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
apiVersion: samba-operator.samba.org/v1alpha1
3+
kind: SmbShare
4+
metadata:
5+
name: tshare4
6+
spec:
7+
shareName: "Since When"
8+
readOnly: false
9+
browseable: false
10+
securityConfig: sharesec1
11+
commonConfig: commonext1
12+
storage:
13+
pvc:
14+
spec:
15+
accessModes:
16+
- ReadWriteOnce
17+
resources:
18+
requests:
19+
storage: 1Gi

tests/integration/smb_share_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/stretchr/testify/suite"
12+
corev1 "k8s.io/api/core/v1"
1213
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1314
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1415
"k8s.io/apimachinery/pkg/types"
@@ -191,6 +192,30 @@ func (s *SmbShareWithDNSSuite) TestPodForDNSContainers() {
191192
s.Require().Contains(names, "svc-watch")
192193
}
193194

195+
type SmbShareWithExternalNetSuite struct {
196+
SmbShareSuite
197+
}
198+
199+
func (s *SmbShareWithExternalNetSuite) TestServiceIsLoadBalancer() {
200+
lbl := fmt.Sprintf("samba-operator.samba.org/service=%s", s.smbShareResource.Name)
201+
l, err := s.tc.Clientset().CoreV1().Services(testNamespace).List(
202+
context.TODO(),
203+
metav1.ListOptions{
204+
LabelSelector: lbl,
205+
},
206+
)
207+
s.Require().NoError(err)
208+
s.Require().Len(l.Items, 1)
209+
// our test environment does not require the k8s cluster to actually
210+
// support an external load balancer. All this test can do is check
211+
// IF LoadBalanacer was set.
212+
svc := l.Items[0]
213+
s.Require().Equal(
214+
corev1.ServiceTypeLoadBalancer,
215+
svc.Spec.Type,
216+
)
217+
}
218+
194219
func allSmbShareSuites() map[string]suite.TestingSuite {
195220
m := map[string]suite.TestingSuite{}
196221
m["users1"] = &SmbShareSuite{
@@ -265,5 +290,32 @@ func allSmbShareSuites() map[string]suite.TestingSuite {
265290
}},
266291
}
267292

293+
m["smbSharesExternal"] = &SmbShareSuite{
294+
fileSources: []kube.FileSource{
295+
{
296+
Path: path.Join(testFilesDir, "userssecret1.yaml"),
297+
Namespace: testNamespace,
298+
},
299+
{
300+
Path: path.Join(testFilesDir, "commonconfig1.yaml"),
301+
Namespace: testNamespace,
302+
},
303+
{
304+
Path: path.Join(testFilesDir, "smbsecurityconfig1.yaml"),
305+
Namespace: testNamespace,
306+
},
307+
{
308+
Path: path.Join(testFilesDir, "smbshare4.yaml"),
309+
Namespace: testNamespace,
310+
},
311+
},
312+
smbShareResource: types.NamespacedName{testNamespace, "tshare4"},
313+
shareName: "Since When",
314+
testAuths: []smbclient.Auth{{
315+
Username: "sambauser",
316+
Password: "1nsecurely",
317+
}},
318+
}
319+
268320
return m
269321
}

0 commit comments

Comments
 (0)