github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/builtin/providers/gitlab/util_test.go (about) 1 package gitlab 2 3 import ( 4 "testing" 5 6 "github.com/xanzy/go-gitlab" 7 ) 8 9 func TestGitlab_validation(t *testing.T) { 10 cases := []struct { 11 Value string 12 ErrCount int 13 }{ 14 { 15 Value: "invalid", 16 ErrCount: 1, 17 }, 18 { 19 Value: "valid_one", 20 ErrCount: 0, 21 }, 22 { 23 Value: "valid_two", 24 ErrCount: 0, 25 }, 26 } 27 28 validationFunc := validateValueFunc([]string{"valid_one", "valid_two"}) 29 30 for _, tc := range cases { 31 _, errors := validationFunc(tc.Value, "test_arg") 32 33 if len(errors) != tc.ErrCount { 34 t.Fatalf("Expected 1 validation error") 35 } 36 } 37 } 38 39 func TestGitlab_visbilityHelpers(t *testing.T) { 40 cases := []struct { 41 String string 42 Level gitlab.VisibilityLevelValue 43 }{ 44 { 45 String: "private", 46 Level: gitlab.PrivateVisibility, 47 }, 48 { 49 String: "public", 50 Level: gitlab.PublicVisibility, 51 }, 52 } 53 54 for _, tc := range cases { 55 level := stringToVisibilityLevel(tc.String) 56 if level == nil || *level != tc.Level { 57 t.Fatalf("got %v expected %v", level, tc.Level) 58 } 59 60 sv := visibilityLevelToString(tc.Level) 61 if sv == nil || *sv != tc.String { 62 t.Fatalf("got %v expected %v", sv, tc.String) 63 } 64 } 65 }