Skip to content
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

✨ Add hash mode compatibility #108

Merged
merged 3 commits into from
Feb 27, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,10 @@ func getNodeImagesFromLocal(localDownloadPath string) (*NodeImages, error) {

// cutOpenStackClusterStackReleaseVersionFromReleaseTag returns a release tag without version,
// e.g. from `openstack-ferrol-1-27-v2` returns `openstack-ferrol-1-27`.
// e.g. from `openstack-ferrol-1-27-v0-sha-a3baa3a` returns `openstack-ferrol-1-27`.
func cutOpenStackClusterStackReleaseVersionFromReleaseTag(releaseTag string) (string, error) {
v := strings.Split(releaseTag, "-")
if len(v) != 5 && len(v) != 6 {
if len(v) != 5 && len(v) != 7 {
return "", fmt.Errorf("invalid release tag %s", releaseTag)
}
return fmt.Sprintf("%s-%s-%s-%s", v[0], v[1], v[2], v[3]), nil
Expand Down
54 changes: 41 additions & 13 deletions internal/controller/openstackclusterstackrelease_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,48 @@ const (
)

func TestCutOpenStackClusterStackReleaseVersionFromReleaseTag(t *testing.T) {
// correct release tag
releaseTag := "openstack-ferrol-1-27-v2"
nameWithoutVersion, err := cutOpenStackClusterStackReleaseVersionFromReleaseTag(releaseTag)

assert.NoError(t, err)
assert.Equal(t, nameWithoutVersion, "openstack-ferrol-1-27")

// incorrect release tag
releaseTag = "openstack-ferrol-1-27"
nameWithoutVersion, err = cutOpenStackClusterStackReleaseVersionFromReleaseTag(releaseTag)
tests := []struct {
releaseTag string
expected string
incorrect bool
}{
{
"openstack-ferrol-1-27-v2", // stable channel
"openstack-ferrol-1-27",
false,
},
{
"openstack-ferrol-1-27-v0-sha-a3baa3a", // custom channel (hash mode)
"openstack-ferrol-1-27",
false,
},
{
"docker-ferrol-1-26-v1-alpha-0", // alpha channel
"docker-ferrol-1-26",
false,
},
{
"openstack-ferrol-1-27", // incorrect tag
"",
true,
},
{
"docker-ferrol-1.26", // incorrect tag
"",
true,
},
}
for _, test := range tests {
nameWithoutVersion, err := cutOpenStackClusterStackReleaseVersionFromReleaseTag(test.releaseTag)
if test.incorrect {
assert.Error(t, err)
assert.EqualError(t, err, fmt.Sprintf("invalid release tag %s", test.releaseTag))
} else {
assert.NoError(t, err)
}

assert.Error(t, err)
assert.EqualError(t, err, fmt.Sprintf("invalid release tag %s", releaseTag))
assert.Empty(t, nameWithoutVersion)
assert.Equal(t, nameWithoutVersion, test.expected)
}
}

func TestGenerateOwnerReference(t *testing.T) {
Expand Down
Loading