-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for several ECS backends
- Loading branch information
Showing
7 changed files
with
252 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ecs | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// Clusters holds ecs clusters name | ||
type Clusters []string | ||
|
||
// Set adds strings elem into the the parser | ||
// it splits str on , and ; | ||
func (c *Clusters) Set(str string) error { | ||
fargs := func(c rune) bool { | ||
return c == ',' || c == ';' | ||
} | ||
// get function | ||
slice := strings.FieldsFunc(str, fargs) | ||
*c = append(*c, slice...) | ||
return nil | ||
} | ||
|
||
// Get Clusters | ||
func (c *Clusters) Get() interface{} { return Clusters(*c) } | ||
|
||
// String return slice in a string | ||
func (c *Clusters) String() string { return fmt.Sprintf("%v", *c) } | ||
|
||
// SetValue sets Clusters into the parser | ||
func (c *Clusters) SetValue(val interface{}) { | ||
*c = Clusters(val.(Clusters)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package ecs | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestClustersSet(t *testing.T) { | ||
checkMap := map[string]Clusters{ | ||
"cluster": {"cluster"}, | ||
"cluster1,cluster2": {"cluster1", "cluster2"}, | ||
"cluster1;cluster2": {"cluster1", "cluster2"}, | ||
"cluster1,cluster2;cluster3": {"cluster1", "cluster2", "cluster3"}, | ||
} | ||
for str, check := range checkMap { | ||
var clusters Clusters | ||
if err := clusters.Set(str); err != nil { | ||
t.Fatalf("Error :%s", err) | ||
} | ||
if !reflect.DeepEqual(clusters, check) { | ||
t.Fatalf("Expected:%s\ngot:%s", check, clusters) | ||
} | ||
} | ||
} | ||
|
||
func TestClustersGet(t *testing.T) { | ||
slices := []Clusters{ | ||
{"cluster"}, | ||
{"cluster1", "cluster2"}, | ||
{"cluster1", "cluster2", "cluster3"}, | ||
} | ||
check := []Clusters{ | ||
{"cluster"}, | ||
{"cluster1", "cluster2"}, | ||
{"cluster1", "cluster2", "cluster3"}, | ||
} | ||
for i, slice := range slices { | ||
if !reflect.DeepEqual(slice.Get(), check[i]) { | ||
t.Fatalf("Expected:%s\ngot:%s", check[i], slice) | ||
} | ||
} | ||
} | ||
|
||
func TestClustersString(t *testing.T) { | ||
slices := []Clusters{ | ||
{"cluster"}, | ||
{"cluster1", "cluster2"}, | ||
{"cluster1", "cluster2", "cluster3"}, | ||
} | ||
check := []string{ | ||
"[cluster]", | ||
"[cluster1 cluster2]", | ||
"[cluster1 cluster2 cluster3]", | ||
} | ||
for i, slice := range slices { | ||
if !reflect.DeepEqual(slice.String(), check[i]) { | ||
t.Fatalf("Expected:%s\ngot:%s", check[i], slice) | ||
} | ||
} | ||
} | ||
|
||
func TestClustersSetValue(t *testing.T) { | ||
check := []Clusters{ | ||
{"cluster"}, | ||
{"cluster1", "cluster2"}, | ||
{"cluster1", "cluster2", "cluster3"}, | ||
} | ||
slices := []Clusters{ | ||
{"cluster"}, | ||
{"cluster1", "cluster2"}, | ||
{"cluster1", "cluster2", "cluster3"}, | ||
} | ||
for i, s := range slices { | ||
var slice Clusters | ||
slice.SetValue(s) | ||
if !reflect.DeepEqual(slice, check[i]) { | ||
t.Fatalf("Expected:%s\ngot:%s", check[i], slice) | ||
} | ||
} | ||
} |
Oops, something went wrong.