Skip to content

Commit d1926f1

Browse files
committed
Separate testdata and add parsing test
Signed-off-by: jose.vazquez <[email protected]>
1 parent bb5f8d6 commit d1926f1

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
//
15+
16+
package crds_test
17+
18+
import (
19+
"bufio"
20+
"bytes"
21+
"testing"
22+
23+
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/autogen/translate/crds"
24+
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/autogen/translate/testdata"
25+
"github.com/stretchr/testify/assert"
26+
"github.com/stretchr/testify/require"
27+
)
28+
29+
func TestParse(t *testing.T) {
30+
scanner := bufio.NewScanner(bytes.NewBuffer(testdata.SampleCRDs))
31+
for _ = range 2 { // CRDs sample file has at least 2 CRDs
32+
def, err := crds.Parse(scanner)
33+
require.NoError(t, err)
34+
assert.NotNil(t, def)
35+
}
36+
}
File renamed without changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2025 Google LLC
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+
15+
package testdata
16+
17+
import _ "embed"
18+
19+
//go:embed crds.yaml
20+
var SampleCRDs []byte

internal/autogen/translate/translator_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package translate_test
1818
import (
1919
"bufio"
2020
"bytes"
21-
_ "embed"
2221
"fmt"
2322
"testing"
2423
"time"
@@ -34,6 +33,7 @@ import (
3433
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/autogen/translate"
3534
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/autogen/translate/crds"
3635
v1 "github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/autogen/translate/samples/v1"
36+
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/autogen/translate/testdata"
3737
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/pointer"
3838
"github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/k8s"
3939
)
@@ -46,9 +46,6 @@ const (
4646
testProjectID = "6098765432109876"
4747
)
4848

49-
//go:embed samples/crds.yaml
50-
var crdsYAMLBytes []byte
51-
5249
func TestFromAPI(t *testing.T) {
5350
for _, tc := range []struct {
5451
name string
@@ -716,7 +713,7 @@ func TestToAPIAllRefs(t *testing.T) {
716713
// },
717714
} {
718715
t.Run(tc.name, func(t *testing.T) {
719-
crdsYML := bytes.NewBuffer(crdsYAMLBytes)
716+
crdsYML := bytes.NewBuffer(testdata.SampleCRDs)
720717
crd, err := extractCRD(tc.crd, bufio.NewScanner(crdsYML))
721718
require.NoError(t, err)
722719
tr, err := translate.NewTranslator(crd, version, sdkVersion)
@@ -2159,7 +2156,7 @@ func TestToAPI(t *testing.T) {
21592156
}
21602157

21612158
func testToAPI[T any](t *testing.T, kind string, input client.Object, objs []client.Object, target, want *T) {
2162-
crdsYML := bytes.NewBuffer(crdsYAMLBytes)
2159+
crdsYML := bytes.NewBuffer(testdata.SampleCRDs)
21632160
crd, err := extractCRD(kind, bufio.NewScanner(crdsYML))
21642161
require.NoError(t, err)
21652162
tr, err := translate.NewTranslator(crd, version, sdkVersion)

0 commit comments

Comments
 (0)