Skip to content

Commit

Permalink
Enable unit tests and add the first one (#51)
Browse files Browse the repository at this point in the history
Test cutOpenStackClusterStackReleaseVersionFromReleaseTag function

Signed-off-by: Roman Hros <[email protected]>
  • Loading branch information
chess-knight authored Jan 17, 2024
1 parent c1900a7 commit f785cc6
Show file tree
Hide file tree
Showing 21 changed files with 6,147 additions and 17 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,8 @@ jobs:
run: |
go mod download
# - name: Running unit tests
# env:
# GIT_PROVIDER: github
# GIT_ORG_NAME: sovereignCloudStack
# GIT_REPOSITORY_NAME: fake-cluster-stacks
# GIT_ACCESS_TOKEN: ${{ secrets.GIT_ACCESS_TOKEN }}
# run: make test-unit
- name: Running unit tests
run: make test-unit

# - name: Create Report
# run: make report-cover-html report-cover-treemap
Expand Down
19 changes: 9 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -528,16 +528,15 @@ generate-modules-ci: generate-modules

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

# .PHONY: test-unit
# test-unit: test-unit-openstack
# echo done

# .PHONY: test-unit-openstack
# test-unit-openstack: $(SETUP_ENVTEST) $(GOTESTSUM) $(HELM) ## Run unit and integration tests
# @mkdir -p $(shell pwd)/.coverage
# cd $(TEST_DIR); CREATE_KIND_CLUSTER=false KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" $(GOTESTSUM) --junitfile=../.coverage/junit.xml --format testname -- -mod=vendor \
# -covermode=atomic -coverprofile=../.coverage/cover.out -p=4 ./internal/controller/...

.PHONY: test-unit
test-unit: test-unit-openstack ## Run unit tests
echo done

.PHONY: test-unit-openstack
test-unit-openstack: $(SETUP_ENVTEST) $(GOTESTSUM) $(HELM)
@mkdir -p $(shell pwd)/.coverage
CREATE_KIND_CLUSTER=false KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" $(GOTESTSUM) --junitfile=.coverage/junit.xml --format testname -- -mod=vendor \
-covermode=atomic -coverprofile=.coverage/cover.out -p=4 ./internal/controller/...

##@ Main Targets
################
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/gophercloud/utils v0.0.0-20231010081019-80377eca5d56
github.com/onsi/ginkgo/v2 v2.14.0
github.com/onsi/gomega v1.30.0
github.com/stretchr/testify v1.8.4
k8s.io/api v0.28.4
k8s.io/apimachinery v0.28.4
k8s.io/client-go v0.28.4
Expand Down Expand Up @@ -55,6 +56,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2023 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package controller

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestCutOpenStackClusterStackReleaseVersionFromReleaseTag(t *testing.T) {
releaseTag := "openstack-ferrol-1-27-v2"
nameWithoutVersion, err := cutOpenStackClusterStackReleaseVersionFromReleaseTag(releaseTag)

assert.NoError(t, err)
assert.Equal(t, nameWithoutVersion, "openstack-ferrol-1-27")

releaseTag = "openstack-ferrol-1-27"
_, err = cutOpenStackClusterStackReleaseVersionFromReleaseTag(releaseTag)

assert.Error(t, err)
}
27 changes: 27 additions & 0 deletions vendor/github.com/pmezard/go-difflib/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f785cc6

Please sign in to comment.