Skip to content

Commit

Permalink
chore: improve api file references (#62)
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly authored Oct 14, 2023
1 parent 9d01599 commit 275e69c
Show file tree
Hide file tree
Showing 18 changed files with 186 additions and 118 deletions.
10 changes: 6 additions & 4 deletions config/crds/chainsaw.kyverno.io_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,32 @@ spec:
properties:
apply:
items:
description: Apply represents a manifest to be applied.
properties:
file:
description: File containing the manifest to be applied.
description: File is the path to the referenced file.
type: string
required:
- file
type: object
type: array
assert:
items:
description: Error represents an assertion expected to succeed.
properties:
file:
description: File containing the assertion manifest.
description: File is the path to the referenced file.
type: string
required:
- file
type: object
type: array
error:
items:
description: Error represents an error condition.
properties:
file:
description: File containing the assertion manifest. It
is expected that the assertion fails.
description: File is the path to the referenced file.
type: string
required:
- file
Expand Down
10 changes: 6 additions & 4 deletions config/crds/chainsaw.kyverno.io_teststeps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,32 @@ spec:
properties:
apply:
items:
description: Apply represents a manifest to be applied.
properties:
file:
description: File containing the manifest to be applied.
description: File is the path to the referenced file.
type: string
required:
- file
type: object
type: array
assert:
items:
description: Error represents an assertion expected to succeed.
properties:
file:
description: File containing the assertion manifest.
description: File is the path to the referenced file.
type: string
required:
- file
type: object
type: array
error:
items:
description: Error represents an error condition.
properties:
file:
description: File containing the assertion manifest. It is expected
that the assertion fails.
description: File is the path to the referenced file.
type: string
required:
- file
Expand Down
5 changes: 3 additions & 2 deletions pkg/apis/v1alpha1/apply.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

// Apply represents a manifest to be applied.
type Apply struct {
// File containing the manifest to be applied.
File string `json:"file"`
// Manifest to be applied.
FileRef `json:",inline"`
}
5 changes: 3 additions & 2 deletions pkg/apis/v1alpha1/assert.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

// Error represents an assertion expected to succeed.
type Assert struct {
// File containing the assertion manifest.
File string `json:"file"`
// Assertion manifest.
FileRef `json:",inline"`
}
6 changes: 3 additions & 3 deletions pkg/apis/v1alpha1/error.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v1alpha1

// Error represents an error condition.
type Error struct {
// File containing the assertion manifest.
// It is expected that the assertion fails.
File string `json:"file"`
// Error manifest.
FileRef `json:",inline"`
}
7 changes: 7 additions & 0 deletions pkg/apis/v1alpha1/file_ref.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package v1alpha1

// FileRef represents a file reference.
type FileRef struct {
// File is the path to the referenced file.
File string `json:"file"`
}
19 changes: 19 additions & 0 deletions pkg/apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions pkg/data/crds/chainsaw.kyverno.io_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,32 @@ spec:
properties:
apply:
items:
description: Apply represents a manifest to be applied.
properties:
file:
description: File containing the manifest to be applied.
description: File is the path to the referenced file.
type: string
required:
- file
type: object
type: array
assert:
items:
description: Error represents an assertion expected to succeed.
properties:
file:
description: File containing the assertion manifest.
description: File is the path to the referenced file.
type: string
required:
- file
type: object
type: array
error:
items:
description: Error represents an error condition.
properties:
file:
description: File containing the assertion manifest. It
is expected that the assertion fails.
description: File is the path to the referenced file.
type: string
required:
- file
Expand Down
10 changes: 6 additions & 4 deletions pkg/data/crds/chainsaw.kyverno.io_teststeps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,32 @@ spec:
properties:
apply:
items:
description: Apply represents a manifest to be applied.
properties:
file:
description: File containing the manifest to be applied.
description: File is the path to the referenced file.
type: string
required:
- file
type: object
type: array
assert:
items:
description: Error represents an assertion expected to succeed.
properties:
file:
description: File containing the assertion manifest.
description: File is the path to the referenced file.
type: string
required:
- file
type: object
type: array
error:
items:
description: Error represents an error condition.
properties:
file:
description: File containing the assertion manifest. It is expected
that the assertion fails.
description: File is the path to the referenced file.
type: string
required:
- file
Expand Down
16 changes: 12 additions & 4 deletions pkg/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ func TestDiscoverTests(t *testing.T) {
want []Test
wantErr bool
}{{
name: "ok",
name: "quick start",
fileName: "chainsaw-test.yaml",
paths: []string{"../../testdata/tests"},
paths: []string{"../../testdata/tests/quick-start"},
want: []Test{{
BasePath: "../../testdata/tests",
BasePath: "../../testdata/tests/quick-start",
Test: &v1alpha1.Test{
TypeMeta: metav1.TypeMeta{
APIVersion: "chainsaw.kyverno.io/v1alpha1",
Expand All @@ -32,7 +32,15 @@ func TestDiscoverTests(t *testing.T) {
Spec: v1alpha1.TestSpec{
Steps: []v1alpha1.TestStepSpec{{
Apply: []v1alpha1.Apply{{
File: "configmap.yaml",
FileRef: v1alpha1.FileRef{
File: "configmap.yaml",
},
}},
}, {
Assert: []v1alpha1.Assert{{
FileRef: v1alpha1.FileRef{
File: "configmap.yaml",
},
}},
}},
},
Expand Down
36 changes: 18 additions & 18 deletions pkg/step/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ func TestLoad(t *testing.T) {
Name: "test-1",
},
Spec: v1alpha1.TestStepSpec{
Apply: []v1alpha1.Apply{
{
Apply: []v1alpha1.Apply{{
FileRef: v1alpha1.FileRef{
File: "foo.yaml",
},
},
Assert: []v1alpha1.Assert{
{
}},
Assert: []v1alpha1.Assert{{
FileRef: v1alpha1.FileRef{
File: "bar.yaml",
},
},
}},
},
},
},
Expand All @@ -82,16 +82,16 @@ func TestLoad(t *testing.T) {
Name: "test-1",
},
Spec: v1alpha1.TestStepSpec{
Apply: []v1alpha1.Apply{
{
Apply: []v1alpha1.Apply{{
FileRef: v1alpha1.FileRef{
File: "foo.yaml",
},
},
Assert: []v1alpha1.Assert{
{
}},
Assert: []v1alpha1.Assert{{
FileRef: v1alpha1.FileRef{
File: "bar.yaml",
},
},
}},
},
},
{
Expand All @@ -103,16 +103,16 @@ func TestLoad(t *testing.T) {
Name: "test-2",
},
Spec: v1alpha1.TestStepSpec{
Apply: []v1alpha1.Apply{
{
Apply: []v1alpha1.Apply{{
FileRef: v1alpha1.FileRef{
File: "bar.yaml",
},
},
Assert: []v1alpha1.Assert{
{
}},
Assert: []v1alpha1.Assert{{
FileRef: v1alpha1.FileRef{
File: "foo.yaml",
},
},
}},
},
},
},
Expand Down
8 changes: 6 additions & 2 deletions pkg/test/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ func TestLoad(t *testing.T) {
Spec: v1alpha1.TestSpec{
Steps: []v1alpha1.TestStepSpec{{
Apply: []v1alpha1.Apply{{
File: "foo.yaml",
FileRef: v1alpha1.FileRef{
File: "foo.yaml",
},
}},
}, {
Assert: []v1alpha1.Assert{{
File: "bar.yaml",
FileRef: v1alpha1.FileRef{
File: "bar.yaml",
},
}},
}},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ spec:
steps:
- apply:
- file: configmap.yaml
- assert:
- file: configmap.yaml
File renamed without changes.
2 changes: 1 addition & 1 deletion website/apis/markdown/members.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{{- $type := .GetType }}
{{- $inline := .IsInline }}
{{- $comment := .GetComment }}
| `{{ $name }}` | {{ template "typ" $type }} | {{ if not $optional }}:white_check_mark:{{ end }} | {{ template "comment" .CommentLines }} |
| `{{ $name }}` | {{ template "typ" $type }} | {{ if not $optional }}:white_check_mark:{{ end }} | {{ if $inline }}:white_check_mark:{{ end }} | {{ template "comment" .CommentLines }} |
{{- end }}
{{- end }}
{{- end }}
8 changes: 4 additions & 4 deletions website/apis/markdown/type.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
{{- end }}
{{- if .GetMembers }}

| Field | Type | Required | Description |
|---|---|---|---|
| Field | Type | Required | Inline | Description |
|---|---|---|---|---|
{{- /* . is a apiType */}}
{{- if .IsExported }}
{{- /* Add apiVersion and kind rows if deemed necessary */}}
| `apiVersion` | `string` | :white_check_mark: | `{{- .APIGroup -}}` |
| `kind` | `string` | :white_check_mark: | `{{- .Name.Name -}}` |
| `apiVersion` | `string` | :white_check_mark: | | `{{- .APIGroup -}}` |
| `kind` | `string` | :white_check_mark: | | `{{- .Name.Name -}}` |
{{- end }}
{{- /* The actual list of members is in the following template */}}
{{- template "members" . }}
Expand Down
Loading

0 comments on commit 275e69c

Please sign in to comment.