зеркало из https://github.com/Azure/draft-classic.git
use strings.TrimSuffix instead of strings.Replace
strings.TrimSuffix is a safer option than strings.Replace for this operation.
This commit is contained in:
Родитель
41f386fec3
Коммит
3c5e572b24
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче