Skip to content

Commit

Permalink
Added unit tests for common helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Kavinraja-G committed Sep 10, 2023
1 parent 41b4d46 commit e829316
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 60 deletions.
59 changes: 1 addition & 58 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,58 +1 @@
module github.com/Kavinraja-G/node-gizmo

go 1.20

require (
github.com/Kavinraja-G/kube-bouncer v0.1.0
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
k8s.io/api v0.28.0
k8s.io/apimachinery v0.28.0
k8s.io/cli-runtime v0.28.0
k8s.io/client-go v0.28.0
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
golang.org/x/net v0.13.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
module github.com/Kavinraja-G/node-gizmogo 1.20require ( github.com/Kavinraja-G/kube-bouncer v0.1.0 github.com/olekukonko/tablewriter v0.0.5 github.com/spf13/cobra v1.7.0 k8s.io/api v0.28.0 k8s.io/apimachinery v0.28.0 k8s.io/client-go v0.28.0)require ( github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/emicklei/go-restful/v3 v3.9.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/swag v0.22.3 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/gnostic-models v0.6.8 // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/uuid v1.3.0 // indirect github.com/imdario/mergo v0.3.6 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-runewidth v0.0.9 // indirect github.com/moby/spdystream v0.2.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect golang.org/x/net v0.13.0 // indirect golang.org/x/oauth2 v0.8.0 // indirect golang.org/x/sys v0.10.0 // indirect golang.org/x/term v0.10.0 // indirect golang.org/x/text v0.11.0 // indirect golang.org/x/time v0.3.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.30.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/klog/v2 v2.100.1 // indirect k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect sigs.k8s.io/yaml v1.3.0 // indirect)
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ k8s.io/api v0.28.0 h1:3j3VPWmN9tTDI68NETBWlDiA9qOiGJ7sdKeufehBYsM=
k8s.io/api v0.28.0/go.mod h1:0l8NZJzB0i/etuWnIXcwfIv+xnDOhL3lLW919AWYDuY=
k8s.io/apimachinery v0.28.0 h1:ScHS2AG16UlYWk63r46oU3D5y54T53cVI5mMJwwqFNA=
k8s.io/apimachinery v0.28.0/go.mod h1:X0xh/chESs2hP9koe+SdIAcXWcQ+RM5hy0ZynB+yEvw=
k8s.io/cli-runtime v0.28.0 h1:Tcz1nnccXZDNIzoH6EwjCs+7ezkUGhorzCweEvlVOFg=
k8s.io/cli-runtime v0.28.0/go.mod h1:U+ySmOKBm/JUCmebhmecXeTwNN1RzI7DW4+OM8Oryas=
k8s.io/client-go v0.28.0 h1:ebcPRDZsCjpj62+cMk1eGNX1QkMdRmQ6lmz5BLoFWeM=
k8s.io/client-go v0.28.0/go.mod h1:0Asy9Xt3U98RypWJmU1ZrRAGKhP6NqDPmptlAzK2kMc=
k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg=
Expand Down
1 change: 1 addition & 0 deletions pkg/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package pkgimport "testing"func TestGetNodeTopologyInfo(t *testing.T) { type args struct { labels map[string]string } tests := []struct { name string args args region string zone string }{ { name: "WithRegionAndZoneInfo", args: args{ labels: map[string]string{ TopologyRegionLabel: "us-east-1", TopologyZoneLabel: "us-east-1a", }, }, region: "us-east-1", zone: "us-east-1a", }, { name: "NoRegionAndZoneLabels", args: args{ labels: map[string]string{}, }, region: "", zone: "", }, { name: "WithOnlyRegionLabel", args: args{ labels: map[string]string{ TopologyRegionLabel: "us-east-1", }, }, region: "us-east-1", zone: "", }, { name: "WithOnlyZoneLabel", args: args{ labels: map[string]string{ TopologyZoneLabel: "us-east-1a", }, }, region: "", zone: "us-east-1a", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, got1 := GetNodeTopologyInfo(tt.args.labels) if got != tt.region { t.Errorf("GetNodeTopologyInfo() got = %v, region %v", got, tt.region) } if got1 != tt.zone { t.Errorf("GetNodeTopologyInfo() got1 = %v, zone %v", got1, tt.zone) } }) }}
Expand Down
39 changes: 39 additions & 0 deletions pkg/outputs/table_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package outputs

import "testing"

func TestTableOutput(t *testing.T) {
type args struct {
headers []string
outputData [][]string
}
tests := []struct {
name string
args args
}{
{
name: "GenericOutputTable",
args: args{
headers: []string{"NAME", "VERSION", "OS", "ARCHITECTURE"},
outputData: [][]string{
{
"Node01",
"1.25.6",
"linux",
"amd64",
}, {
"Node02",
"1.25.6",
"linux",
"arm64",
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
TableOutput(tt.args.headers, tt.args.outputData)
})
}
}
35 changes: 35 additions & 0 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package utils

import "testing"

func TestPrettyByteSize(t *testing.T) {
type args struct {
b int64
}
tests := []struct {
name string
args args
want string
}{
{
name: "ValidByteInPrettyFormatInKiB",
args: args{
b: 1024,
},
want: "1.0KiB",
}, {
name: "ValidByteInPrettyFormatInGiB",
args: args{
b: 1073741824,
},
want: "1.0GiB",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := PrettyByteSize(tt.args.b); got != tt.want {
t.Errorf("PrettyByteSize() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit e829316

Please sign in to comment.