File tree Expand file tree Collapse file tree 1 file changed +67
-0
lines changed Expand file tree Collapse file tree 1 file changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ package utils_test
2+
3+ import (
4+ "go/ast"
5+ "testing"
6+
7+ "sigs.k8s.io/kube-api-linter/pkg/analysis/utils"
8+ )
9+
10+ func TestFieldName (t * testing.T ) {
11+ t .Parallel ()
12+
13+ cases := map [string ]struct {
14+ field * ast.Field
15+ want string
16+ }{
17+ "field has Names" : {
18+ field : & ast.Field {
19+ Names : []* ast.Ident {
20+ {
21+ Name : "foo" ,
22+ },
23+ },
24+ },
25+ want : "foo" ,
26+ },
27+ "filed has no Names, but is an Ident" : {
28+ field : & ast.Field {
29+ Type : & ast.Ident {
30+ Name : "foo" ,
31+ },
32+ },
33+ want : "foo" ,
34+ },
35+ "field has no Names, but is a StarExpr with an Ident" : {
36+ field : & ast.Field {
37+ Type : & ast.StarExpr {
38+ X : & ast.Ident {
39+ Name : "foo" ,
40+ },
41+ },
42+ },
43+ want : "foo" ,
44+ },
45+ "field has no Names, and is not an Ident or StarExpr" : {
46+ field : & ast.Field {
47+ Type : & ast.ArrayType {
48+ Elt : & ast.Ident {
49+ Name : "foo" ,
50+ },
51+ },
52+ },
53+ want : "" ,
54+ },
55+ }
56+
57+ for name , tc := range cases {
58+ t .Run (name , func (t * testing.T ) {
59+ t .Parallel ()
60+
61+ got := utils .FieldName (tc .field )
62+ if got != tc .want {
63+ t .Errorf ("got %q, want %q" , got , tc .want )
64+ }
65+ })
66+ }
67+ }
You can’t perform that action at this time.
0 commit comments