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

Add unit test for func IsGTE #8905

Merged
merged 1 commit into from
Apr 13, 2020
Merged
Changes from all 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
55 changes: 54 additions & 1 deletion pkg/k8sversion/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ limitations under the License.

package k8sversion

import "testing"
import (
"testing"
)

func TestParse(t *testing.T) {
grid := []struct {
Expand Down Expand Up @@ -55,3 +57,54 @@ func TestParse(t *testing.T) {
}
}
}

func TestIsGTE(t *testing.T) {
kv, _ := Parse("1.6.2-alpha.1+ea69570f61af8e")
cases := []struct {
Name string
Version string
Expected bool
}{
{
Name: "KV greater than Version",
Version: "1.4.0",
Expected: true,
},
{
Name: "KV greater than Version",
Version: "1.4.0-alpha.1",
Expected: true,
},

{
Name: "KV equal Version",
Version: "1.6.2",
Expected: true,
},
{
Name: "KV equal Version",
Version: "1.6.2-alpha.1+ea69570f61af8e",
Expected: true,
},

{
Name: "Version greater than KV",
Version: "1.6.5",
Expected: false,
},
{
Name: "KV equal Version",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think Name should be "Version greater than KV" (?)

Version: "1.6.5+ea69570f61af8e",
Expected: false,
},
}

for _, c := range cases {
t.Run(c.Name, func(t *testing.T) {
ret := kv.IsGTE(c.Version)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I normally use actual for the value we got

if c.Expected != ret {
t.Errorf("Expected: %v, Got: %v", c.Expected, ret)
}
})
}
}