2017-08-22 09:46:03 +00:00
|
|
|
package ecs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2017-10-31 14:53:11 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2017-08-22 09:46:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestClustersSet(t *testing.T) {
|
2017-09-06 10:10:05 +00:00
|
|
|
tests := []struct {
|
|
|
|
desc string
|
|
|
|
value string
|
|
|
|
expected Clusters
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "One value should return Clusters of size 1",
|
|
|
|
value: "cluster",
|
|
|
|
expected: Clusters{"cluster"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Two values separated by comma should return Clusters of size 2",
|
|
|
|
value: "cluster1,cluster2",
|
|
|
|
expected: Clusters{"cluster1", "cluster2"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Two values separated by semicolon should return Clusters of size 2",
|
|
|
|
value: "cluster1;cluster2",
|
|
|
|
expected: Clusters{"cluster1", "cluster2"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Three values separated by comma and semicolon should return Clusters of size 3",
|
|
|
|
value: "cluster1,cluster2;cluster3",
|
|
|
|
expected: Clusters{"cluster1", "cluster2", "cluster3"},
|
|
|
|
},
|
2017-08-22 09:46:03 +00:00
|
|
|
}
|
2017-09-06 10:10:05 +00:00
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
test := test
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
var clusters Clusters
|
|
|
|
err := clusters.Set(test.value)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, test.expected, clusters)
|
|
|
|
})
|
2017-08-22 09:46:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClustersGet(t *testing.T) {
|
2017-09-06 10:10:05 +00:00
|
|
|
tests := []struct {
|
|
|
|
desc string
|
|
|
|
clusters Clusters
|
|
|
|
expected Clusters
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "Should return 1 cluster",
|
|
|
|
clusters: Clusters{"cluster"},
|
|
|
|
expected: Clusters{"cluster"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Should return 2 clusters",
|
|
|
|
clusters: Clusters{"cluster1", "cluster2"},
|
|
|
|
expected: Clusters{"cluster1", "cluster2"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Should return 3 clusters",
|
|
|
|
clusters: Clusters{"cluster1", "cluster2", "cluster3"},
|
|
|
|
expected: Clusters{"cluster1", "cluster2", "cluster3"},
|
|
|
|
},
|
2017-08-22 09:46:03 +00:00
|
|
|
}
|
2017-09-06 10:10:05 +00:00
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
test := test
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
actual := test.clusters.Get()
|
|
|
|
assert.Equal(t, test.expected, actual)
|
|
|
|
})
|
2017-08-22 09:46:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClustersString(t *testing.T) {
|
2017-09-06 10:10:05 +00:00
|
|
|
tests := []struct {
|
|
|
|
desc string
|
|
|
|
clusters Clusters
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "Should return 1 cluster",
|
|
|
|
clusters: Clusters{"cluster"},
|
|
|
|
expected: "[cluster]",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Should return 2 clusters",
|
|
|
|
clusters: Clusters{"cluster1", "cluster2"},
|
|
|
|
expected: "[cluster1 cluster2]",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Should return 3 clusters",
|
|
|
|
clusters: Clusters{"cluster1", "cluster2", "cluster3"},
|
|
|
|
expected: "[cluster1 cluster2 cluster3]",
|
|
|
|
},
|
2017-08-22 09:46:03 +00:00
|
|
|
}
|
2017-09-06 10:10:05 +00:00
|
|
|
for _, test := range tests {
|
|
|
|
test := test
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
actual := test.clusters.String()
|
|
|
|
assert.Equal(t, test.expected, actual)
|
|
|
|
})
|
2017-08-22 09:46:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClustersSetValue(t *testing.T) {
|
2017-09-06 10:10:05 +00:00
|
|
|
tests := []struct {
|
|
|
|
desc string
|
|
|
|
clusters Clusters
|
|
|
|
expected Clusters
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "Should return Clusters of size 1",
|
|
|
|
clusters: Clusters{"cluster"},
|
|
|
|
expected: Clusters{"cluster"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Should return Clusters of size 2",
|
|
|
|
clusters: Clusters{"cluster1", "cluster2"},
|
|
|
|
expected: Clusters{"cluster1", "cluster2"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Should return Clusters of size 3",
|
|
|
|
clusters: Clusters{"cluster1", "cluster2", "cluster3"},
|
|
|
|
expected: Clusters{"cluster1", "cluster2", "cluster3"},
|
|
|
|
},
|
2017-08-22 09:46:03 +00:00
|
|
|
}
|
2017-09-06 10:10:05 +00:00
|
|
|
for _, test := range tests {
|
|
|
|
test := test
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
var slice Clusters
|
|
|
|
slice.SetValue(test.clusters)
|
|
|
|
assert.Equal(t, test.expected, slice)
|
|
|
|
})
|
2017-08-22 09:46:03 +00:00
|
|
|
}
|
|
|
|
}
|