mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-20 01:32:40 +00:00
added tap acceptance tests, fixed duplicate namespace problem (#244)
This commit is contained in:
@@ -561,7 +561,7 @@ func getNamespaces(kubernetesProvider *kubernetes.Provider) []string {
|
||||
if config.Config.Tap.AllNamespaces {
|
||||
return []string{mizu.K8sAllNamespaces}
|
||||
} else if len(config.Config.Tap.Namespaces) > 0 {
|
||||
return config.Config.Tap.Namespaces
|
||||
return mizu.Unique(config.Config.Tap.Namespaces)
|
||||
} else {
|
||||
return []string{kubernetesProvider.CurrentNamespace()}
|
||||
}
|
||||
|
@@ -9,3 +9,17 @@ func Contains(slice []string, containsValue string) bool {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func Unique(slice []string) []string {
|
||||
keys := make(map[string]bool)
|
||||
var list []string
|
||||
|
||||
for _, entry := range slice {
|
||||
if _, value := keys[entry]; !value {
|
||||
keys[entry] = true
|
||||
list = append(list, entry)
|
||||
}
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
|
@@ -1,7 +1,9 @@
|
||||
package mizu_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/up9inc/mizu/cli/mizu"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -88,3 +90,41 @@ func TestContainsNilSlice(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUniqueNoDuplicateValues(t *testing.T) {
|
||||
tests := []struct {
|
||||
Slice []string
|
||||
Expected []string
|
||||
}{
|
||||
{Slice: []string{"apple", "orange", "banana", "grapes"}, Expected: []string{"apple", "orange", "banana", "grapes"}},
|
||||
{Slice: []string{"dog", "cat", "mouse"}, Expected: []string{"dog", "cat", "mouse"}},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
t.Run(fmt.Sprintf("%v", index), func(t *testing.T) {
|
||||
actual := mizu.Unique(test.Slice)
|
||||
if !reflect.DeepEqual(test.Expected, actual) {
|
||||
t.Errorf("unexpected result - Expected: %v, actual: %v", test.Expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUniqueDuplicateValues(t *testing.T) {
|
||||
tests := []struct {
|
||||
Slice []string
|
||||
Expected []string
|
||||
}{
|
||||
{Slice: []string{"apple", "apple", "orange", "orange", "banana", "banana", "grapes", "grapes"}, Expected: []string{"apple", "orange", "banana", "grapes"}},
|
||||
{Slice: []string{"dog", "cat", "cat", "mouse"}, Expected: []string{"dog", "cat", "mouse"}},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
t.Run(fmt.Sprintf("%v", index), func(t *testing.T) {
|
||||
actual := mizu.Unique(test.Slice)
|
||||
if !reflect.DeepEqual(test.Expected, actual) {
|
||||
t.Errorf("unexpected result - Expected: %v, actual: %v", test.Expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user