From 2e4b5e036c50987af1e90018d4bf2f86ce6efe94 Mon Sep 17 00:00:00 2001 From: Ammar Yasser Date: Tue, 29 Oct 2024 20:34:54 +0300 Subject: [PATCH] Run unit tests (#1287) * test: Fix unit tests to reflect latest changes - Update the node provisioner test to expect the empty string as the node ip - Update the node01 provisioner test to pass etcd sync as false Signed-off-by: aerosouund * fix: Fix naming clash in docker test There is an import called container and a method named container, rename the method to containerFromNames. Signed-off-by: aerosouund * test: Configure Makefile to add a new target called test-gocli and run it with make all Signed-off-by: aerosouund --------- Signed-off-by: aerosouund --- cluster-provision/gocli/Makefile | 6 +++- cluster-provision/gocli/docker/docker_test.go | 28 +++++++++---------- .../gocli/opts/node01/node01_test.go | 2 +- .../gocli/opts/nodes/testconfig.go | 2 +- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/cluster-provision/gocli/Makefile b/cluster-provision/gocli/Makefile index 1a60ccb8cd..f86e9df060 100644 --- a/cluster-provision/gocli/Makefile +++ b/cluster-provision/gocli/Makefile @@ -11,12 +11,16 @@ export GOFLAGS=-mod=vendor BIN_DIR = $(CURDIR)/build GO ?= go -all: container-run +all: test-gocli container-run .PHONY: test test: $(GO) test -v ./cmd/... -coverprofile cover.out +.PHONY: test-gocli +test-gocli: + $(GO) test -v ./... -coverprofile cover.out + .PHONY: gocli cli: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -ldflags "-X 'kubevirt.io/kubevirtci/cluster-provision/gocli/images.SUFFIX=:$(KUBEVIRTCI_TAG)'" -o $(BIN_DIR)/cli ./cmd/cli diff --git a/cluster-provision/gocli/docker/docker_test.go b/cluster-provision/gocli/docker/docker_test.go index 101d5391a4..4754148feb 100644 --- a/cluster-provision/gocli/docker/docker_test.go +++ b/cluster-provision/gocli/docker/docker_test.go @@ -23,23 +23,23 @@ func Test_filterByPrefix(t *testing.T) { prefix string }{ containers: []types.Container{ - container("prefix-1", "something", "unimportant"), - container("prefix-2", "something1", "unimportant1"), - container("absolutely-unrelated"), - container("something1", "not-a-prefix1", "unimportant1"), - container("something1", "prefix-3", "unimportant1"), - container("prefix-4"), - container("/prefix-5"), - container("not-a-prefix2", "unimportant1"), + containerFromNames("prefix-1", "something", "unimportant"), + containerFromNames("prefix-2", "something1", "unimportant1"), + containerFromNames("absolutely-unrelated"), + containerFromNames("something1", "not-a-prefix1", "unimportant1"), + containerFromNames("something1", "prefix-3", "unimportant1"), + containerFromNames("prefix-4"), + containerFromNames("/prefix-5"), + containerFromNames("not-a-prefix2", "unimportant1"), }, prefix: "prefix", }, want: []types.Container{ - container("prefix-1", "something", "unimportant"), - container("prefix-2", "something1", "unimportant1"), - container("something1", "prefix-3", "unimportant1"), - container("prefix-4"), - container("/prefix-5"), + containerFromNames("prefix-1", "something", "unimportant"), + containerFromNames("prefix-2", "something1", "unimportant1"), + containerFromNames("something1", "prefix-3", "unimportant1"), + containerFromNames("prefix-4"), + containerFromNames("/prefix-5"), }, }, } @@ -52,7 +52,7 @@ func Test_filterByPrefix(t *testing.T) { } } -func container(names ...string) types.Container { +func containerFromNames(names ...string) types.Container { return types.Container{ Names: names, } diff --git a/cluster-provision/gocli/opts/node01/node01_test.go b/cluster-provision/gocli/opts/node01/node01_test.go index e584717a35..0fc6ecdf06 100644 --- a/cluster-provision/gocli/opts/node01/node01_test.go +++ b/cluster-provision/gocli/opts/node01/node01_test.go @@ -24,7 +24,7 @@ var _ = Describe("Node01Provisioner", func() { BeforeEach(func() { mockCtrl = gomock.NewController(GinkgoT()) sshClient = kubevirtcimocks.NewMockSSHClient(mockCtrl) - opt = NewNode01Provisioner(sshClient, false) + opt = NewNode01Provisioner(sshClient, false, false) AddExpectCalls(sshClient) }) diff --git a/cluster-provision/gocli/opts/nodes/testconfig.go b/cluster-provision/gocli/opts/nodes/testconfig.go index 847c2c6c92..11c67eb93f 100644 --- a/cluster-provision/gocli/opts/nodes/testconfig.go +++ b/cluster-provision/gocli/opts/nodes/testconfig.go @@ -6,7 +6,7 @@ func AddExpectCalls(sshClient *kubevirtcimocks.MockSSHClient) { cmds := []string{ "source /var/lib/kubevirtci/shared_vars.sh", `timeout=30; interval=5; while ! hostnamectl | grep Transient; do echo "Waiting for dhclient to set the hostname from dnsmasq"; sleep $interval; timeout=$((timeout - interval)); [ $timeout -le 0 ] && exit 1; done`, - `echo "KUBELET_EXTRA_ARGS=--cgroup-driver=systemd --runtime-cgroups=/systemd/system.slice --kubelet-cgroups=/systemd/system.slice --fail-swap-on=false ${nodeip} --feature-gates=CPUManager=true,NodeSwap=true --cpu-manager-policy=static --kube-reserved=cpu=250m --system-reserved=cpu=250m" | tee /etc/sysconfig/kubelet > /dev/null`, + `echo "KUBELET_EXTRA_ARGS=--cgroup-driver=systemd --runtime-cgroups=/systemd/system.slice --kubelet-cgroups=/systemd/system.slice --fail-swap-on=false --feature-gates=CPUManager=true,NodeSwap=true --cpu-manager-policy=static --kube-reserved=cpu=250m --system-reserved=cpu=250m" | tee /etc/sysconfig/kubelet > /dev/null`, "systemctl daemon-reload && service kubelet restart", "swapoff -a", "until ip address show dev eth0 | grep global | grep inet6; do sleep 1; done",