terraform/command/flag_var_test.go

57 lines
781 B
Go
Raw Normal View History

2014-07-18 20:37:27 +02:00
package command
import (
"flag"
"reflect"
"testing"
)
func TestFlagVar_impl(t *testing.T) {
var _ flag.Value = new(FlagVar)
}
func TestFlagVar(t *testing.T) {
cases := []struct {
Input string
Output map[string]string
Error bool
}{
{
"key=value",
map[string]string{"key": "value"},
false,
},
{
"key=",
map[string]string{"key": ""},
false,
},
{
"key=foo=bar",
map[string]string{"key": "foo=bar"},
false,
},
{
"key",
nil,
true,
},
}
for _, tc := range cases {
f := new(FlagVar)
err := f.Set(tc.Input)
if (err != nil) != tc.Error {
t.Fatalf("bad error. Input: %#v", tc.Input)
}
actual := map[string]string(*f)
if !reflect.DeepEqual(actual, tc.Output) {
t.Fatalf("bad: %#v", actual)
}
}
}