Skip to content

Commit f174f30

Browse files
authored
fix: Version fetching code and test (#2097)
This re-instates the test for `GetLatestCLIRelease` and ensures it also works on pre-release versions.
1 parent a29b20d commit f174f30

2 files changed

Lines changed: 13 additions & 18 deletions

File tree

cli/internal/plugins/versions.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ func GetLatestCLIRelease(ctx context.Context) (string, error) {
4444
if err != nil {
4545
return "", fmt.Errorf("unmarshaling manifest response: %w", err)
4646
}
47-
return extractVersionFromTag(mr.Latest), nil
47+
tag := strings.TrimPrefix(mr.Latest, "cli-")
48+
return tag, nil
4849
}
4950

5051
func getLatestCQPluginRelease(ctx context.Context, name string, typ PluginType) (string, error) {
@@ -58,14 +59,8 @@ func getLatestCQPluginRelease(ctx context.Context, name string, typ PluginType)
5859
if err != nil {
5960
return "", fmt.Errorf("unmarshaling manifest response: %w", err)
6061
}
61-
return extractVersionFromTag(mr.Latest), nil
62-
}
63-
64-
// extractVersionFromTag takes a tag of the form "plugins-source-test-v0.1.21" and returns
65-
// the version, i.e. "v0.1.21"
66-
func extractVersionFromTag(tag string) string {
67-
parts := strings.Split(tag, "-")
68-
return parts[len(parts)-1]
62+
version := strings.TrimPrefix(mr.Latest, fmt.Sprintf("plugins-%s-%s-", string(typ), name))
63+
return version, nil
6964
}
7065

7166
func getLatestCommunityPluginRelease(ctx context.Context, org, name string, typ PluginType) (string, error) {

cli/internal/plugins/versions_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ func TestGetLatestCommunityPluginRelease(t *testing.T) {
2828
}
2929
}
3030

31-
// func TestGetLatestCLIRelease(t *testing.T) {
32-
// version, err := GetLatestCLIRelease(context.Background())
33-
// if err != nil {
34-
// t.Fatalf("error calling GetLatestCLIRelease: %v", err)
35-
// }
31+
func TestGetLatestCLIRelease(t *testing.T) {
32+
version, err := GetLatestCLIRelease(context.Background())
33+
if err != nil {
34+
t.Fatalf("error calling GetLatestCLIRelease: %v", err)
35+
}
3636

37-
// if !strings.HasPrefix(version, "v") {
38-
// t.Errorf("got version = %q, want a version starting with 'v'", version)
39-
// }
40-
// }
37+
if !strings.HasPrefix(version, "v") {
38+
t.Errorf("got version = %q, want a version starting with 'v'", version)
39+
}
40+
}

0 commit comments

Comments
 (0)