-
Notifications
You must be signed in to change notification settings - Fork 30
Report an XRD schema Kubernetes would reject as non-structural #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ limitations under the License. | |
| package crd | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/google/go-cmp/cmp" | ||
|
|
@@ -33,6 +34,9 @@ var claimableXRDBytes []byte | |
| //go:embed testdata/unclaimable-xrd.yaml | ||
| var unclaimableXRDBytes []byte | ||
|
|
||
| //go:embed testdata/untyped-field-xrd.yaml | ||
| var untypedFieldXRDBytes []byte | ||
|
|
||
| func TestProcessXRD(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
|
|
@@ -44,6 +48,8 @@ func TestProcessXRD(t *testing.T) { | |
|
|
||
| expectedClaimKind string | ||
| expectedClaimListKind string | ||
|
|
||
| expectedErr string | ||
|
Comment on lines
+51
to
+52
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n -C 3 'cmpopts\.EquateErrors|cmp\.Diff\(.*err|TestProcessXRD' --glob '*.go'Repository: crossplane/cli Length of output: 152 🏁 Script executed: set -euo pipefail
printf '%s\n' '--- changed file and diff ---'
git diff -- internal/crd/generator_test.go
printf '%s\n' '--- imports and test body ---'
sed -n '1,130p' internal/crd/generator_test.go
printf '%s\n' '--- local error-comparison conventions ---'
rg -n -C 3 'cmpopts\.EquateErrors|cmp\.Diff|expectedErr|reason' internal/crd --glob '*_test.go' || trueRepository: crossplane/cli Length of output: 12766 🏁 Script executed: set -euo pipefail
printf '%s\n' '--- ProcessXRD implementation and error flow ---'
rg -n -C 8 'func ProcessXRD|ProcessXRD\(' internal/crd --glob '*.go'
printf '%s\n' '--- table-driven error-test conventions in nearby packages ---'
rg -n -C 6 'type .*struct|wantErr|expectedErr|reason|cmpopts\.EquateErrors|errors\.New' --glob '*_test.go' --glob '!internal/crd/generator_test.go' | head -240
printf '%s\n' '--- module dependency versions ---'
rg -n -C 2 'go-cmp|k8s.io/apimachinery|apiextensions-apiserver' go.mod go.sumRepository: crossplane/cli Length of output: 3216 🏁 Script executed: set -euo pipefail
printf '%s\n' '--- generator error path ---'
sed -n '1,180p' internal/crd/generator.go
printf '%s\n' '--- complete generator test ---'
sed -n '1,190p' internal/crd/generator_test.go
printf '%s\n' '--- repository-wide error comparison usage ---'
rg -n -C 5 'cmpopts\.EquateErrors|cmp\.Diff\(.*want.*err|wantErr|reason' --glob '*_test.go' . || trueRepository: crossplane/cli Length of output: 50371 🏁 Script executed: set -euo pipefail
printf '%s\n' '--- generator.go validation path ---'
sed -n '95,155p' internal/crd/generator.go
printf '%s\n' '--- shared error comparator ---'
rg -n -C 6 'func EquateErrors|EquateErrors' internal pkg --glob '*.go' --glob '!**/*_test.go' | head -100
printf '%s\n' '--- representative required test shape ---'
sed -n '20,125p' pkg/validate/unknown_fields_test.go
printf '%s\n' '--- generator test imports and relevant assertions ---'
sed -n '15,95p' internal/crd/generator_test.goRepository: crossplane/cli Length of output: 1343 🏁 Script executed: set -euo pipefail
printf '%s\n' '--- createCRDFromXRD validation path ---'
sed -n '1,95p' internal/crd/generator.go
printf '%s\n' '--- representative required test shape ---'
sed -n '20,125p' pkg/validate/unknown_fields_test.go
printf '%s\n' '--- error comparator declarations and imports ---'
rg -n -C 4 'EquateErrors' --glob '*.go' . | head -120 || trueRepository: crossplane/cli Length of output: 14768 Use the required table-test error contract.
🤖 Prompt for AI AgentsSource: Path instructions |
||
| }{ | ||
| "ClaimableXRD": { | ||
| xrdBytes: claimableXRDBytes, | ||
|
|
@@ -57,6 +63,10 @@ func TestProcessXRD(t *testing.T) { | |
| expectedXRKind: "XInternalBucket", | ||
| expectedXRListKind: "XInternalBucketList", | ||
| }, | ||
| "XRDWithAnUntypedField": { | ||
| xrdBytes: untypedFieldXRDBytes, | ||
| expectedErr: `properties[spec].properties[parameters].properties[acl].type: Required value: must not be empty for specified object fields`, | ||
| }, | ||
| } | ||
|
|
||
| for name, tc := range tcs { | ||
|
|
@@ -65,6 +75,15 @@ func TestProcessXRD(t *testing.T) { | |
|
|
||
| outFS := afero.NewMemMapFs() | ||
| xrPath, claimPath, err := ProcessXRD(outFS, tc.xrdBytes, "output", "/") | ||
| if tc.expectedErr != "" { | ||
| if err == nil { | ||
| t.Fatalf("expected an error mentioning %q, got none", tc.expectedErr) | ||
| } | ||
| if !strings.Contains(err.Error(), tc.expectedErr) { | ||
| t.Fatalf("expected the error to mention %q, got: %v", tc.expectedErr, err) | ||
| } | ||
| return | ||
| } | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| apiVersion: apiextensions.crossplane.io/v1 | ||
| kind: CompositeResourceDefinition | ||
| metadata: | ||
| name: xuntypedbuckets.platform.example.com | ||
| spec: | ||
| group: platform.example.com | ||
| names: | ||
| categories: | ||
| - crossplane | ||
| kind: XUntypedBucket | ||
| plural: xuntypedbuckets | ||
| versions: | ||
| - name: v1alpha1 | ||
| referenceable: true | ||
| schema: | ||
| openAPIV3Schema: | ||
| description: UntypedBucket is the Schema for the UntypedBucket API. | ||
| properties: | ||
| spec: | ||
| description: UntypedBucketSpec defines the desired state of UntypedBucket. | ||
| properties: | ||
| parameters: | ||
| properties: | ||
| acl: | ||
| description: This property has no type, which is not structural. | ||
| type: object | ||
| type: object | ||
| status: | ||
| description: UntypedBucketStatus defines the observed state of UntypedBucket. | ||
| type: object | ||
| type: object | ||
| served: true |
Uh oh!
There was an error while loading. Please reload this page.