1
+ /*
2
+ Copyright 2025 The Kubernetes Authors.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
1
16
package utils_test
2
17
3
18
import (
4
19
"go/ast"
5
- "testing"
20
+
21
+ . "github.com/onsi/ginkgo/v2"
22
+ . "github.com/onsi/gomega"
6
23
7
24
"sigs.k8s.io/kube-api-linter/pkg/analysis/utils"
8
25
)
9
26
10
- func TestFieldName (t * testing.T ) {
11
- t .Parallel ()
12
-
13
- cases := map [string ]struct {
27
+ var _ = Describe ("FieldName" , func () {
28
+ type fieldNameInput struct {
14
29
field * ast.Field
15
30
want string
16
- }{
17
- "field has Names" : {
31
+ }
32
+
33
+ DescribeTable ("Should extract the field name" , func (in fieldNameInput ) {
34
+ Expect (utils .FieldName (in .field )).To (Equal (in .want ), "expect to match the extracted field name" )
35
+ },
36
+ Entry ("field has Names" , fieldNameInput {
18
37
field : & ast.Field {
19
38
Names : []* ast.Ident {
20
39
{
@@ -23,16 +42,16 @@ func TestFieldName(t *testing.T) {
23
42
},
24
43
},
25
44
want : "foo" ,
26
- },
27
- "filed has no Names, but is an Ident": {
45
+ }) ,
46
+ Entry ( "field has no Names, but is an Ident", fieldNameInput {
28
47
field : & ast.Field {
29
48
Type : & ast.Ident {
30
49
Name : "foo" ,
31
50
},
32
51
},
33
52
want : "foo" ,
34
- },
35
- "field has no Names, but is a StarExpr with an Ident" : {
53
+ }) ,
54
+ Entry ( "field has no Names, but is a StarExpr with an Ident" , fieldNameInput {
36
55
field : & ast.Field {
37
56
Type : & ast.StarExpr {
38
57
X : & ast.Ident {
@@ -41,8 +60,8 @@ func TestFieldName(t *testing.T) {
41
60
},
42
61
},
43
62
want : "foo" ,
44
- },
45
- "field has no Names, and is not an Ident or StarExpr" : {
63
+ }) ,
64
+ Entry ( "field has no Names, and is not an Ident or StarExpr" , fieldNameInput {
46
65
field : & ast.Field {
47
66
Type : & ast.ArrayType {
48
67
Elt : & ast.Ident {
@@ -51,17 +70,6 @@ func TestFieldName(t *testing.T) {
51
70
},
52
71
},
53
72
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
- }
73
+ }),
74
+ )
75
+ })
0 commit comments