github.com/googleapis/api-linter@v1.65.2/lint/rule_groups_test.go (about) 1 package lint 2 3 import ( 4 "testing" 5 ) 6 7 func TestAIPCoreGroup(t *testing.T) { 8 tests := []struct { 9 name string 10 aip int 11 group string 12 }{ 13 {"InCoreGroup", 1, "core"}, 14 {"NotInCoreGroup_AIP<=0", 0, ""}, 15 {"NotInCoreGroup_AIP>=1000", 1000, ""}, 16 } 17 for _, test := range tests { 18 t.Run(test.name, func(t *testing.T) { 19 if got := aipCoreGroup(test.aip); got != test.group { 20 t.Errorf("aipCoreGroup(%d) got %s, but want %s", test.aip, got, test.group) 21 } 22 }) 23 } 24 } 25 26 func TestAIPClientLibrariesGroup(t *testing.T) { 27 tests := []struct { 28 name string 29 aip int 30 group string 31 }{ 32 {"InClientLibrariesGroup", 4232, "client-libraries"}, 33 {"NotInClientLibrariesGroup_AIP>=4300", 4300, ""}, 34 {"NotInClientLibrariesGroup_AIP<4200", 4000, ""}, 35 } 36 for _, test := range tests { 37 t.Run(test.name, func(t *testing.T) { 38 if got := aipClientLibrariesGroup(test.aip); got != test.group { 39 t.Errorf("aipClientLibrariesGroup(%d) got %s, but want %s", test.aip, got, test.group) 40 } 41 }) 42 } 43 } 44 45 func TestGetRuleGroupPanic(t *testing.T) { 46 var groups []func(int) string 47 defer func() { 48 if r := recover(); r == nil { 49 t.Errorf("getRuleGroup did not panic") 50 } 51 }() 52 getRuleGroup(0, groups) 53 } 54 55 func TestGetRuleGroup(t *testing.T) { 56 groupOne := func(aip int) string { 57 if aip == 1 { 58 return "ONE" 59 } 60 return "" 61 } 62 groupTwo := func(aip int) string { 63 if aip == 2 { 64 return "TWO" 65 } 66 return "" 67 } 68 groups := []func(int) string{ 69 groupOne, 70 groupTwo, 71 } 72 73 tests := []struct { 74 name string 75 aip int 76 group string 77 }{ 78 {"GroupOne", 1, "ONE"}, 79 {"GroupTwo", 2, "TWO"}, 80 } 81 82 for _, test := range tests { 83 t.Run(test.name, func(t *testing.T) { 84 if got := getRuleGroup(test.aip, groups); got != test.group { 85 t.Errorf("getRuleGroup(%d) got %s, but want %s", test.aip, got, test.group) 86 } 87 }) 88 } 89 }