Skip to content

Commit c17423e

Browse files
committed
use ginkgo
Signed-off-by: sivchari <shibuuuu5@gmail.com>
1 parent 90cf8be commit c17423e

File tree

2 files changed

+63
-27
lines changed

2 files changed

+63
-27
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
*/
16+
package utils_test
17+
18+
import (
19+
"testing"
20+
21+
. "github.com/onsi/ginkgo/v2"
22+
. "github.com/onsi/gomega"
23+
)
24+
25+
func TestValidation(t *testing.T) {
26+
RegisterFailHandler(Fail)
27+
RunSpecs(t, "Utils")
28+
}

pkg/analysis/utils/utils_test.go

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
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+
*/
116
package utils_test
217

318
import (
419
"go/ast"
5-
"testing"
20+
21+
. "github.com/onsi/ginkgo/v2"
22+
. "github.com/onsi/gomega"
623

724
"sigs.k8s.io/kube-api-linter/pkg/analysis/utils"
825
)
926

10-
func TestFieldName(t *testing.T) {
11-
t.Parallel()
12-
13-
cases := map[string]struct {
27+
var _ = Describe("FieldName", func() {
28+
type fieldNameInput struct {
1429
field *ast.Field
1530
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{
1837
field: &ast.Field{
1938
Names: []*ast.Ident{
2039
{
@@ -23,16 +42,16 @@ func TestFieldName(t *testing.T) {
2342
},
2443
},
2544
want: "foo",
26-
},
27-
"filed has no Names, but is an Ident": {
45+
}),
46+
Entry("field has no Names, but is an Ident", fieldNameInput{
2847
field: &ast.Field{
2948
Type: &ast.Ident{
3049
Name: "foo",
3150
},
3251
},
3352
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{
3655
field: &ast.Field{
3756
Type: &ast.StarExpr{
3857
X: &ast.Ident{
@@ -41,8 +60,8 @@ func TestFieldName(t *testing.T) {
4160
},
4261
},
4362
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{
4665
field: &ast.Field{
4766
Type: &ast.ArrayType{
4867
Elt: &ast.Ident{
@@ -51,17 +70,6 @@ func TestFieldName(t *testing.T) {
5170
},
5271
},
5372
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

Comments
 (0)