github.com/phobos182/packer@v0.2.3-0.20130819023704-c84d2aeffc68/common/command/flag_slice_value_test.go (about) 1 package command 2 3 import ( 4 "flag" 5 "reflect" 6 "testing" 7 ) 8 9 func TestAppendSliceValue_implements(t *testing.T) { 10 var raw interface{} 11 raw = new(AppendSliceValue) 12 if _, ok := raw.(flag.Value); !ok { 13 t.Fatalf("AppendSliceValue should be a Value") 14 } 15 } 16 17 func TestAppendSliceValueSet(t *testing.T) { 18 sv := new(AppendSliceValue) 19 err := sv.Set("foo") 20 if err != nil { 21 t.Fatalf("err: %s", err) 22 } 23 24 err = sv.Set("bar") 25 if err != nil { 26 t.Fatalf("err: %s", err) 27 } 28 29 expected := []string{"foo", "bar"} 30 if !reflect.DeepEqual([]string(*sv), expected) { 31 t.Fatalf("Bad: %#v", sv) 32 } 33 } 34 35 func TestSliceValue_implements(t *testing.T) { 36 var raw interface{} 37 raw = new(SliceValue) 38 if _, ok := raw.(flag.Value); !ok { 39 t.Fatalf("SliceValue should be a Value") 40 } 41 } 42 43 func TestSliceValueSet(t *testing.T) { 44 sv := new(SliceValue) 45 err := sv.Set("foo,bar,baz") 46 if err != nil { 47 t.Fatalf("err: %s", err) 48 } 49 50 expected := []string{"foo", "bar", "baz"} 51 if !reflect.DeepEqual([]string(*sv), expected) { 52 t.Fatalf("Bad: %#v", sv) 53 } 54 }