From af2855a18c070ee919cb5a5280dc3296952aa3e5 Mon Sep 17 00:00:00 2001 From: mitch Date: Mon, 24 Oct 2022 08:40:50 -0400 Subject: [PATCH] Added tests for VersionInSlice --- SemVersion_test.go | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 SemVersion_test.go diff --git a/SemVersion_test.go b/SemVersion_test.go new file mode 100644 index 0000000..a9268e5 --- /dev/null +++ b/SemVersion_test.go @@ -0,0 +1,88 @@ +package versionedTerraform + +import "testing" + +func TestSemVersion_VersionInSlice_success(t *testing.T) { + want := SemVersion{ + version: "1.1.9", + isStable: true, + majorVersion: 1, + minorVersion: 1, + patchVersion: 9, + } + ver1 := SemVersion{ + version: "1.1.10", + isStable: true, + majorVersion: 1, + minorVersion: 1, + patchVersion: 10, + } + + ver2 := SemVersion{ + version: "0.1.9", + isStable: true, + majorVersion: 0, + minorVersion: 1, + patchVersion: 9, + } + + ver3 := SemVersion{ + version: "1.0.9", + isStable: true, + majorVersion: 1, + minorVersion: 0, + patchVersion: 9, + } + + var semArray []SemVersion + semArray = append(semArray, ver1) + semArray = append(semArray, ver2) + semArray = append(semArray, ver3) + semArray = append(semArray, want) + + if !want.VersionInSlice(semArray) { + t.Errorf("Expected Sem Version to be found in semArray") + } +} + +func TestSemVersion_VersionInSlice_fail(t *testing.T) { + want := SemVersion{ + version: "1.1.9", + isStable: true, + majorVersion: 1, + minorVersion: 1, + patchVersion: 9, + } + ver1 := SemVersion{ + version: "1.1.10", + isStable: true, + majorVersion: 1, + minorVersion: 1, + patchVersion: 10, + } + + ver2 := SemVersion{ + version: "0.1.9", + isStable: true, + majorVersion: 0, + minorVersion: 1, + patchVersion: 9, + } + + ver3 := SemVersion{ + version: "1.0.9", + isStable: true, + majorVersion: 1, + minorVersion: 0, + patchVersion: 9, + } + + var semArray []SemVersion + semArray = append(semArray, ver1) + semArray = append(semArray, ver2) + semArray = append(semArray, ver3) + + if want.VersionInSlice(semArray) { + t.Errorf("Expected Sem Version to not be found in semArray") + } +}