github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/helper/fields/type_test.go (about) 1 package fields 2 3 import "testing" 4 5 func TestFieldTypeString(t *testing.T) { 6 if s := TypeString.String(); s != "string" { 7 t.Fatalf("bad: expected 'string' got: %s", s) 8 } 9 10 if s := TypeInt.String(); s != "integer" { 11 t.Fatalf("bad: expected 'integer' got: %s", s) 12 } 13 14 if s := TypeBool.String(); s != "boolean" { 15 t.Fatalf("bad: expected 'boolean' got: %s", s) 16 } 17 18 if s := TypeMap.String(); s != "map" { 19 t.Fatalf("bad: expected 'map' got: %v", s) 20 } 21 22 if s := TypeArray.String(); s != "array" { 23 t.Fatalf("bad: expected 'array' got: %v", s) 24 } 25 26 if s := TypeInvalid.String(); s != "unknown type" { 27 t.Fatalf("bad: expected 'unkown type' got: %v", s) 28 } 29 } 30 31 func TestFieldTypeZero(t *testing.T) { 32 if z := TypeString.Zero(); z != "" { 33 t.Fatalf("bad: expected \"\" got: %v", z) 34 } 35 36 if z := TypeInt.Zero(); z != 0 { 37 t.Fatalf("bad: expected 0 got: %v", z) 38 } 39 40 if z := TypeBool.Zero(); z != false { 41 t.Fatalf("bad: expected false got: %v", z) 42 } 43 44 z := TypeMap.Zero() 45 if _, ok := z.(map[string]interface{}); !ok { 46 t.Fatalf("bad: expected map[string]interface{} got: %v", z) 47 } 48 49 z = TypeArray.Zero() 50 if _, ok := z.([]interface{}); !ok { 51 t.Fatalf("bad: expected []interface{} got: %v", z) 52 } 53 54 defer func() { 55 if r := recover(); r == nil { 56 t.Errorf("The code did not panic") 57 } 58 }() 59 60 TypeInvalid.Zero() 61 }