Skip to content

Commit

Permalink
Merge pull request #138 from srl-labs/test/more-e2e-testing
Browse files Browse the repository at this point in the history
test: more and more meaingful e2e test for basic c9s functionality
carlmontanari authored Mar 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents f2440ea + 1fb588e commit b91c0c1
Showing 17 changed files with 924 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/vars.env
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
GO_VERSION=1.22
DEVSPACE_VERSION=v6.3.11
DEVSPACE_VERSION=v6.3.12
GCI_VERSION=v0.12.3
GOFUMPT_VERSION=v0.6.0
GOLANGCI_LINT_VERSION=v1.56.2
GOLANGCI_LINT_VERSION=v1.57.1
GOLINES_VERSION=v0.12.2
GOTESTSUM_VERSION=v1.11.0
HELM_VERSION=v3.14.2
8 changes: 8 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -95,6 +95,8 @@ jobs:

- name: spin up kind cluster
uses: helm/[email protected]
with:
version: v0.22.0

- name: verify kind cluster
run: |
@@ -105,6 +107,12 @@ jobs:
- name: deploy clabernetes
run: devspace run deploy --profile debug

# actions seem to be running out of disk for e2e -- probably due to all the image build stuff
# floating around, all the junk runners get pre-built with, and runners not being super beefy
# lets just system prune all the docker stuff to get rid of some junk we dont need
- name: docker system prune
run: docker system prune -a -f

- name: setup tmate session
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_e2e }}
4 changes: 2 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -177,7 +177,7 @@ issues:
# prefer to sprintf -- feels more consistent overall
- linters:
- perfsprint
text: "can be replaced with string addition"
text: "can be replaced with string concatenation"

run:
go: '1.21'
@@ -189,4 +189,4 @@ output:
uniq-by-line: false

service:
golangci-lint-version: 1.56.x
golangci-lint-version: 1.57.x
2 changes: 1 addition & 1 deletion e2e/clabverter/clabverter_basic_test.go
Original file line number Diff line number Diff line change
@@ -86,5 +86,5 @@ func TestClabverterBasic(t *testing.T) {
},
}

clabernetestesthelpersuite.Run(t, steps, namespace)
clabernetestesthelpersuite.Run(t, testName, steps, namespace)
}
20 changes: 20 additions & 0 deletions e2e/topology/basic/test-fixtures/20-apply.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
apiVersion: clabernetes.containerlab.dev/v1alpha1
kind: Topology
metadata:
name: topology-basic
spec:
definition:
containerlab: |-
name: topology-basic
topology:
nodes:
srl1:
kind: srl
image: ghcr.io/nokia/srlinux
srl2:
kind: srl
image: ghcr.io/nokia/srlinux
links:
- endpoints: ["srl1:e1-1", "srl2:e1-1"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: clabernetes.containerlab.dev/v1alpha1
kind: Connectivity
metadata:
labels:
clabernetes/app: clabernetes
clabernetes/name: topology-basic
clabernetes/topologyKind: containerlab
clabernetes/topologyOwner: topology-basic
name: topology-basic
namespace: NAMESPACE
ownerReferences:
- apiVersion: clabernetes.containerlab.dev/v1alpha1
kind: Topology
name: topology-basic
spec:
pointToPointTunnels: {}
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
apiVersion: apps/v1
kind: Deployment
metadata:
annotations: {}
labels:
app.kubernetes.io/name: topology-basic-srl1
clabernetes/app: clabernetes
clabernetes/name: topology-basic-srl1
clabernetes/topologyNode: srl1
clabernetes/topologyOwner: topology-basic
name: topology-basic-srl1
namespace: NAMESPACE
ownerReferences:
- apiVersion: clabernetes.containerlab.dev/v1alpha1
kind: Topology
name: topology-basic
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 0
selector:
matchLabels:
app.kubernetes.io/name: topology-basic-srl1
clabernetes/app: clabernetes
clabernetes/name: topology-basic-srl1
clabernetes/topologyNode: srl1
clabernetes/topologyOwner: topology-basic
strategy:
type: Recreate
template:
metadata:
creationTimestamp: null
labels:
app.kubernetes.io/name: topology-basic-srl1
clabernetes/app: clabernetes
clabernetes/name: topology-basic-srl1
clabernetes/topologyNode: srl1
clabernetes/topologyOwner: topology-basic
spec:
containers:
- command:
- /clabernetes/manager
- launch
env:
- name: NODE_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: APP_NAME
value: clabernetes
- name: MANAGER_NAMESPACE
value: clabernetes
- name: LAUNCHER_CRI_KIND
value: containerd
- name: LAUNCHER_IMAGE_PULL_THROUGH_MODE
value: auto
- name: LAUNCHER_LOGGER_LEVEL
value: debug
- name: LAUNCHER_TOPOLOGY_NAME
value: topology-basic
- name: LAUNCHER_NODE_NAME
value: srl1
- name: LAUNCHER_NODE_IMAGE
value: ghcr.io/nokia/srlinux
- name: LAUNCHER_CONNECTIVITY_KIND
value: vxlan
- name: LAUNCHER_CONTAINERLAB_VERSION
- name: LAUNCHER_CONTAINERLAB_TIMEOUT
- name: LAUNCHER_PRIVILEGED
value: "true"
imagePullPolicy: IfNotPresent
name: srl1
ports:
- containerPort: 14789
name: vxlan
protocol: UDP
- containerPort: 4799
name: slurpeeth
protocol: TCP
resources:
requests:
cpu: 200m
memory: 512Mi
securityContext:
privileged: true
runAsUser: 0
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /clabernetes/topo.clab.yaml
name: topology-basic-config
readOnly: true
subPath: srl1
- mountPath: /clabernetes/files-from-url.yaml
name: topology-basic-config
readOnly: true
subPath: srl1-files-from-url
- mountPath: /clabernetes/configured-pull-secrets.yaml
name: topology-basic-config
readOnly: true
subPath: configured-pull-secrets
- mountPath: /clabernetes/.node/containerd.sock
name: cri-sock
readOnly: true
subPath: containerd.sock
workingDir: /clabernetes
dnsPolicy: ClusterFirst
hostname: srl1
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: clabernetes-launcher-service-account
serviceAccountName: clabernetes-launcher-service-account
terminationGracePeriodSeconds: 30
volumes:
- configMap:
defaultMode: 493
name: topology-basic
name: topology-basic-config
- hostPath:
path: /run/containerd
type: ""
name: cri-sock
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: v1
kind: Service
metadata:
labels:
clabernetes/app: clabernetes
clabernetes/name: topology-basic-srl1
clabernetes/topologyKind: containerlab
clabernetes/topologyNode: srl1
clabernetes/topologyOwner: topology-basic
clabernetes/topologyServiceType: fabric
name: topology-basic-srl1-vx
namespace: NAMESPACE
ownerReferences:
- apiVersion: clabernetes.containerlab.dev/v1alpha1
kind: Topology
name: topology-basic
spec:
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: vxlan
port: 14789
protocol: UDP
targetPort: 14789
- name: slurpeeth
port: 4799
protocol: TCP
targetPort: 4799
selector:
clabernetes/app: clabernetes
clabernetes/name: topology-basic-srl1
clabernetes/topologyNode: srl1
clabernetes/topologyOwner: topology-basic
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: clabernetes.containerlab.dev/v1alpha1
kind: Connectivity
metadata:
labels:
clabernetes/app: clabernetes
clabernetes/name: topology-basic
clabernetes/topologyKind: containerlab
clabernetes/topologyOwner: topology-basic
name: topology-basic
namespace: NAMESPACE
spec:
pointToPointTunnels:
srl1:
- destination: topology-basic-srl2-vx.NAMESPACE.svc.cluster.local
localInterface: e1-1
localNode: srl1
remoteInterface: e1-1
remoteNode: srl2
tunnelID: 1
srl2:
- destination: topology-basic-srl1-vx.NAMESPACE.svc.cluster.local
localInterface: e1-1
localNode: srl2
remoteInterface: e1-1
remoteNode: srl1
tunnelID: 1
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
apiVersion: apps/v1
kind: Deployment
metadata:
annotations: {}
labels:
app.kubernetes.io/name: topology-basic-srl1
clabernetes/app: clabernetes
clabernetes/name: topology-basic-srl1
clabernetes/topologyNode: srl1
clabernetes/topologyOwner: topology-basic
name: topology-basic-srl1
namespace: NAMESPACE
ownerReferences:
- apiVersion: clabernetes.containerlab.dev/v1alpha1
kind: Topology
name: topology-basic
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 0
selector:
matchLabels:
app.kubernetes.io/name: topology-basic-srl1
clabernetes/app: clabernetes
clabernetes/name: topology-basic-srl1
clabernetes/topologyNode: srl1
clabernetes/topologyOwner: topology-basic
strategy:
type: Recreate
template:
metadata:
annotations: {}
creationTimestamp: null
labels:
app.kubernetes.io/name: topology-basic-srl1
clabernetes/app: clabernetes
clabernetes/name: topology-basic-srl1
clabernetes/topologyNode: srl1
clabernetes/topologyOwner: topology-basic
spec:
containers:
- command:
- /clabernetes/manager
- launch
env:
- name: NODE_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: APP_NAME
value: clabernetes
- name: MANAGER_NAMESPACE
value: clabernetes
- name: LAUNCHER_CRI_KIND
value: containerd
- name: LAUNCHER_IMAGE_PULL_THROUGH_MODE
value: auto
- name: LAUNCHER_LOGGER_LEVEL
value: debug
- name: LAUNCHER_TOPOLOGY_NAME
value: topology-basic
- name: LAUNCHER_NODE_NAME
value: srl1
- name: LAUNCHER_NODE_IMAGE
value: ghcr.io/nokia/srlinux
- name: LAUNCHER_CONNECTIVITY_KIND
value: vxlan
- name: LAUNCHER_CONTAINERLAB_VERSION
- name: LAUNCHER_CONTAINERLAB_TIMEOUT
- name: LAUNCHER_PRIVILEGED
value: "true"
imagePullPolicy: IfNotPresent
name: srl1
ports:
- containerPort: 14789
name: vxlan
protocol: UDP
- containerPort: 4799
name: slurpeeth
protocol: TCP
resources:
requests:
cpu: 200m
memory: 512Mi
securityContext:
privileged: true
runAsUser: 0
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /clabernetes/topo.clab.yaml
name: topology-basic-config
readOnly: true
subPath: srl1
- mountPath: /clabernetes/files-from-url.yaml
name: topology-basic-config
readOnly: true
subPath: srl1-files-from-url
- mountPath: /clabernetes/configured-pull-secrets.yaml
name: topology-basic-config
readOnly: true
subPath: configured-pull-secrets
- mountPath: /clabernetes/.node/containerd.sock
name: cri-sock
readOnly: true
subPath: containerd.sock
workingDir: /clabernetes
dnsPolicy: ClusterFirst
hostname: srl1
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: clabernetes-launcher-service-account
serviceAccountName: clabernetes-launcher-service-account
terminationGracePeriodSeconds: 30
volumes:
- configMap:
defaultMode: 493
name: topology-basic
name: topology-basic-config
- hostPath:
path: /run/containerd
type: ""
name: cri-sock
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
apiVersion: apps/v1
kind: Deployment
metadata:
annotations: {}
labels:
app.kubernetes.io/name: topology-basic-srl2
clabernetes/app: clabernetes
clabernetes/name: topology-basic-srl2
clabernetes/topologyNode: srl2
clabernetes/topologyOwner: topology-basic
name: topology-basic-srl2
namespace: NAMESPACE
ownerReferences:
- apiVersion: clabernetes.containerlab.dev/v1alpha1
kind: Topology
name: topology-basic
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 0
selector:
matchLabels:
app.kubernetes.io/name: topology-basic-srl2
clabernetes/app: clabernetes
clabernetes/name: topology-basic-srl2
clabernetes/topologyNode: srl2
clabernetes/topologyOwner: topology-basic
strategy:
type: Recreate
template:
metadata:
creationTimestamp: null
labels:
app.kubernetes.io/name: topology-basic-srl2
clabernetes/app: clabernetes
clabernetes/name: topology-basic-srl2
clabernetes/topologyNode: srl2
clabernetes/topologyOwner: topology-basic
spec:
containers:
- command:
- /clabernetes/manager
- launch
env:
- name: NODE_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: APP_NAME
value: clabernetes
- name: MANAGER_NAMESPACE
value: clabernetes
- name: LAUNCHER_CRI_KIND
value: containerd
- name: LAUNCHER_IMAGE_PULL_THROUGH_MODE
value: auto
- name: LAUNCHER_LOGGER_LEVEL
value: debug
- name: LAUNCHER_TOPOLOGY_NAME
value: topology-basic
- name: LAUNCHER_NODE_NAME
value: srl2
- name: LAUNCHER_NODE_IMAGE
value: ghcr.io/nokia/srlinux
- name: LAUNCHER_CONNECTIVITY_KIND
value: vxlan
- name: LAUNCHER_CONTAINERLAB_VERSION
- name: LAUNCHER_CONTAINERLAB_TIMEOUT
- name: LAUNCHER_PRIVILEGED
value: "true"
imagePullPolicy: IfNotPresent
name: srl2
ports:
- containerPort: 14789
name: vxlan
protocol: UDP
- containerPort: 4799
name: slurpeeth
protocol: TCP
resources:
requests:
cpu: 200m
memory: 512Mi
securityContext:
privileged: true
runAsUser: 0
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /clabernetes/topo.clab.yaml
name: topology-basic-config
readOnly: true
subPath: srl2
- mountPath: /clabernetes/files-from-url.yaml
name: topology-basic-config
readOnly: true
subPath: srl2-files-from-url
- mountPath: /clabernetes/configured-pull-secrets.yaml
name: topology-basic-config
readOnly: true
subPath: configured-pull-secrets
- mountPath: /clabernetes/.node/containerd.sock
name: cri-sock
readOnly: true
subPath: containerd.sock
workingDir: /clabernetes
dnsPolicy: ClusterFirst
hostname: srl2
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: clabernetes-launcher-service-account
serviceAccountName: clabernetes-launcher-service-account
terminationGracePeriodSeconds: 30
volumes:
- configMap:
defaultMode: 493
name: topology-basic
name: topology-basic-config
- hostPath:
path: /run/containerd
type: ""
name: cri-sock
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: v1
kind: Service
metadata:
labels:
clabernetes/app: clabernetes
clabernetes/name: topology-basic-srl1
clabernetes/topologyKind: containerlab
clabernetes/topologyNode: srl1
clabernetes/topologyOwner: topology-basic
clabernetes/topologyServiceType: fabric
name: topology-basic-srl1-vx
namespace: NAMESPACE
ownerReferences:
- apiVersion: clabernetes.containerlab.dev/v1alpha1
kind: Topology
name: topology-basic
spec:
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: vxlan
port: 14789
protocol: UDP
targetPort: 14789
- name: slurpeeth
port: 4799
protocol: TCP
targetPort: 4799
selector:
clabernetes/app: clabernetes
clabernetes/name: topology-basic-srl1
clabernetes/topologyNode: srl1
clabernetes/topologyOwner: topology-basic
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
apiVersion: v1
kind: Service
metadata:
labels:
clabernetes/app: clabernetes
clabernetes/name: topology-basic-srl1
clabernetes/topologyKind: containerlab
clabernetes/topologyNode: srl1
clabernetes/topologyOwner: topology-basic
clabernetes/topologyServiceType: expose
name: topology-basic-srl1
namespace: NAMESPACE
ownerReferences:
- apiVersion: clabernetes.containerlab.dev/v1alpha1
kind: Topology
name: topology-basic
spec:
allocateLoadBalancerNodePorts: true
externalTrafficPolicy: Cluster
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: port-161-udp
port: 161
protocol: UDP
targetPort: 60000
- name: port-21-tcp
port: 21
protocol: TCP
targetPort: 60000
- name: port-22-tcp
port: 22
protocol: TCP
targetPort: 60001
- name: port-23-tcp
port: 23
protocol: TCP
targetPort: 60002
- name: port-80-tcp
port: 80
protocol: TCP
targetPort: 60003
- name: port-443-tcp
port: 443
protocol: TCP
targetPort: 60004
- name: port-830-tcp
port: 830
protocol: TCP
targetPort: 60005
- name: port-5000-tcp
port: 5000
protocol: TCP
targetPort: 60006
- name: port-5900-tcp
port: 5900
protocol: TCP
targetPort: 60007
- name: port-6030-tcp
port: 6030
protocol: TCP
targetPort: 60008
- name: port-9339-tcp
port: 9339
protocol: TCP
targetPort: 60009
- name: port-9340-tcp
port: 9340
protocol: TCP
targetPort: 60010
- name: port-9559-tcp
port: 9559
protocol: TCP
targetPort: 60011
- name: port-57400-tcp
port: 57400
protocol: TCP
targetPort: 60012
selector:
clabernetes/app: clabernetes
clabernetes/name: topology-basic-srl1
clabernetes/topologyNode: srl1
clabernetes/topologyOwner: topology-basic
sessionAffinity: None
type: LoadBalancer
status:
loadBalancer: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
apiVersion: clabernetes.containerlab.dev/v1alpha1
kind: Topology
metadata:
annotations: {}
name: topology-basic
namespace: NAMESPACE
spec:
connectivity: vxlan
definition:
containerlab: |-
name: topology-basic
topology:
nodes:
srl1:
kind: srl
image: ghcr.io/nokia/srlinux
srl2:
kind: srl
image: ghcr.io/nokia/srlinux
links:
- endpoints: ["srl1:e1-1", "srl2:e1-1"]
deployment:
containerlabTimeout: ""
persistence:
enabled: false
scheduling: {}
expose:
disableAutoExpose: false
disableExpose: false
imagePull: {}
naming: global
status:
configs:
srl1: |
name: clabernetes-srl1
prefix: ""
topology:
defaults:
ports:
- 60000:21/tcp
- 60001:22/tcp
- 60002:23/tcp
- 60003:80/tcp
- 60000:161/udp
- 60004:443/tcp
- 60005:830/tcp
- 60006:5000/tcp
- 60007:5900/tcp
- 60008:6030/tcp
- 60009:9339/tcp
- 60010:9340/tcp
- 60011:9559/tcp
- 60012:57400/tcp
nodes:
srl1:
kind: srl
image: ghcr.io/nokia/srlinux
ports: []
links:
- endpoints:
- srl1:e1-1
- host:srl1-e1-1
debug: false
srl2: |
name: clabernetes-srl2
prefix: ""
topology:
defaults:
ports:
- 60000:21/tcp
- 60001:22/tcp
- 60002:23/tcp
- 60003:80/tcp
- 60000:161/udp
- 60004:443/tcp
- 60005:830/tcp
- 60006:5000/tcp
- 60007:5900/tcp
- 60008:6030/tcp
- 60009:9339/tcp
- 60010:9340/tcp
- 60011:9559/tcp
- 60012:57400/tcp
nodes:
srl2:
kind: srl
image: ghcr.io/nokia/srlinux
ports: []
links:
- endpoints:
- srl2:e1-1
- host:srl2-e1-1
debug: false
exposedPorts:
srl1:
tcpPorts:
- 21
- 22
- 23
- 80
- 443
- 830
- 5000
- 5900
- 6030
- 9339
- 9340
- 9559
- 57400
udpPorts:
- 161
srl2:
tcpPorts:
- 21
- 22
- 23
- 80
- 443
- 830
- 5000
- 5900
- 6030
- 9339
- 9340
- 9559
- 57400
udpPorts:
- 161
kind: containerlab
reconcileHashes:
config: 25ea403243c3741d3013049756aa02db0ad8dc3d0d9bf803dc1576f9dda33649
filesFromURL: {}
imagePullSecrets: 37517e5f3dc66819f61f5a7bb8ace1921282415f10551d2defa5c3eb0985b570
removeTopologyPrefix: false
73 changes: 72 additions & 1 deletion e2e/topology/basic/topology_basic_test.go
Original file line number Diff line number Diff line change
@@ -46,10 +46,81 @@ func TestContainerlabBasic(t *testing.T) {
clabernetestesthelper.NormalizeExposeService,
},
},
{
Name: fmt.Sprintf("%s-srl1-vx", testName),
NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{
clabernetestesthelper.NormalizeFabricService,
},
},
},
"deployment": {
{
Name: fmt.Sprintf("%s-srl1", testName),
NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{
clabernetestesthelper.NormalizeDeployment,
},
},
},
"connectivity": {
{
Name: testName,
NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{},
},
},
},
},
{
// this step we add a second node to topo and actually configure some links this time.
Index: 20,
Description: "Add a node and connect them",
AssertObjects: map[string][]clabernetestesthelpersuite.AssertObject{
"topology": {
{
Name: testName,
NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{
clabernetestesthelper.NormalizeTopology,
},
},
},
"service": {
{
Name: fmt.Sprintf("%s-srl1", testName),
NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{
clabernetestesthelper.NormalizeExposeService,
},
},
{
Name: fmt.Sprintf("%s-srl1-vx", testName),
NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{
clabernetestesthelper.NormalizeFabricService,
},
},
},
"deployment": {
{
Name: fmt.Sprintf("%s-srl1", testName),
NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{
clabernetestesthelper.NormalizeDeployment,
},
},
{
Name: fmt.Sprintf("%s-srl2", testName),
NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{
clabernetestesthelper.NormalizeDeployment,
},
},
},
"connectivity": {
{
Name: testName,
NormalizeFuncs: []func(t *testing.T, objectData []byte) []byte{
clabernetestesthelper.NormalizeConnectivity,
},
},
},
},
},
}

clabernetestesthelpersuite.Run(t, steps, namespace)
clabernetestesthelpersuite.Run(t, testName, steps, namespace)
}
51 changes: 51 additions & 0 deletions testhelper/kubernetes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testhelper

import (
"regexp"
"testing"

clabernetesutil "github.com/srl-labs/clabernetes/util"
@@ -53,6 +54,18 @@ func NormalizeKubernetesObject(t *testing.T, object []byte) []byte {
// can also see a uid on owner refs, we should only ever have one owner ref...
object = YQCommand(t, object, "del(.metadata.ownerReferences[0].uid)")

// revision and restartedAt annotations obviously will change in tests
object = YQCommand(
t,
object,
"del(.metadata.annotations.\"deployment.kubernetes.io/revision\")",
)
object = YQCommand(
t,
object,
"del(.spec.template.metadata.annotations.\"kubectl.kubernetes.io/restartedAt\")",
)

return object
}

@@ -98,3 +111,41 @@ func NormalizeExposeService(t *testing.T, objectData []byte) []byte {

return objectData
}

// NormalizeFabricService normalizes a (fabric) service cr by removing fields that may change
// between ci and local or other folks machines/clusters -- so we can compare results more easily.
func NormalizeFabricService(t *testing.T, objectData []byte) []byte {
t.Helper()

// cluster ips obviously are going to be different all the time so we'll ignore them
objectData = YQCommand(t, objectData, "del(.spec.clusterIP)")
objectData = YQCommand(t, objectData, "del(.spec.clusterIPs)")

// remove node ports since they'll be random
objectData = YQCommand(t, objectData, "del(.spec.ports[].nodePort)")

return objectData
}

// NormalizeDeployment normalizes a deployment by removing fields that may change between ci and
// local or other folks machines/clusters (like image/registry)-- so we can compare results more
// easily.
func NormalizeDeployment(t *testing.T, objectData []byte) []byte {
t.Helper()

// we dont care about testing that the image was set "right" really, so just remove it
objectData = YQCommand(t, objectData, "del(.spec.template.spec.containers[0].image)")

return objectData
}

// NormalizeConnectivity normalizes a connectivity cr between ci and local or other folks
// machines/clusters -- so we can compare results more easily. For now this is just replacing the
// namespace in the destinations since those will be random(ish) per test run.
func NormalizeConnectivity(t *testing.T, objectData []byte) []byte {
t.Helper()

// replace the namespace in the connectivity destinations
return regexp.MustCompile(`\..*\.svc.cluster.local`).
ReplaceAll(objectData, []byte(".NAMESPACE.svc.cluster.local"))
}
30 changes: 16 additions & 14 deletions testhelper/suite/run.go
Original file line number Diff line number Diff line change
@@ -15,11 +15,13 @@ const (
)

// Run executes a clabernetes e2e test.
func Run(t *testing.T, steps []Step, namespace string) { //nolint: thelper
func Run(t *testing.T, testName string, steps []Step, namespace string) { //nolint: thelper
clabernetestesthelper.KubectlCreateNamespace(t, namespace)

defer func() {
if !*clabernetestesthelper.SkipCleanup {
t.Logf("deleting namespace %q used in test %q", namespace, testName)

clabernetestesthelper.KubectlDeleteNamespace(t, namespace)
}
}()
@@ -45,26 +47,26 @@ func Run(t *testing.T, steps []Step, namespace string) { //nolint: thelper
for idx := range objects {
object := step.AssertObjects[kind][idx]

t.Logf("\tbegin assertion of %q resources %q", kind, object.Name)

fileName := fmt.Sprintf("golden/%d-%s.%s.yaml", step.Index, kind, object.Name)

if *clabernetestesthelper.Update {
// updating so no reason to fetch/compare object
objectData := getter(t, namespace, kind, object.Name, object)

clabernetestesthelper.WriteTestFixtureFile(t, fileName, objectData)

// we just wrote the golden file of course it will match, no need to check
break
} else {
eventually(
t,
eventuallyPollInterval,
eventuallyMaxTime,
func() []byte {
return getter(t, namespace, kind, object.Name, object)
},
clabernetestesthelper.ReadTestFixtureFile(t, fileName),
)
}

eventually(
t,
eventuallyPollInterval,
eventuallyMaxTime,
func() []byte {
return getter(t, namespace, kind, object.Name, object)
},
clabernetestesthelper.ReadTestFixtureFile(t, fileName),
)
}
}

0 comments on commit b91c0c1

Please sign in to comment.