Skip to content

Commit 039f0c6

Browse files
s-urbaniakjosvazg
authored andcommitted
fix unit test
Signed-off-by: jose.vazquez <[email protected]>
1 parent 2428df9 commit 039f0c6

File tree

4 files changed

+52
-11
lines changed

4 files changed

+52
-11
lines changed

internal/generated/crds/crds.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1+
// Copyright 2025 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package crds
216

317
import (
418
"bufio"
519
"bytes"
6-
"fmt"
7-
820
_ "embed"
21+
"fmt"
922

1023
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1124
)

internal/generated/crds/crds.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2025 MongoDB Inc
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
# The file is generated by openapi2crd
216
---
317
apiVersion: apiextensions.k8s.io/v1

internal/generated/crds/parse.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2025 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package crds
216

317
import (

internal/generated/crds/parse_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ package crds
1717

1818
import (
1919
"bufio"
20-
"fmt"
21-
"io"
2220
"strings"
2321
"testing"
2422

@@ -28,28 +26,26 @@ import (
2826
)
2927

3028
func TestParseCRD(t *testing.T) {
31-
var noErr error
32-
3329
tests := map[string]struct {
3430
scanner *bufio.Scanner
3531
expectedCrd *apiextensionsv1.CustomResourceDefinition
36-
expectedErr error
32+
expectedErr string
3733
}{
3834
"valid CRD": {
3935
scanner: bufio.NewScanner(strings.NewReader(validCRDManifest(t))),
4036
expectedCrd: validCRDObject(t),
4137
},
4238
"not a CRD": {
4339
scanner: bufio.NewScanner(strings.NewReader("apiVersion: autoscaling/__internal\nkind: Scale\nmetadata:\n name: test-scale\n")),
44-
expectedErr: fmt.Errorf("unexpected kind %q: %w", "Scale", noErr),
40+
expectedErr: "failed to decode YAML: no kind \"Scale\" is registered for the internal version of group \"autoscaling\" in scheme \"pkg/runtime/scheme.go:110\"",
4541
},
4642
"empty input": {
4743
scanner: bufio.NewScanner(strings.NewReader("")),
48-
expectedErr: io.EOF,
44+
expectedErr: "EOF",
4945
},
5046
"only comments": {
5147
scanner: bufio.NewScanner(strings.NewReader("# This is a comment\n# Another comment line\n")),
52-
expectedErr: io.EOF,
48+
expectedErr: "EOF",
5349
},
5450
"multiple CRDs, returns first": {
5551
scanner: bufio.NewScanner(strings.NewReader(validCRDManifest(t) + "---\n" + validCRDManifest(t))),
@@ -59,7 +55,11 @@ func TestParseCRD(t *testing.T) {
5955
for name, tt := range tests {
6056
t.Run(name, func(t *testing.T) {
6157
got, err := ParseCRD(tt.scanner)
62-
assert.Equal(t, tt.expectedErr, err)
58+
gotErr := ""
59+
if err != nil {
60+
gotErr = err.Error()
61+
}
62+
assert.Equal(t, tt.expectedErr, gotErr)
6363
assert.Equal(t, tt.expectedCrd, got)
6464
})
6565
}

0 commit comments

Comments
 (0)