Skip to content

Commit

Permalink
Tests robustness
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
  • Loading branch information
simonferquel committed Apr 30, 2018
1 parent 29b4a14 commit ac5453c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cli/command/stack/kubernetes/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kubernetes

import (
"fmt"
"sort"
"strings"

"github.com/docker/cli/cli/command/formatter"
Expand All @@ -25,6 +26,8 @@ func generateValuedLabelsSelector(valuedLabels map[string][]string) []string {
if len(v) == 1 {
result = append(result, fmt.Sprintf("%s=%s", k, v[0]))
} else {
// make result more testable by sorting values
sort.Strings(v)
result = append(result, fmt.Sprintf("%s in (%s)", k, strings.Join(v, ",")))
}
}
Expand All @@ -50,6 +53,9 @@ func parseLabelFilters(rawFilters []string) ([]string, map[string][]string) {
func generateLabelSelector(f filters.Args, stackName string) string {
names := f.Get("name")

// make result more testable by sorting names
sort.Strings(names)

for _, n := range names {
if strings.HasPrefix(n, stackName+"_") {
// also accepts with unprefixed service name (for compat with existing swarm scripts where service names are prefixed by stack names)
Expand Down
11 changes: 11 additions & 0 deletions cli/command/stack/kubernetes/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ func TestSerficeFiltersLabelSelectorGen(t *testing.T) {
"label2=test2",
},
},
{
name: "name filter with stackName prefix",
stackName: "test",
filters: filters.NewArgs(
filters.KeyValuePair{Key: "name", Value: "test_svc1"},
),
expectedSelectorParts: []string{
"com.docker.stack.namespace=test",
"com.docker.service.name in (test_svc1,svc1)",
},
},
}

for _, c := range cases {
Expand Down

0 comments on commit ac5453c

Please sign in to comment.