From 01fc19f73f3c1c3938c4b72dd65141372f0e16e2 Mon Sep 17 00:00:00 2001 From: Akanksha Gahalot Date: Mon, 19 Jun 2023 09:58:46 +0530 Subject: [PATCH 1/3] Added unit-tests for internal/version.go Signed-off-by: Akanksha Gahalot --- go.mod | 3 +++ internal/version/version_test.go | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 internal/version/version_test.go diff --git a/go.mod b/go.mod index eeca4a3af..da0cd4e2f 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/internal/version/version_test.go b/internal/version/version_test.go new file mode 100644 index 000000000..2bbf7fbcb --- /dev/null +++ b/internal/version/version_test.go @@ -0,0 +1,35 @@ +/* +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 ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_GetVersion(t *testing.T) { + expected := "1.0.0+unreleased" + actual := GetVersion() + assert.Equal(t, expected, actual) + +} + +func Test_GetVersion_when_BuildData_is_empty(t *testing.T) { + BuildMetadata = "" + expected := "1.0.0" + actual := GetVersion() + assert.Equal(t, expected, actual) + +} From eb8e789bd681c74f86ee89784b188640378051f5 Mon Sep 17 00:00:00 2001 From: Akanksha Gahalot Date: Tue, 20 Jun 2023 12:00:57 +0530 Subject: [PATCH 2/3] removed testify and used reflect as used in other unit tests Signed-off-by: Akanksha Gahalot --- internal/version/version_test.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/version/version_test.go b/internal/version/version_test.go index 2bbf7fbcb..c41e53e1b 100644 --- a/internal/version/version_test.go +++ b/internal/version/version_test.go @@ -14,15 +14,16 @@ limitations under the License. package version import ( + "reflect" "testing" - - "github.com/stretchr/testify/assert" ) func Test_GetVersion(t *testing.T) { expected := "1.0.0+unreleased" actual := GetVersion() - assert.Equal(t, expected, actual) + if !reflect.DeepEqual(expected, actual) { + t.Errorf("Tested GetVersion expected was %v actually got %v", expected, actual) + } } @@ -30,6 +31,7 @@ func Test_GetVersion_when_BuildData_is_empty(t *testing.T) { BuildMetadata = "" expected := "1.0.0" actual := GetVersion() - assert.Equal(t, expected, actual) - + if !reflect.DeepEqual(expected, actual) { + t.Errorf("Tested GetVersion expected was %v actually got %v", expected, actual) + } } From 9b72dca579583a432eafb0e3b3485e8430a0706e Mon Sep 17 00:00:00 2001 From: Akanksha Gahalot Date: Tue, 20 Jun 2023 14:22:27 +0530 Subject: [PATCH 3/3] resolved review comments Signed-off-by: Akanksha Gahalot --- go.mod | 3 --- internal/version/version_test.go | 11 +---------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/go.mod b/go.mod index da0cd4e2f..eeca4a3af 100644 --- a/go.mod +++ b/go.mod @@ -10,17 +10,14 @@ 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 ) diff --git a/internal/version/version_test.go b/internal/version/version_test.go index c41e53e1b..eaca323ab 100644 --- a/internal/version/version_test.go +++ b/internal/version/version_test.go @@ -18,18 +18,9 @@ import ( "testing" ) -func Test_GetVersion(t *testing.T) { - 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" + expected := Version actual := GetVersion() if !reflect.DeepEqual(expected, actual) { t.Errorf("Tested GetVersion expected was %v actually got %v", expected, actual)