mirror of
https://github.com/weaveworks/scope.git
synced 2026-05-06 01:08:03 +00:00
Upgraded from 99c19923, branch release-3.0. This required fetching or upgrading the following: * k8s.io/api to kubernetes-1.9.1 * k8s.io/apimachinery to kubernetes-1.9.1 * github.com/juju/ratelimit to 1.0.1 * github.com/spf13/pflag to 4c012f6d Also, update Scope's imports/function calls to be compatible with the new client.
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package pflag
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func setUpCount(c *int) *FlagSet {
|
|
f := NewFlagSet("test", ContinueOnError)
|
|
f.CountVarP(c, "verbose", "v", "a counter")
|
|
return f
|
|
}
|
|
|
|
func TestCount(t *testing.T) {
|
|
testCases := []struct {
|
|
input []string
|
|
success bool
|
|
expected int
|
|
}{
|
|
{[]string{}, true, 0},
|
|
{[]string{"-v"}, true, 1},
|
|
{[]string{"-vvv"}, true, 3},
|
|
{[]string{"-v", "-v", "-v"}, true, 3},
|
|
{[]string{"-v", "--verbose", "-v"}, true, 3},
|
|
{[]string{"-v=3", "-v"}, true, 4},
|
|
{[]string{"--verbose=0"}, true, 0},
|
|
{[]string{"-v=0"}, true, 0},
|
|
{[]string{"-v=a"}, false, 0},
|
|
}
|
|
|
|
devnull, _ := os.Open(os.DevNull)
|
|
os.Stderr = devnull
|
|
for i := range testCases {
|
|
var count int
|
|
f := setUpCount(&count)
|
|
|
|
tc := &testCases[i]
|
|
|
|
err := f.Parse(tc.input)
|
|
if err != nil && tc.success == true {
|
|
t.Errorf("expected success, got %q", err)
|
|
continue
|
|
} else if err == nil && tc.success == false {
|
|
t.Errorf("expected failure, got success")
|
|
continue
|
|
} else if tc.success {
|
|
c, err := f.GetCount("verbose")
|
|
if err != nil {
|
|
t.Errorf("Got error trying to fetch the counter flag")
|
|
}
|
|
if c != tc.expected {
|
|
t.Errorf("expected %d, got %d", tc.expected, c)
|
|
}
|
|
}
|
|
}
|
|
}
|