-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
60 lines (44 loc) · 1.07 KB
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package testcontainers
import (
"strings"
"github.com/distribution/reference"
)
func mustNotFail(err error) {
if err != nil {
panic(err)
}
}
func joinStrings(prefix, s, suffix string) string {
var sb strings.Builder
if prefix != "" {
sb.WriteString(prefix)
sb.WriteRune('_')
}
sb.WriteString(s)
if suffix != "" {
sb.WriteRune('_')
sb.WriteString(suffix)
}
return sb.String()
}
func changeImageName(image string, name string) string {
named, err := reference.ParseNormalizedNamed(image)
mustNotFail(err)
if domain := reference.Domain(named); domain != "" {
name = domain + "/" + name
}
result, err := reference.WithName(name)
mustNotFail(err)
if tagged, ok := named.(reference.NamedTagged); ok {
result, err = reference.WithTag(result, tagged.Tag())
mustNotFail(err)
}
return reference.FamiliarString(result)
}
func changeImageTag(image string, tag string) string {
named, err := reference.ParseNormalizedNamed(image)
mustNotFail(err)
named, err = reference.WithTag(named, tag)
mustNotFail(err)
return reference.FamiliarString(named)
}