Skip to content

Commit c3ba7da

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 3c87740 commit c3ba7da

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"
@@ -200,6 +201,30 @@ func (s *SmbShareWithDNSSuite) TestPodForDNSContainers() {
200201
s.Require().Contains(names, "svc-watch")
201202
}
202203

204+
type SmbShareWithExternalNetSuite struct {
205+
SmbShareSuite
206+
}
207+
208+
func (s *SmbShareWithExternalNetSuite) TestServiceIsLoadBalancer() {
209+
lbl := fmt.Sprintf("samba-operator.samba.org/service=%s", s.smbShareResource.Name)
210+
l, err := s.tc.Clientset().CoreV1().Services(testNamespace).List(
211+
context.TODO(),
212+
metav1.ListOptions{
213+
LabelSelector: lbl,
214+
},
215+
)
216+
s.Require().NoError(err)
217+
s.Require().Len(l.Items, 1)
218+
// our test environment does not require the k8s cluster to actually
219+
// support an external load balancer. All this test can do is check
220+
// IF LoadBalanacer was set.
221+
svc := l.Items[0]
222+
s.Require().Equal(
223+
corev1.ServiceTypeLoadBalancer,
224+
svc.Spec.Type,
225+
)
226+
}
227+
203228
func allSmbShareSuites() map[string]suite.TestingSuite {
204229
m := map[string]suite.TestingSuite{}
205230
m["users1"] = &SmbShareSuite{
@@ -274,5 +299,32 @@ func allSmbShareSuites() map[string]suite.TestingSuite {
274299
}},
275300
}
276301

302+
m["smbSharesExternal"] = &SmbShareWithExternalNetSuite{SmbShareSuite{
303+
fileSources: []kube.FileSource{
304+
{
305+
Path: path.Join(testFilesDir, "userssecret1.yaml"),
306+
Namespace: testNamespace,
307+
},
308+
{
309+
Path: path.Join(testFilesDir, "commonconfig1.yaml"),
310+
Namespace: testNamespace,
311+
},
312+
{
313+
Path: path.Join(testFilesDir, "smbsecurityconfig1.yaml"),
314+
Namespace: testNamespace,
315+
},
316+
{
317+
Path: path.Join(testFilesDir, "smbshare4.yaml"),
318+
Namespace: testNamespace,
319+
},
320+
},
321+
smbShareResource: types.NamespacedName{testNamespace, "tshare4"},
322+
shareName: "Since When",
323+
testAuths: []smbclient.Auth{{
324+
Username: "sambauser",
325+
Password: "1nsecurely",
326+
}},
327+
}}
328+
277329
return m
278330
}

0 commit comments

Comments
 (0)