Skip to content

Commit

Permalink
Add hash mode compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Feder <matej.feder@dnation.cloud>
  • Loading branch information
matofeder committed Feb 26, 2024
1 parent 1d9b91e commit 36c01c0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,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
49 changes: 36 additions & 13 deletions internal/controller/openstackclusterstackrelease_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,43 @@ 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)
"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,
},
}
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 36c01c0

Please sign in to comment.