Create image reference cache.
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
@@ -41,3 +41,19 @@ func SubtractStringSlice(ss []string, str string) []string {
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// MergeStringSlices merges 2 string slices into one and remove duplicated elements.
|
||||
func MergeStringSlices(a []string, b []string) []string {
|
||||
set := map[string]struct{}{}
|
||||
for _, s := range a {
|
||||
set[s] = struct{}{}
|
||||
}
|
||||
for _, s := range b {
|
||||
set[s] = struct{}{}
|
||||
}
|
||||
var ss []string
|
||||
for s := range set {
|
||||
ss = append(ss, s)
|
||||
}
|
||||
return ss
|
||||
}
|
||||
|
||||
@@ -46,3 +46,14 @@ func TestSubtractStringSlice(t *testing.T) {
|
||||
assert.Empty(t, SubtractStringSlice(nil, "hij"))
|
||||
assert.Empty(t, SubtractStringSlice([]string{}, "hij"))
|
||||
}
|
||||
|
||||
func TestMergeStringSlices(t *testing.T) {
|
||||
s1 := []string{"abc", "def", "ghi"}
|
||||
s2 := []string{"def", "jkl", "mno"}
|
||||
expect := []string{"abc", "def", "ghi", "jkl", "mno"}
|
||||
result := MergeStringSlices(s1, s2)
|
||||
assert.Len(t, result, len(expect))
|
||||
for _, s := range expect {
|
||||
assert.Contains(t, result, s)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user