mirror of
https://github.com/rancher/os.git
synced 2025-09-01 14:48:55 +00:00
Bump libcompose and its dependencies
This commit is contained in:
21
vendor/github.com/docker/libcompose/utils/util.go
generated
vendored
21
vendor/github.com/docker/libcompose/utils/util.go
generated
vendored
@@ -2,7 +2,6 @@ package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
@@ -17,7 +16,7 @@ type InParallel struct {
|
||||
pool sync.Pool
|
||||
}
|
||||
|
||||
// Add adds runs the specified task in parallel and add it to the waitGroup.
|
||||
// Add runs the specified task in parallel and adds it to the waitGroup.
|
||||
func (i *InParallel) Add(task func() error) {
|
||||
i.wg.Add(1)
|
||||
|
||||
@@ -30,7 +29,7 @@ func (i *InParallel) Add(task func() error) {
|
||||
}()
|
||||
}
|
||||
|
||||
// Wait waits for all tasks to complete and returns the latests error encountered if any.
|
||||
// Wait waits for all tasks to complete and returns the latest error encountered if any.
|
||||
func (i *InParallel) Wait() error {
|
||||
i.wg.Wait()
|
||||
obj := i.pool.Get()
|
||||
@@ -112,22 +111,6 @@ func FilterString(data map[string][]string) string {
|
||||
return string(bytes)
|
||||
}
|
||||
|
||||
// LabelFilterString returns a label json string representation of the specifed couple (key,value)
|
||||
// that is used as filter for docker.
|
||||
func LabelFilterString(key, value string) string {
|
||||
return FilterString(map[string][]string{
|
||||
"label": {fmt.Sprintf("%s=%s", key, value)},
|
||||
})
|
||||
}
|
||||
|
||||
// LabelFilter returns a label map representation of the specifed couple (key,value)
|
||||
// that is used as filter for docker.
|
||||
func LabelFilter(key, value string) map[string][]string {
|
||||
return map[string][]string{
|
||||
"label": {fmt.Sprintf("%s=%s", key, value)},
|
||||
}
|
||||
}
|
||||
|
||||
// Contains checks if the specified string (key) is present in the specified collection.
|
||||
func Contains(collection []string, key string) bool {
|
||||
for _, value := range collection {
|
||||
|
287
vendor/github.com/docker/libcompose/utils/util_test.go
generated
vendored
287
vendor/github.com/docker/libcompose/utils/util_test.go
generated
vendored
@@ -1,287 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type jsonfrom struct {
|
||||
Element1 string `json:"element2"`
|
||||
Element2 int `json:"element1"`
|
||||
}
|
||||
type jsonto struct {
|
||||
Elt1 int `json:"element1"`
|
||||
Elt2 string `json:"element2"`
|
||||
Elt3 int
|
||||
}
|
||||
|
||||
func TestInParallel(t *testing.T) {
|
||||
size := 5
|
||||
booleanMap := make(map[int]bool, size+1)
|
||||
tasks := InParallel{}
|
||||
for i := 0; i < size; i++ {
|
||||
task := func(index int) func() error {
|
||||
return func() error {
|
||||
booleanMap[index] = true
|
||||
return nil
|
||||
}
|
||||
}(i)
|
||||
tasks.Add(task)
|
||||
}
|
||||
err := tasks.Wait()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Make sure every value is true
|
||||
for _, value := range booleanMap {
|
||||
if !value {
|
||||
t.Fatalf("booleanMap expected to contain only true values, got at least one false")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInParallelError(t *testing.T) {
|
||||
size := 5
|
||||
booleanMap := make(map[int]bool, size+1)
|
||||
tasks := InParallel{}
|
||||
for i := 0; i < size; i++ {
|
||||
task := func(index int) func() error {
|
||||
return func() error {
|
||||
booleanMap[index] = true
|
||||
if index%2 == 0 {
|
||||
return fmt.Errorf("Error with %v", index)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}(i)
|
||||
tasks.Add(task)
|
||||
}
|
||||
err := tasks.Wait()
|
||||
if err == nil {
|
||||
t.Fatalf("Expected an error on Wait, got nothing.")
|
||||
}
|
||||
for key, value := range booleanMap {
|
||||
if key%2 != 0 && !value {
|
||||
t.Fatalf("booleanMap expected to contain true values on odd number, got %v", booleanMap)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertByJSON(t *testing.T) {
|
||||
valids := []struct {
|
||||
src jsonfrom
|
||||
expected jsonto
|
||||
}{
|
||||
{
|
||||
jsonfrom{Element2: 1},
|
||||
jsonto{1, "", 0},
|
||||
},
|
||||
{
|
||||
jsonfrom{},
|
||||
jsonto{0, "", 0},
|
||||
},
|
||||
{
|
||||
jsonfrom{"element1", 2},
|
||||
jsonto{2, "element1", 0},
|
||||
},
|
||||
}
|
||||
for _, valid := range valids {
|
||||
var target jsonto
|
||||
err := ConvertByJSON(valid.src, &target)
|
||||
if err != nil || target.Elt1 != valid.expected.Elt1 || target.Elt2 != valid.expected.Elt2 || target.Elt3 != 0 {
|
||||
t.Fatalf("Expected %v from %v got %v, %v", valid.expected, valid.src, target, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertByJSONInvalid(t *testing.T) {
|
||||
invalids := []interface{}{
|
||||
// Incompatible struct
|
||||
struct {
|
||||
Element1 int `json:"element2"`
|
||||
Element2 string `json:"element1"`
|
||||
}{1, "element1"},
|
||||
// Not marshable struct
|
||||
struct {
|
||||
Element1 func(int) int
|
||||
}{
|
||||
func(i int) int { return 0 },
|
||||
},
|
||||
}
|
||||
for _, invalid := range invalids {
|
||||
var target jsonto
|
||||
if err := ConvertByJSON(invalid, &target); err == nil {
|
||||
t.Fatalf("Expected an error converting %v to %v, got nothing", invalid, target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type yamlfrom struct {
|
||||
Element1 string `yaml:"element2"`
|
||||
Element2 int `yaml:"element1"`
|
||||
}
|
||||
type yamlto struct {
|
||||
Elt1 int `yaml:"element1"`
|
||||
Elt2 string `yaml:"element2"`
|
||||
Elt3 int
|
||||
}
|
||||
|
||||
func TestConvert(t *testing.T) {
|
||||
valids := []struct {
|
||||
src yamlfrom
|
||||
expected yamlto
|
||||
}{
|
||||
{
|
||||
yamlfrom{Element2: 1},
|
||||
yamlto{1, "", 0},
|
||||
},
|
||||
{
|
||||
yamlfrom{},
|
||||
yamlto{0, "", 0},
|
||||
},
|
||||
{
|
||||
yamlfrom{"element1", 2},
|
||||
yamlto{2, "element1", 0},
|
||||
},
|
||||
}
|
||||
for _, valid := range valids {
|
||||
var target yamlto
|
||||
err := Convert(valid.src, &target)
|
||||
if err != nil || target.Elt1 != valid.expected.Elt1 || target.Elt2 != valid.expected.Elt2 || target.Elt3 != 0 {
|
||||
t.Fatalf("Expected %v from %v got %v, %v", valid.expected, valid.src, target, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertInvalid(t *testing.T) {
|
||||
invalids := []interface{}{
|
||||
// Incompatible struct
|
||||
struct {
|
||||
Element1 int `yaml:"element2"`
|
||||
Element2 string `yaml:"element1"`
|
||||
}{1, "element1"},
|
||||
// Not marshable struct
|
||||
// This one panics :-|
|
||||
// struct {
|
||||
// Element1 func(int) int
|
||||
// }{
|
||||
// func(i int) int { return 0 },
|
||||
// },
|
||||
}
|
||||
for _, invalid := range invalids {
|
||||
var target yamlto
|
||||
if err := Convert(invalid, &target); err == nil {
|
||||
t.Fatalf("Expected an error converting %v to %v, got nothing", invalid, target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterStringSet(t *testing.T) {
|
||||
s := map[string]bool{"abcd": true, "b": true, "cde": true, "d": true, "ef": true}
|
||||
expected := map[string]bool{"abcd": true, "cde": true}
|
||||
result := FilterStringSet(s, func(x string) bool { return len(x) > 2 })
|
||||
assert.Equal(t, expected, result)
|
||||
}
|
||||
|
||||
func TestFilterString(t *testing.T) {
|
||||
datas := []struct {
|
||||
value map[string][]string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
map[string][]string{},
|
||||
"{}",
|
||||
},
|
||||
{
|
||||
map[string][]string{
|
||||
"key": {},
|
||||
},
|
||||
`{"key":[]}`,
|
||||
},
|
||||
{
|
||||
map[string][]string{
|
||||
"key": {"value1", "value2"},
|
||||
},
|
||||
`{"key":["value1","value2"]}`,
|
||||
},
|
||||
{
|
||||
map[string][]string{
|
||||
"key1": {"value1", "value2"},
|
||||
"key2": {"value3", "value4"},
|
||||
},
|
||||
`{"key1":["value1","value2"],"key2":["value3","value4"]}`,
|
||||
},
|
||||
}
|
||||
for _, data := range datas {
|
||||
actual := FilterString(data.value)
|
||||
if actual != data.expected {
|
||||
t.Fatalf("Expected '%v' for %v, got '%v'", data.expected, data.value, actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLabelFilter(t *testing.T) {
|
||||
filters := []struct {
|
||||
key string
|
||||
value string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
"key", "value", `{"label":["key=value"]}`,
|
||||
}, {
|
||||
"key", "", `{"label":["key="]}`,
|
||||
}, {
|
||||
"", "", `{"label":["="]}`,
|
||||
},
|
||||
}
|
||||
for _, filter := range filters {
|
||||
actual := LabelFilterString(filter.key, filter.value)
|
||||
if actual != filter.expected {
|
||||
t.Fatalf("Expected '%s for key=%s and value=%s, got %s", filter.expected, filter.key, filter.value, actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestContains(t *testing.T) {
|
||||
cases := []struct {
|
||||
collection []string
|
||||
key string
|
||||
contains bool
|
||||
}{
|
||||
{
|
||||
[]string{}, "", false,
|
||||
},
|
||||
{
|
||||
[]string{""}, "", true,
|
||||
},
|
||||
{
|
||||
[]string{"value1", "value2"}, "value3", false,
|
||||
},
|
||||
{
|
||||
[]string{"value1", "value2"}, "value1", true,
|
||||
},
|
||||
{
|
||||
[]string{"value1", "value2"}, "value2", true,
|
||||
},
|
||||
}
|
||||
for _, element := range cases {
|
||||
actual := Contains(element.collection, element.key)
|
||||
if actual != element.contains {
|
||||
t.Fatalf("Expected contains to be %v for %v in %v, but was %v", element.contains, element.key, element.collection, actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMerge(t *testing.T) {
|
||||
a := []string{"a", "b", "c"}
|
||||
b := []string{"b", "c", "d", "e"}
|
||||
expected := []string{"a", "b", "c", "d", "e"}
|
||||
r := Merge(a, b)
|
||||
assert.Equal(t, len(expected), len(r))
|
||||
for _, v := range expected {
|
||||
assert.True(t, Contains(r, v))
|
||||
}
|
||||
assert.Equal(t, "a:b", fmt.Sprint("a", ":", "b"))
|
||||
}
|
Reference in New Issue
Block a user