diff --git a/internal/controller/openstackclusterstackrelease_controller.go b/internal/controller/openstackclusterstackrelease_controller.go index e7a1c0c4..cb4b73b3 100644 --- a/internal/controller/openstackclusterstackrelease_controller.go +++ b/internal/controller/openstackclusterstackrelease_controller.go @@ -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 diff --git a/internal/controller/openstackclusterstackrelease_controller_test.go b/internal/controller/openstackclusterstackrelease_controller_test.go index 8159e9e8..6d208ec6 100644 --- a/internal/controller/openstackclusterstackrelease_controller_test.go +++ b/internal/controller/openstackclusterstackrelease_controller_test.go @@ -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) {