Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 8 additions & 1 deletion src/go/rpk/pkg/cli/connect/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@rules_go//go:def.bzl", "go_library")
load("@rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "connect",
Expand All @@ -24,3 +24,10 @@ go_library(
"@org_uber_go_zap//:zap",
],
)

go_test(
name = "connect_test",
srcs = ["install_test.go"],
embed = [":connect"],
deps = ["@com_github_stretchr_testify//require"],
)
9 changes: 6 additions & 3 deletions src/go/rpk/pkg/cli/connect/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,15 @@ func downloadAndInstallConnect(ctx context.Context, fs afero.Fs, installPath, do
// validateVersion validates that the provided version in the flag is either
// 'latest' or it's a full semantic version.
func validateVersion(version string) error {
// This simple regexp just matches that a semver is in the string, it may
// be prefixed with 'v' and contain anything after. Nothing to capture.
// The version may be prefixed with 'v' and carry a prerelease or build
// suffix (e.g. '4.102.0-rc1'), which is forwarded to the manifest for
// lookup; the manifest is the source of truth for what is published.
// Segments are unbounded in width: Connect minor versions passed 99 in
// 4.100.0.
if version == "latest" {
return nil
}
vMatch := regexp.MustCompile(`^v?\d{1,2}\.\d{1,2}\.\d{1,2}`).MatchString(version)
vMatch := regexp.MustCompile(`^v?\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$`).MatchString(version)
if !vMatch {
return fmt.Errorf("provided version %q is not valid. Ensure is either 'latest' or it follows the format MAJOR.MINOR.PATCH (e.g., 2.1.3)", version)
}
Expand Down
27 changes: 27 additions & 0 deletions src/go/rpk/pkg/cli/connect/install_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2026 Redpanda Data, Inc.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.md
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0

package connect

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestValidateVersion(t *testing.T) {
// Connect minor versions passed 99 in 4.100.0, so segments must not be
// capped in width.
for _, ok := range []string{"latest", "4.99.0", "4.102.0", "v4.102.0", "4.102.0-rc1", "4.102.100"} {
require.NoError(t, validateVersion(ok), ok)
}
for _, bad := range []string{"", "abc", "4", "4.102", "garbage", "4.102.0garbage", "4.102.0 "} {
require.Error(t, validateVersion(bad), bad)
}
}
Loading