Skip to content

Commit

Permalink
refactor: remove test dirs from config (#612)
Browse files Browse the repository at this point in the history
* refactor: remove test dirs from config

Signed-off-by: Charles-Edouard Brétéché <[email protected]>

* fix

Signed-off-by: Charles-Edouard Brétéché <[email protected]>

---------

Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly authored Dec 7, 2023
1 parent 81a719b commit 1ecb519
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 65 deletions.
5 changes: 0 additions & 5 deletions .crds/chainsaw.kyverno.io_configurations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ spec:
description: If set, do not delete the resources after running the
tests (implies SkipClusterDelete).
type: boolean
testDirs:
description: Directories containing test cases to run.
items:
type: string
type: array
testFile:
default: chainsaw-test.yaml
description: TestFile is the name of the file containing the test
Expand Down
13 changes: 0 additions & 13 deletions .schemas/json/configuration-chainsaw-v1alpha1.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,19 +368,6 @@
"null"
]
},
"testDirs": {
"description": "Directories containing test cases to run.",
"type": [
"array",
"null"
],
"items": {
"type": [
"string",
"null"
]
}
},
"testFile": {
"description": "TestFile is the name of the file containing the test to run.",
"type": [
Expand Down
26 changes: 13 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,8 @@ codegen-mkdocs: codegen-cli-docs codegen-api-docs codegen-jp-docs ## Generate mk
@$(PIP) install -U mkdocs-material mkdocs-redirects mkdocs-minify-plugin mkdocs-include-markdown-plugin lunr mkdocs-rss-plugin mike
@mkdocs build -f ./website/mkdocs.yaml

.PHONY: codegen
codegen: codegen-crds codegen-deepcopy codegen-register codegen-mkdocs codegen-cli-docs codegen-api-docs ## Rebuild all generated code and docs

.PHONY: verify-codegen
verify-codegen: codegen ## Verify all generated code and docs are up to date
@echo Checking codegen is up to date... >&2
@git --no-pager diff -- .
@echo 'If this test fails, it is because the git diff is non-empty after running "make codegen".' >&2
@echo 'To correct this, locally run "make codegen", commit the changes, and re-run tests.' >&2
@git diff --quiet --exit-code -- .

.PHONY: codegen-schemas-openapi
codegen-schemas-openapi: $(KIND) $(HELM) ## Generate openapi schemas (v2 and v3)
codegen-schemas-openapi: codegen-crds $(KIND) ## Generate openapi schemas (v2 and v3)
@echo Generate openapi schema... >&2
@rm -rf ./.temp/.schemas
@mkdir -p ./.temp/.schemas/openapi/v2
Expand All @@ -147,7 +136,7 @@ codegen-schemas-openapi: $(KIND) $(HELM) ## Generate openapi schemas (v2 and v3)
@$(KIND) delete cluster --name schema

.PHONY: codegen-schemas-json
codegen-schemas-json: #codegen-schemas-openapi ## Generate json schemas
codegen-schemas-json: codegen-schemas-openapi ## Generate json schemas
@$(PIP) install openapi2jsonschema
@rm -rf ./.temp/.schemas/json
@rm -rf ./.schemas/json
Expand All @@ -156,6 +145,17 @@ codegen-schemas-json: #codegen-schemas-openapi ## Generate json schemas
@cp ./.temp/.schemas/json/test-chainsaw-*.json ./.schemas/json
@cp ./.temp/.schemas/json/configuration-chainsaw-*.json ./.schemas/json

.PHONY: codegen
codegen: codegen-crds codegen-deepcopy codegen-register codegen-mkdocs codegen-cli-docs codegen-api-docs codegen-schemas-json ## Rebuild all generated code and docs

.PHONY: verify-codegen
verify-codegen: codegen ## Verify all generated code and docs are up to date
@echo Checking codegen is up to date... >&2
@git --no-pager diff -- .
@echo 'If this test fails, it is because the git diff is non-empty after running "make codegen".' >&2
@echo 'To correct this, locally run "make codegen", commit the changes, and re-run tests.' >&2
@git diff --quiet --exit-code -- .

##########
# MKDOCS #
##########
Expand Down
4 changes: 0 additions & 4 deletions pkg/apis/v1alpha1/configuration_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ type ConfigurationSpec struct {
// +optional
Timeouts Timeouts `json:"timeouts"`

// Directories containing test cases to run.
// +optional
TestDirs []string `json:"testDirs,omitempty"`

// If set, do not delete the resources after running the tests (implies SkipClusterDelete).
// +optional
SkipDelete bool `json:"skipDelete,omitempty"`
Expand Down
5 changes: 0 additions & 5 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.

1 change: 0 additions & 1 deletion pkg/commands/migrate/kuttl/config/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ func testSuite(in unstructured.Unstructured) (*v1alpha1.Configuration, error) {
ObjectMeta: from.ObjectMeta,
Spec: v1alpha1.ConfigurationSpec{
Timeouts: timeouts,
TestDirs: from.TestDirs,
SkipDelete: from.SkipDelete,
ReportFormat: v1alpha1.ReportFormatType(from.ReportFormat),
ReportName: from.ReportName,
Expand Down
15 changes: 6 additions & 9 deletions pkg/commands/test/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ func Command() *cobra.Command {
if flagutils.IsSet(flags, "exec-timeout") {
configuration.Spec.Timeouts.Exec = &options.execTimeout
}
if flagutils.IsSet(flags, "test-dir") {
configuration.Spec.TestDirs = options.testDirs
}
if flagutils.IsSet(flags, "skip-delete") {
configuration.Spec.SkipDelete = options.skipDelete
}
Expand Down Expand Up @@ -149,8 +146,11 @@ func Command() *cobra.Command {
if flagutils.IsSet(flags, "cleanup-delay") {
configuration.Spec.DelayBeforeCleanup = &options.delayBeforeCleanup
}
if len(options.testDirs) == 0 {
options.testDirs = append(options.testDirs, ".")
}
fmt.Fprintf(out, "- Using test file: %s\n", configuration.Spec.TestFile)
fmt.Fprintf(out, "- TestDirs %v\n", configuration.Spec.TestDirs)
fmt.Fprintf(out, "- TestDirs %v\n", options.testDirs)
fmt.Fprintf(out, "- SkipDelete %v\n", configuration.Spec.SkipDelete)
fmt.Fprintf(out, "- FailFast %v\n", configuration.Spec.FailFast)
fmt.Fprintf(out, "- ReportFormat '%v'\n", configuration.Spec.ReportFormat)
Expand Down Expand Up @@ -179,13 +179,10 @@ func Command() *cobra.Command {
}
// loading tests
fmt.Fprintln(out, "Loading tests...")
if len(configuration.Spec.TestDirs) == 0 {
configuration.Spec.TestDirs = append(configuration.Spec.TestDirs, ".")
}
if err := fsutils.CheckFolders(configuration.Spec.TestDirs...); err != nil {
if err := fsutils.CheckFolders(options.testDirs...); err != nil {
return err
}
tests, err := discovery.DiscoverTests(configuration.Spec.TestFile, configuration.Spec.TestDirs...)
tests, err := discovery.DiscoverTests(configuration.Spec.TestFile, options.testDirs...)
if err != nil {
return err
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/data/crds/chainsaw.kyverno.io_configurations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ spec:
description: If set, do not delete the resources after running the
tests (implies SkipClusterDelete).
type: boolean
testDirs:
description: Directories containing test cases to run.
items:
type: string
type: array
testFile:
default: chainsaw-test.yaml
description: TestFile is the name of the file containing the test
Expand Down
3 changes: 0 additions & 3 deletions testdata/commands/test/config/config_all_fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ spec:
delete: 5s
cleanup: 5s
exec: 10s
testDirs:
- '.'
- '..'
skipDelete: true
failFast: true
parallel: 5
Expand Down
2 changes: 1 addition & 1 deletion testdata/commands/test/config_all_fields.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Loading config (../../../testdata/commands/test/config/config_all_fields.yaml)...
- Using test file: chainsaw-test.yaml
- TestDirs [. ..]
- TestDirs [.]
- SkipDelete true
- FailFast true
- ReportFormat 'JSON'
Expand Down
2 changes: 1 addition & 1 deletion testdata/commands/test/default.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Loading default configuration...
- Using test file: chainsaw-test.yaml
- TestDirs []
- TestDirs [.]
- SkipDelete false
- FailFast false
- ReportFormat ''
Expand Down
2 changes: 1 addition & 1 deletion testdata/commands/test/with_regex.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Loading default configuration...
- Using test file: chainsaw-test.yaml
- TestDirs []
- TestDirs [.]
- SkipDelete false
- FailFast false
- ReportFormat ''
Expand Down
2 changes: 1 addition & 1 deletion testdata/commands/test/with_repeat_count.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Loading default configuration...
- Using test file: chainsaw-test.yaml
- TestDirs []
- TestDirs [.]
- SkipDelete false
- FailFast false
- ReportFormat ''
Expand Down
2 changes: 1 addition & 1 deletion testdata/commands/test/with_suppress.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Loading default configuration...
- Using test file: chainsaw-test.yaml
- Timeout 30s
- TestDirs []
- TestDirs [.]
- SkipDelete false
- FailFast false
- ReportFormat ''
Expand Down
2 changes: 1 addition & 1 deletion testdata/commands/test/with_timeout.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Loading default configuration...
- Using test file: chainsaw-test.yaml
- TestDirs []
- TestDirs [.]
- SkipDelete false
- FailFast false
- ReportFormat ''
Expand Down
1 change: 0 additions & 1 deletion website/docs/apis/chainsaw.v1alpha1.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ during the testing process.</p>
| Field | Type | Required | Inline | Description |
|---|---|---|---|---|
| `timeouts` | [`Timeouts`](#chainsaw-kyverno-io-v1alpha1-Timeouts) | | | <p>Global timeouts configuration. Applies to all tests/test steps if not overridden.</p> |
| `testDirs` | `[]string` | | | <p>Directories containing test cases to run.</p> |
| `skipDelete` | `bool` | | | <p>If set, do not delete the resources after running the tests (implies SkipClusterDelete).</p> |
| `failFast` | `bool` | | | <p>FailFast determines whether the test should stop upon encountering the first failure.</p> |
| `parallel` | `int` | | | <p>The maximum number of tests to run at once.</p> |
Expand Down

0 comments on commit 1ecb519

Please sign in to comment.