Skip to content

fix: fix bug with trailing version info not being properly stripped #14963

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

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion codersdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,12 @@ func DefaultSupportLinks(docsURL string) []LinkConfig {
}
}

func RemoveTrailingVersionInfo(v string) string {
return strings.Split(strings.Split(v, "-")[0], "+")[0]
}

func DefaultDocsURL() string {
version := strings.Split(buildinfo.Version(), "-")[0]
version := RemoveTrailingVersionInfo(buildinfo.Version())
if version == "v0.0.0" {
return "https://coder.com/docs"
}
Expand Down
35 changes: 35 additions & 0 deletions codersdk/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,3 +565,38 @@
require.NotContains(t, enterprise.Features(), "", "enterprise should not contain empty string")
require.NotContains(t, premium.Features(), "", "premium should not contain empty string")
}

func TestRemoveTrailingVersionInfo(t *testing.T) {
t.Parallel()

testCases := []struct {
Name string
Version string
ExpectedAfterStrippingInfo string
}{
{
Version: "v2.16.0+683a720",
ExpectedAfterStrippingInfo: "v2.16.0",
},
{
Version: "v2.16.0-devel+683a720)",
ExpectedAfterStrippingInfo: "v2.16.0",
},
}

for _, tc := range testCases {
// Is this still necessary?
tc := tc

t.Run(tc.Name, func(t *testing.T) {

Check failure on line 591 in codersdk/deployment_test.go

View workflow job for this annotation

GitHub Actions / lint

empty-lines: extra empty line at the end of a block (revive)
t.Parallel()

stripped := codersdk.RemoveTrailingVersionInfo(tc.Version)
if !assert.Equal(t, tc.ExpectedAfterStrippingInfo, stripped) {
// Log relevant information if the assertion fails
t.Logf("Test failed for case: %s\nExpected: %s\nGot: %s", tc.Name, tc.ExpectedAfterStrippingInfo, stripped)
}

})
}
}
Loading