Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add unit-tests for internal/version.go #977

Merged
merged 4 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions go.mod
enraiha0307 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ require (
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
golang.org/x/term v0.8.0
gopkg.in/yaml.v3 v3.0.1
oras.land/oras-go/v2 v2.2.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/docker-credential-helpers v0.7.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.8.0 // indirect
)
37 changes: 37 additions & 0 deletions internal/version/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright The ORAS 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 (
"reflect"
"testing"
)

func Test_GetVersion(t *testing.T) {
enraiha0307 marked this conversation as resolved.
Show resolved Hide resolved
expected := "1.0.0+unreleased"
actual := GetVersion()
if !reflect.DeepEqual(expected, actual) {
t.Errorf("Tested GetVersion expected was %v actually got %v", expected, actual)
}

}

func Test_GetVersion_when_BuildData_is_empty(t *testing.T) {
BuildMetadata = ""
expected := "1.0.0"
enraiha0307 marked this conversation as resolved.
Show resolved Hide resolved
actual := GetVersion()
if !reflect.DeepEqual(expected, actual) {
t.Errorf("Tested GetVersion expected was %v actually got %v", expected, actual)
}
}