Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit f785cc6

Browse files
authored
Enable unit tests and add the first one (#51)
Test cutOpenStackClusterStackReleaseVersionFromReleaseTag function Signed-off-by: Roman Hros <[email protected]>
1 parent c1900a7 commit f785cc6

21 files changed

+6147
-17
lines changed

.github/workflows/test.yaml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,8 @@ jobs:
5252
run: |
5353
go mod download
5454
55-
# - name: Running unit tests
56-
# env:
57-
# GIT_PROVIDER: github
58-
# GIT_ORG_NAME: sovereignCloudStack
59-
# GIT_REPOSITORY_NAME: fake-cluster-stacks
60-
# GIT_ACCESS_TOKEN: ${{ secrets.GIT_ACCESS_TOKEN }}
61-
# run: make test-unit
55+
- name: Running unit tests
56+
run: make test-unit
6257

6358
# - name: Create Report
6459
# run: make report-cover-html report-cover-treemap

Makefile

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -528,16 +528,15 @@ generate-modules-ci: generate-modules
528528

529529
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use --use-env --bin-dir $(abspath $(TOOLS_BIN_DIR)) -p path $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))
530530

531-
# .PHONY: test-unit
532-
# test-unit: test-unit-openstack
533-
# echo done
534-
535-
# .PHONY: test-unit-openstack
536-
# test-unit-openstack: $(SETUP_ENVTEST) $(GOTESTSUM) $(HELM) ## Run unit and integration tests
537-
# @mkdir -p $(shell pwd)/.coverage
538-
# cd $(TEST_DIR); CREATE_KIND_CLUSTER=false KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" $(GOTESTSUM) --junitfile=../.coverage/junit.xml --format testname -- -mod=vendor \
539-
# -covermode=atomic -coverprofile=../.coverage/cover.out -p=4 ./internal/controller/...
540-
531+
.PHONY: test-unit
532+
test-unit: test-unit-openstack ## Run unit tests
533+
echo done
534+
535+
.PHONY: test-unit-openstack
536+
test-unit-openstack: $(SETUP_ENVTEST) $(GOTESTSUM) $(HELM)
537+
@mkdir -p $(shell pwd)/.coverage
538+
CREATE_KIND_CLUSTER=false KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" $(GOTESTSUM) --junitfile=.coverage/junit.xml --format testname -- -mod=vendor \
539+
-covermode=atomic -coverprofile=.coverage/cover.out -p=4 ./internal/controller/...
541540

542541
##@ Main Targets
543542
################

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/gophercloud/utils v0.0.0-20231010081019-80377eca5d56
99
github.com/onsi/ginkgo/v2 v2.14.0
1010
github.com/onsi/gomega v1.30.0
11+
github.com/stretchr/testify v1.8.4
1112
k8s.io/api v0.28.4
1213
k8s.io/apimachinery v0.28.4
1314
k8s.io/client-go v0.28.4
@@ -55,6 +56,7 @@ require (
5556
github.com/modern-go/reflect2 v1.0.2 // indirect
5657
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
5758
github.com/pkg/errors v0.9.1 // indirect
59+
github.com/pmezard/go-difflib v1.0.0 // indirect
5860
github.com/prometheus/client_golang v1.17.0 // indirect
5961
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
6062
github.com/prometheus/common v0.44.0 // indirect
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2023 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package controller
18+
19+
import (
20+
"testing"
21+
22+
"github.com/stretchr/testify/assert"
23+
)
24+
25+
func TestCutOpenStackClusterStackReleaseVersionFromReleaseTag(t *testing.T) {
26+
releaseTag := "openstack-ferrol-1-27-v2"
27+
nameWithoutVersion, err := cutOpenStackClusterStackReleaseVersionFromReleaseTag(releaseTag)
28+
29+
assert.NoError(t, err)
30+
assert.Equal(t, nameWithoutVersion, "openstack-ferrol-1-27")
31+
32+
releaseTag = "openstack-ferrol-1-27"
33+
_, err = cutOpenStackClusterStackReleaseVersionFromReleaseTag(releaseTag)
34+
35+
assert.Error(t, err)
36+
}

vendor/github.com/pmezard/go-difflib/LICENSE

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)