mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
34 lines
588 B
Go
34 lines
588 B
Go
package flagutil
|
|
|
|
import (
|
|
"flag"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
var fooFlag Array
|
|
|
|
func init() {
|
|
os.Args = append(os.Args, "--fooFlag=foo", "--fooFlag=bar")
|
|
flag.Var(&fooFlag, "fooFlag", "test")
|
|
}
|
|
|
|
func TestMain(m *testing.M) {
|
|
flag.Parse()
|
|
os.Exit(m.Run())
|
|
}
|
|
|
|
func TestArray(t *testing.T) {
|
|
expected := map[string]struct{}{
|
|
"foo": {},
|
|
"bar": {},
|
|
}
|
|
if len(expected) != len(fooFlag) {
|
|
t.Errorf("len array flag (%d) is not equal to %d", len(fooFlag), len(expected))
|
|
}
|
|
for _, i := range fooFlag {
|
|
if _, ok := expected[i]; !ok {
|
|
t.Errorf("unexpected item in array %v", i)
|
|
}
|
|
}
|
|
}
|