refactor: don't reinvent the wheel
This commit is contained in:
@ -1,87 +0,0 @@
|
||||
package deploy
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetImageNameAndTag(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
imageName string
|
||||
expectedName string
|
||||
expectedTag string
|
||||
expectError bool
|
||||
description string
|
||||
}{
|
||||
{
|
||||
name: "standard image with tag",
|
||||
imageName: "nginx:1.23",
|
||||
expectedName: "nginx",
|
||||
expectedTag: "1.23",
|
||||
expectError: false,
|
||||
description: "should parse standard image name with tag",
|
||||
},
|
||||
{
|
||||
name: "image with digest",
|
||||
imageName: "nginx:1.23@sha256:abc123",
|
||||
expectedName: "nginx",
|
||||
expectedTag: "1.23",
|
||||
expectError: false,
|
||||
description: "should parse image with digest, ignoring digest part",
|
||||
},
|
||||
{
|
||||
name: "image with latest tag",
|
||||
imageName: "redis:latest",
|
||||
expectedName: "redis",
|
||||
expectedTag: "latest",
|
||||
expectError: false,
|
||||
description: "should parse image with latest tag",
|
||||
},
|
||||
{
|
||||
name: "image with numeric tag",
|
||||
imageName: "postgres:14",
|
||||
expectedName: "postgres",
|
||||
expectedTag: "14",
|
||||
expectError: false,
|
||||
description: "should parse image with numeric tag",
|
||||
},
|
||||
{
|
||||
name: "image with complex name",
|
||||
imageName: "registry.example.com/myapp/api:v1.2.3",
|
||||
expectedName: "registry.example.com/myapp/api",
|
||||
expectedTag: "v1.2.3",
|
||||
expectError: false,
|
||||
description: "should parse image with registry prefix and complex name",
|
||||
},
|
||||
{
|
||||
name: "image without tag",
|
||||
imageName: "nginx",
|
||||
expectError: true,
|
||||
description: "should error when no tag present",
|
||||
},
|
||||
{
|
||||
name: "empty image name",
|
||||
imageName: "",
|
||||
expectError: true,
|
||||
description: "should error on empty image name",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
name, tag, err := GetImageNameAndTag(tt.imageName)
|
||||
|
||||
if tt.expectError {
|
||||
assert.Error(t, err)
|
||||
assert.Empty(t, name)
|
||||
assert.Empty(t, tag)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.expectedName, name)
|
||||
assert.Equal(t, tt.expectedTag, tag)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user