Merged in feature/testingopts (pull request #129)
Testing Options and Clean Up * bitsandbobs * lint * healthchecks * imgintests * singlegenerate * testclean * network * networkclean * cmds
This commit is contained in:
+2
@@ -0,0 +1,2 @@
|
||||
// Package collections allows to interact with lists of things.
|
||||
package collections
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package collections
|
||||
|
||||
import "fmt"
|
||||
|
||||
// SliceValueNotFoundError is returned when a provided values file input is not found on the host path.
|
||||
type SliceValueNotFoundError struct {
|
||||
sourceString string
|
||||
}
|
||||
|
||||
func (err SliceValueNotFoundError) Error() string {
|
||||
return fmt.Sprintf("Could not resolve requested slice value from string %s", err.sourceString)
|
||||
}
|
||||
|
||||
// NewSliceValueNotFoundError creates a new slice found error
|
||||
func NewSliceValueNotFoundError(sourceString string) SliceValueNotFoundError {
|
||||
return SliceValueNotFoundError{sourceString}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package collections
|
||||
|
||||
// ListIntersection returns all the items in both list1 and list2. Note that this will dedup the items so that the
|
||||
// output is more predictable. Otherwise, the end list depends on which list was used as the base.
|
||||
func ListIntersection(list1 []string, list2 []string) []string {
|
||||
out := []string{}
|
||||
|
||||
// Only need to iterate list1, because we want items in both lists, not union.
|
||||
for _, item := range list1 {
|
||||
if ListContains(list2, item) && !ListContains(out, item) {
|
||||
out = append(out, item)
|
||||
}
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
// ListSubtract removes all the items in list2 from list1.
|
||||
func ListSubtract(list1 []string, list2 []string) []string {
|
||||
out := []string{}
|
||||
|
||||
for _, item := range list1 {
|
||||
if !ListContains(list2, item) {
|
||||
out = append(out, item)
|
||||
}
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
// ListContains returns true if the given list of strings (haystack) contains the given string (needle).
|
||||
func ListContains(haystack []string, needle string) bool {
|
||||
for _, str := range haystack {
|
||||
if needle == str {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package collections
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// GetSliceLastValueE will take a source string and returns the last value when split by the separator char.
|
||||
func GetSliceLastValueE(source string, separator string) (string, error) {
|
||||
if len(source) > 0 && len(separator) > 0 && strings.Contains(source, separator) {
|
||||
tmp := strings.Split(source, separator)
|
||||
return tmp[len(tmp)-1], nil
|
||||
}
|
||||
return "", NewSliceValueNotFoundError(source)
|
||||
}
|
||||
|
||||
// GetSliceIndexValueE will take a source string and returns the value at the given index when split by
|
||||
// the separator char.
|
||||
func GetSliceIndexValueE(source string, separator string, index int) (string, error) {
|
||||
if len(source) > 0 && len(separator) > 0 && strings.Contains(source, separator) && index >= 0 {
|
||||
tmp := strings.Split(source, separator)
|
||||
if index > len(tmp) {
|
||||
return "", NewSliceValueNotFoundError(source)
|
||||
}
|
||||
return tmp[index], nil
|
||||
}
|
||||
return "", NewSliceValueNotFoundError(source)
|
||||
}
|
||||
Reference in New Issue
Block a user