-
Notifications
You must be signed in to change notification settings - Fork 674
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add semver check for dev and beta version (#5757)
* Add semver check for dev and beta version Signed-off-by: pmahindrakar-oss <[email protected]> * add unsupported version tests Signed-off-by: pmahindrakar-oss <[email protected]> * passing context and refactored to table driven utests Signed-off-by: pmahindrakar-oss <[email protected]> --------- Signed-off-by: pmahindrakar-oss <[email protected]>
- Loading branch information
1 parent
fd841ba
commit 2d9c35b
Showing
3 changed files
with
134 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,126 @@ | ||
package config | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIsSupportedSDKVersion(t *testing.T) { | ||
t.Run("supported version", func(t *testing.T) { | ||
config := LiteralOffloadingConfig{ | ||
SupportedSDKVersions: map[string]string{ | ||
"flytekit": "0.16.0", | ||
}, | ||
} | ||
assert.True(t, config.IsSupportedSDKVersion("flytekit", "0.16.0")) | ||
}) | ||
|
||
t.Run("unsupported version", func(t *testing.T) { | ||
config := LiteralOffloadingConfig{ | ||
SupportedSDKVersions: map[string]string{ | ||
"flytekit": "0.16.0", | ||
}, | ||
} | ||
assert.False(t, config.IsSupportedSDKVersion("flytekit", "0.15.0")) | ||
}) | ||
|
||
t.Run("unsupported SDK", func(t *testing.T) { | ||
config := LiteralOffloadingConfig{ | ||
SupportedSDKVersions: map[string]string{ | ||
"flytekit": "0.16.0", | ||
}, | ||
} | ||
assert.False(t, config.IsSupportedSDKVersion("unknown", "0.16.0")) | ||
}) | ||
|
||
t.Run("invalid version", func(t *testing.T) { | ||
config := LiteralOffloadingConfig{ | ||
SupportedSDKVersions: map[string]string{ | ||
"flytekit": "0.16.0", | ||
}, | ||
} | ||
assert.False(t, config.IsSupportedSDKVersion("flytekit", "invalid")) | ||
}) | ||
ctx := context.Background() | ||
tests := []struct { | ||
name string | ||
config LiteralOffloadingConfig | ||
sdk string | ||
version string | ||
expectedResult bool | ||
}{ | ||
{ | ||
name: "supported version", | ||
config: LiteralOffloadingConfig{ | ||
SupportedSDKVersions: map[string]string{ | ||
"flytekit": "0.16.0", | ||
}, | ||
}, | ||
sdk: "flytekit", | ||
version: "0.16.0", | ||
expectedResult: true, | ||
}, | ||
{ | ||
name: "unsupported version", | ||
config: LiteralOffloadingConfig{ | ||
SupportedSDKVersions: map[string]string{ | ||
"flytekit": "0.16.0", | ||
}, | ||
}, | ||
sdk: "flytekit", | ||
version: "0.15.0", | ||
expectedResult: false, | ||
}, | ||
{ | ||
name: "unsupported SDK", | ||
config: LiteralOffloadingConfig{ | ||
SupportedSDKVersions: map[string]string{ | ||
"flytekit": "0.16.0", | ||
}, | ||
}, | ||
sdk: "unknown", | ||
version: "0.16.0", | ||
expectedResult: false, | ||
}, | ||
{ | ||
name: "invalid version", | ||
config: LiteralOffloadingConfig{ | ||
SupportedSDKVersions: map[string]string{ | ||
"flytekit": "0.16.0", | ||
}, | ||
}, | ||
sdk: "flytekit", | ||
version: "invalid", | ||
expectedResult: false, | ||
}, | ||
{ | ||
name: "invalid constraint", | ||
config: LiteralOffloadingConfig{ | ||
SupportedSDKVersions: map[string]string{ | ||
"flytekit": "invalid", | ||
}, | ||
}, | ||
sdk: "flytekit", | ||
version: "0.16.0", | ||
expectedResult: false, | ||
}, | ||
{ | ||
name: "supported dev version", | ||
config: LiteralOffloadingConfig{ | ||
SupportedSDKVersions: map[string]string{ | ||
"flytekit": "1.13.4", | ||
}, | ||
}, | ||
sdk: "flytekit", | ||
version: "1.13.4.dev12+g990b450ea.d20240917", | ||
expectedResult: true, | ||
}, | ||
{ | ||
name: "supported beta version", | ||
config: LiteralOffloadingConfig{ | ||
SupportedSDKVersions: map[string]string{ | ||
"flytekit": "1.13.4", | ||
}, | ||
}, | ||
sdk: "flytekit", | ||
version: "v1.13.6b0", | ||
expectedResult: true, | ||
}, | ||
{ | ||
name: "unsupported dev version", | ||
config: LiteralOffloadingConfig{ | ||
SupportedSDKVersions: map[string]string{ | ||
"flytekit": "1.13.4", | ||
}, | ||
}, | ||
sdk: "flytekit", | ||
version: "1.13.3.dev12+g990b450ea.d20240917", | ||
expectedResult: false, | ||
}, | ||
{ | ||
name: "unsupported beta version", | ||
config: LiteralOffloadingConfig{ | ||
SupportedSDKVersions: map[string]string{ | ||
"flytekit": "1.13.4", | ||
}, | ||
}, | ||
sdk: "flytekit", | ||
version: "v1.13.3b0", | ||
expectedResult: false, | ||
}, | ||
} | ||
|
||
t.Run("invalid constraint", func(t *testing.T) { | ||
config := LiteralOffloadingConfig{ | ||
SupportedSDKVersions: map[string]string{ | ||
"flytekit": "invalid", | ||
}, | ||
} | ||
assert.False(t, config.IsSupportedSDKVersion("flytekit", "0.16.0")) | ||
}) | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := tt.config.IsSupportedSDKVersion(ctx, tt.sdk, tt.version) | ||
assert.Equal(t, tt.expectedResult, result) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters