Skip to content

Commit

Permalink
Add hash mode compatibility (#108)
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Feder <[email protected]>
  • Loading branch information
matofeder authored Feb 27, 2024
1 parent 1d01a75 commit c6a4caf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
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

0 comments on commit c6a4caf

Please sign in to comment.