github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/releases/versions_test.go (about) 1 package releases 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 type testCase struct { 11 name string 12 version string 13 releaseVersion string 14 expectedState SoftwareUpdateState 15 expectReleaseNil bool 16 } 17 18 func TestCheckIsLatestVersion(t *testing.T) { 19 testCases := []testCase{ 20 {"up to date", "v1.5.6", "v1.5.6", UpToDate, false}, 21 {"ahead of version", "v1.7.0", "v1.5.6", UpToDate, false}, 22 {"new version", "v1.5.6", "v1.5.7", UpdateAvailable, false}, 23 {"new minor version", "v1.5.6", "v1.6.0", UpdateAvailable, false}, 24 {"new major version", "v1.5.6", "v2.0.0", UpdateAvailable, false}, 25 {"invalid version", "abcdef", "v1.6.0", UnreleasedVersion, true}, 26 {"empty version", "", "v1.6.0", UnreleasedVersion, true}, 27 {"invalid release version", "v1.5.6", "abderf", Unknown, true}, 28 {"invalid release version string", "v1.5.6", "1.7.8", Unknown, true}, 29 } 30 31 for _, tc := range testCases { 32 tc := tc 33 t.Run(tc.name, func(t *testing.T) { 34 state, _, release, _ := CheckIsLatestVersion(context.Background(), func() (string, error) { 35 return tc.version, nil 36 }, func(ctx context.Context) (*Release, error) { 37 return &Release{ 38 Version: tc.releaseVersion, 39 }, nil 40 }) 41 require.Equal(t, tc.expectedState, state) 42 require.Equal(t, tc.expectReleaseNil, release == nil) 43 }) 44 } 45 }