зеркало из https://github.com/Azure/draft-classic.git
Merge pull request #758 from bacongobbler/use-trimsuffix
use strings.TrimSuffix instead of strings.Replace
This commit is contained in:
Коммит
685cd49619
|
@ -213,7 +213,7 @@ func (b *Builder) AuthToken(ctx context.Context, app *builder.AppContext) (strin
|
|||
}
|
||||
|
||||
func getRegistryName(registry string) string {
|
||||
return strings.Replace(registry, ".azurecr.io", "", 1)
|
||||
return strings.TrimSuffix(registry, ".azurecr.io")
|
||||
}
|
||||
|
||||
func blobComplete(metadata azblob.Metadata) bool {
|
||||
|
|
|
@ -3,10 +3,21 @@ package azure
|
|||
import "testing"
|
||||
|
||||
func TestGetRegistryName(t *testing.T) {
|
||||
input := "acrdevname.azurecr.io"
|
||||
expected := "acrdevname"
|
||||
output := getRegistryName(input)
|
||||
if output != expected {
|
||||
t.Errorf("getRegistryName: expected %v but got %v", expected, output)
|
||||
var registryNameTests = []struct {
|
||||
in string
|
||||
out string
|
||||
}{
|
||||
{"acrdevname.azurecr.io", "acrdevname"},
|
||||
{"jpalma.azurecr.io", "jpalma"},
|
||||
{"usdraftacr.azurecr.io", "usdraftacr"},
|
||||
}
|
||||
|
||||
for _, tt := range registryNameTests {
|
||||
t.Run(tt.in, func(t *testing.T) {
|
||||
actual := getRegistryName(tt.in)
|
||||
if actual != tt.out {
|
||||
t.Errorf("expected %v but got %v", tt.out, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче