Skip to content

Commit a8fabd5

Browse files
committed
Test some more chart variants
1 parent 2b1e0b4 commit a8fabd5

11 files changed

Lines changed: 400 additions & 49 deletions

File tree

pkg/schemagen/schemagen_test.go

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package schemagen_test
22

33
import (
4-
"embed"
54
"io/fs"
65
"os"
7-
"path/filepath"
86
"strings"
97
"testing"
108

@@ -19,44 +17,45 @@ import (
1917
)
2018

2119
func TestGenerateCRD_Golden(t *testing.T) {
22-
chartLoader, err := loader.Loader("./testdata/charts/juiceshop-chart")
23-
if err != nil {
24-
t.Fatalf("Creating chart loader failed: %v", err)
25-
}
26-
chart, err := chartLoader.Load()
27-
if err != nil {
28-
t.Fatalf("Loading chart failed: %v", err)
20+
charts, err := fs.Glob(os.DirFS("testdata/charts"), "*/values.yaml")
21+
require.NoError(t, err)
22+
require.NotEmpty(t, charts, "No test charts found in testdata/charts")
23+
for i, chartPath := range charts {
24+
charts[i] = strings.TrimSuffix(chartPath, "/values.yaml")
2925
}
26+
t.Log("Found test charts:", charts)
3027

31-
crd, err := schemagen.GenerateCRD(*chart)
32-
if err != nil {
33-
t.Fatalf("GenerateCRD failed: %v", err)
34-
}
28+
for _, chartPath := range charts {
29+
t.Run(chartPath, func(t *testing.T) {
30+
chartLoader, err := loader.Loader("./testdata/charts/" + chartPath)
31+
require.NoError(t, err, "Creating chart loader failed for chart: %s", chartPath)
32+
chart, err := chartLoader.Load()
33+
require.NoError(t, err, "Loading chart failed for chart: %s", chartPath)
3534

36-
yamlData, err := kubeyaml.Marshal(crd)
37-
if err != nil {
38-
t.Fatalf("Failed to marshal CRD to YAML: %v", err)
39-
}
35+
crd, err := schemagen.GenerateCRD(*chart)
36+
require.NoError(t, err, "GenerateCRD failed for chart: %s", chartPath)
4037

41-
if err := os.WriteFile("testdata/charts/juiceshop-crd.yaml", yamlData, 0644); err != nil {
42-
t.Fatalf("Failed to write CRD to file: %v", err)
38+
yamlData, err := kubeyaml.Marshal(crd)
39+
require.NoError(t, err, "Failed to marshal CRD to YAML for chart: %s", chartPath)
40+
41+
require.NoError(t, os.WriteFile("./testdata/charts/"+chartPath+".golden.yaml", yamlData, 0644))
42+
})
4343
}
4444
}
4545

46-
//go:embed testdata/preprocess/*
47-
var preprocessTestFiles embed.FS
48-
4946
func Test_PreprocessYAMLHints(t *testing.T) {
50-
files, err := fs.Glob(preprocessTestFiles, "testdata/preprocess/*.processed.yaml")
47+
preprocessTestFiles := os.DirFS("testdata/preprocess")
48+
files, err := fs.Glob(preprocessTestFiles, "*.processed.yaml")
5149
require.NoError(t, err)
50+
require.NotEmpty(t, files, "No test files found in testdata/preprocess")
5251

5352
for _, processedFile := range files {
54-
t.Run(strings.TrimSuffix(filepath.Base(processedFile), ".processed.yaml"), func(t *testing.T) {
53+
t.Run(strings.TrimSuffix(processedFile, ".processed.yaml"), func(t *testing.T) {
5554
originalFile := strings.TrimSuffix(processedFile, ".processed.yaml") + ".yaml"
56-
originalData, err := preprocessTestFiles.ReadFile(originalFile)
55+
originalData, err := fs.ReadFile(preprocessTestFiles, originalFile)
5756
require.NoError(t, err)
5857

59-
expectedProcessedData, err := preprocessTestFiles.ReadFile(processedFile)
58+
expectedProcessedData, err := fs.ReadFile(preprocessTestFiles, processedFile)
6059
require.NoError(t, err)
6160

6261
actualProcessedData, err := schemagen.PreprocessYAMLHints(originalData)
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: empties.v3.juiceshop.bundles.appcat.io
5+
spec:
6+
group: v3.juiceshop.bundles.appcat.io
7+
names:
8+
categories:
9+
- all
10+
- claim
11+
- helmetica
12+
kind: Empty
13+
listKind: EmptyList
14+
plural: empties
15+
singular: empty
16+
scope: Namespaced
17+
versions:
18+
- additionalPrinterColumns:
19+
- jsonPath: .status.instanceNamespace
20+
name: Instance Namespace
21+
type: string
22+
- jsonPath: .status.releaseStatus
23+
name: Status
24+
type: string
25+
- jsonPath: .status.driftDetected
26+
name: Drift
27+
type: boolean
28+
- jsonPath: .metadata.creationTimestamp
29+
name: Age
30+
type: date
31+
name: bundle
32+
schema:
33+
openAPIV3Schema:
34+
properties:
35+
spec:
36+
description: Configures the desired state of the service.
37+
properties:
38+
approval:
39+
default:
40+
strategy: Automatic
41+
description: Approval contains the approval strategy for the service.
42+
properties:
43+
strategy:
44+
default: Automatic
45+
description: The approval strategy for the service. Can be either
46+
'Automatic' or 'Manual'.
47+
enum:
48+
- Automatic
49+
- Manual
50+
type: string
51+
type: object
52+
manages:
53+
description: The dependency group whose CRDs the operator of this
54+
service manages.
55+
items:
56+
properties:
57+
dependencyGroup:
58+
properties:
59+
as:
60+
description: Overrides the name the scope label is built
61+
from, so that a second deployment of the same operator
62+
can serve a separate set of consumers.
63+
type: string
64+
name:
65+
description: The name of the DependencyGroup.
66+
type: string
67+
required:
68+
- name
69+
type: object
70+
required:
71+
- dependencyGroup
72+
type: object
73+
type: array
74+
ociUrl:
75+
description: The OCI repository where the service bundle is stored.
76+
type: string
77+
provides:
78+
description: The list of dependency groups whose CRDs this service
79+
ships.
80+
items:
81+
properties:
82+
dependencyGroup:
83+
properties:
84+
as:
85+
description: Overrides the name the scope label is built
86+
from, so that a second deployment of the same operator
87+
can serve a separate set of consumers.
88+
type: string
89+
name:
90+
description: The name of the DependencyGroup.
91+
type: string
92+
required:
93+
- name
94+
type: object
95+
required:
96+
- dependencyGroup
97+
type: object
98+
type: array
99+
requires:
100+
description: The list of dependency groups that this service consumes.
101+
items:
102+
properties:
103+
dependencyGroup:
104+
properties:
105+
as:
106+
description: Overrides the name the scope label is built
107+
from, so that a second deployment of the same operator
108+
can serve a separate set of consumers.
109+
type: string
110+
name:
111+
description: The name of the DependencyGroup.
112+
type: string
113+
required:
114+
- name
115+
type: object
116+
required:
117+
- dependencyGroup
118+
type: object
119+
type: array
120+
values:
121+
description: This field together with the `.spec.version` field defines
122+
the configuration of the service. Every change to either of these
123+
two fields creates a new revision of the service.
124+
type: object
125+
version:
126+
description: The version of the service. Every change to this field
127+
together with the `.spec.values` field creates a new revision of
128+
the service.
129+
type: string
130+
type: object
131+
status:
132+
description: Status contains the observed state of the service.
133+
properties:
134+
appliedRevision:
135+
description: The name of the revision that is currently applied to
136+
the cluster.
137+
type: string
138+
driftDetected:
139+
description: Whether a drift was detected.
140+
type: boolean
141+
instanceNamespace:
142+
description: The namespace where the service is deployed in.
143+
type: string
144+
latestRevision:
145+
description: The name of the revision that currently matches the spec.
146+
type: string
147+
releaseStatus:
148+
description: The current status of the service.
149+
type: string
150+
type: object
151+
type: object
152+
served: true
153+
storage: true
154+
subresources:
155+
status: {}
156+
status:
157+
acceptedNames:
158+
kind: ""
159+
plural: ""
160+
conditions: null
161+
storedVersions: null
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apiVersion: v2
2+
name: juiceshop
3+
description: A Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 3.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "1.31.2"
25+
26+
annotations:
27+
crd.bundle.appcat.io/kind: "Empty"
28+
crd.bundle.appcat.io/listKind: "EmptyList"
29+
crd.bundle.appcat.io/singular: "empty"
30+
crd.bundle.appcat.io/plural: "empties"

pkg/schemagen/testdata/charts/empty/values.yaml

Whitespace-only changes.

0 commit comments

Comments
 (0)