Skip to content

Commit

Permalink
add unittest case
Browse files Browse the repository at this point in the history
Signed-off-by: dongjiang1989 <[email protected]>
  • Loading branch information
dongjiang1989 committed Oct 25, 2024
1 parent c6b32ec commit 3cdad8a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
uses: actions/checkout@v4
- id: git-x
run: |
echo "git-version=$(git describe --tags --always)" >> "$GITHUB_OUTPUT"
echo "git-version=$(echo \"${GITHUB_SHA:-$(git rev-parse HEAD)}\" | cut -c1-8)" >> "$GITHUB_OUTPUT"
- id: git-branch
run: |
echo "git-branch=$(echo ${GITHUB_REF##*/} | tr '[A-Z]' '[a-z]')" >> "$GITHUB_OUTPUT"
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ TOOLING=$(GOLANGCILINTER_BINARY) $(GOSEC_BINARY) $(GOSYCLO_BINARY) $(SWAGGO_BINA
GO_PKG=github.com/kubeservice-stack/$(SERVER_NAME)
COMMON_PKG ?= $(GO_PKG)/pkg
COMMON_CMD ?= $(GO_PKG)/cmd
COMMON_INTERNAL ?= $(GO_PKG)/internal
# The ldflags for the go build process to set the version related data.
GO_BUILD_LDFLAGS=\
-s \
Expand Down
41 changes: 41 additions & 0 deletions pkg/version/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright 2024 The KubeService-Stack 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 version

import (
"testing"

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

func TestVersionInfo(t *testing.T) {
assert := assert.New(t)
info := Info()
assert.Equal("(version=, branch=, revision=unknown)", info)
}

func TestVersionBuildContext(t *testing.T) {
assert := assert.New(t)
info := BuildContext()
assert.Equal("(go=go1.22.0, platform=darwin/amd64, user=, date=, tags=unknown)", info)
}

func TestVersionPrint(t *testing.T) {
assert := assert.New(t)
info := Print("echo")
assert.NotEmpty(info)
}

0 comments on commit 3cdad8a

Please sign in to comment.