From 1a5e5d15ed393d7bde6a453722ad828343445300 Mon Sep 17 00:00:00 2001 From: Tomas Nevrlka Date: Mon, 26 Feb 2024 16:40:42 +0100 Subject: [PATCH] chore: unify provided templates and testOutline - Change the docs reflecting the changes - Move all the provided templates and testOutline into a new templates/default directory --- docs/DeveloperGenerateTest.md | 37 ++++++------------------ templates/default/barebones.tmpl | 23 +++++++++++++++ templates/default/recommended.tmpl | 45 ++++++++++++++++++++++++++++++ templates/default/testOutline | 32 +++++++++++++++++++++ 4 files changed, 108 insertions(+), 29 deletions(-) create mode 100644 templates/default/barebones.tmpl create mode 100644 templates/default/recommended.tmpl create mode 100644 templates/default/testOutline diff --git a/docs/DeveloperGenerateTest.md b/docs/DeveloperGenerateTest.md index c656feb29d..bda3641c16 100644 --- a/docs/DeveloperGenerateTest.md +++ b/docs/DeveloperGenerateTest.md @@ -180,33 +180,10 @@ These should utilize the provided `specs.tmpl` by including the following line w `{{ template "specs" . }}` -Please see the provided example: -``` -package {{ .CustomData.PackageName }} - -/* This was generated from a template file. Please feel free to update as necessary! - a couple things to note: - - Remember to implement specific logic of the service/domain you are trying to test if it not already there in the pkg/ - - - To include the tests as part of the E2E Test suite: - - Update the pkg/framework/describe.go to include the `Describe func` of this new test suite, If you haven't already done so. - - Import this new package into the cmd/e2e_test.go -*/ - -import ( - // Imports here -) - -{{ range .CustomData.Outline }} -var _ = framework.{{ .Name }} -("{{ .Text }}", {{ range .Labels }}Label("{{.}}"), {{ end }} func() { - // Setup here +Everything needed to get started is in the [templates/default](../templates/default) directory. - // Generated specs: - {{ template "specs" . }} -}) -{{ end -}} -``` +Please see the provided [recommended](../templates/default/recommended.tmpl) and [barebones](../templates/default/barebones.tmpl) templates. +Copy them and make your own. ## Usage @@ -267,11 +244,13 @@ As noted above, this command will create a new package under the `tests/` direct ### Generating a team specific Ginkgo spec file from an existing text outline file This will generate the Ginkgo spec in a subdirectory within our tests directory using a team specific template provided by user. Please see the [Team specific template](#team-specific-template) section. +Feel free to use the provided [testOutline](../templates/default/testOutline) file for testing. + `./mage GenerateTeamSpecificGinkgoSpecFromTextOutline // // /.go` ```bash -➜ ./mage GenerateTeamSpecificGinkgoSpecFromTextOutline templates/testOutline templates/barebones/barebones.tmpl tests/template_poc/template_poc.go -I0219 15:42:17.808595 351210 magefile.go:755] Mapping outline from a text file, templates/testOutline +➜ ./mage GenerateTeamSpecificGinkgoSpecFromTextOutline templates/default/testOutline templates/default/recommended.tmpl tests/template_poc/template_poc.go +I0219 15:42:17.808595 351210 magefile.go:755] Mapping outline from a text file, templates/default/testOutline I0219 15:42:17.808685 351210 magefile.go:762] Mapping outline to a Ginkgo spec file, tests/template_poc/template_poc.go I0219 15:42:17.809210 351210 ginkgosspec.go:144] Creating new test package directory and spec file /home/tnevrlka/Work/e2e-tests/tests/template_poc/template_poc.go. ``` @@ -341,4 +320,4 @@ $ ./mage GenerateTestSuiteFile chaos I0623 12:48:13.761038 31196 magefile.go:467] Creating new test suite file cmd/chaos_test.go. cmd/chaos_test.go -``` \ No newline at end of file +``` diff --git a/templates/default/barebones.tmpl b/templates/default/barebones.tmpl new file mode 100644 index 0000000000..bb2f367298 --- /dev/null +++ b/templates/default/barebones.tmpl @@ -0,0 +1,23 @@ +package {{ .CustomData.PackageName }} + +/* This was generated from a template file. Please feel free to update as necessary! + a couple things to note: + - Remember to implement specific logic of the service/domain you are trying to test if it not already there in the pkg/ + + - To include the tests as part of the E2E Test suite: + - Update the pkg/framework/describe.go to include the `Describe func` of this new test suite, If you haven't already done so. + - Import this new package into the cmd/e2e_test.go +*/ + +import ( + // Imports here +) + +{{ range .CustomData.Outline }} +var _ = framework.{{ .Name }}("{{ .Text }}", {{ range .Labels }}Label("{{.}}"), {{ end }} func() { + // Setup here + + // Generated specs: + {{ template "specs" . }} +}) +{{ end -}} \ No newline at end of file diff --git a/templates/default/recommended.tmpl b/templates/default/recommended.tmpl new file mode 100644 index 0000000000..5db1255dcf --- /dev/null +++ b/templates/default/recommended.tmpl @@ -0,0 +1,45 @@ +package {{ .CustomData.PackageName }} + +/* This was generated from a template file. Please feel free to update as necessary! + a couple things to note: + - Remember to implement specific logic of the service/domain you are trying to test if it not already there in the pkg/ + + - To include the tests as part of the E2E Test suite: + - Update the pkg/framework/describe.go to include the `Describe func` of this new test suite, If you haven't already done so. + - Import this new package into the cmd/e2e_test.go +*/ + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "fmt" + "strings" + "time" + "encoding/json" + "context" + + + "github.com/redhat-appstudio/e2e-tests/pkg/framework" + //framework imports edit as required + "github.com/redhat-appstudio/e2e-tests/pkg/constants" + "github.com/redhat-appstudio/e2e-tests/pkg/utils" + +) + +{{ range .CustomData.Outline }} +var _ = framework.{{ .Name }}("{{ .Text }}", {{range .Labels }}Label("{{.}}"), {{ end }} func() { + defer GinkgoRecover() + var err error + var f *framework.Framework + // use 'f' to access common controllers or the specific service controllers within the framework + BeforeAll(func() { + // Initialize the tests controllers + f, err = framework.NewFramework() + Expect(err).NotTo(HaveOccurred()) + }) + + // Generated specs: + {{ template "specs" . }} +}) +{{ end }} \ No newline at end of file diff --git a/templates/default/testOutline b/templates/default/testOutline new file mode 100644 index 0000000000..771906c22a --- /dev/null +++ b/templates/default/testOutline @@ -0,0 +1,32 @@ +BuildSuiteDescribe: Build service E2E tests @build, @HACBS + Describe: test PaC component build @github-webhook, @pac-build, @pipeline + When: a new component without specified branch is created @pac-custom-default-branch + It: correctly targets the default branch (that is not named 'main') with PaC + It: triggers a PipelineRun + It: a related PipelineRun and Github webhook should be deleted after deleting the component + It: PR branch should not exists in the repo + When: a new component with specified custom branch branch is created + It: triggers a PipelineRun + It: should lead to a PaC init PR creation + It: the PipelineRun should eventually finish successfully + It: eventually leads to a creation of a PR comment with the PipelineRun status report + When: the PaC init branch is updated + It: eventually leads to triggering another PipelineRun + It: PipelineRun should eventually finish + It: eventually leads to another update of a PR with a comment about the PipelineRun status report + When: the PaC init branch is merged + It: eventually leads to triggering another PipelineRun + It: pipelineRun should eventually finish + When: the component is removed and recreated (with the same name in the same namespace) + It: should no longer lead to a creation of a PaC PR + + Describe: Creating component with container image source + It: should not trigger a PipelineRun + + Describe: PLNSRVCE-799 - test pipeline selector @pipeline-selector + It: a specific Pipeline bundle should be used and additional pipeline params should be added to the PipelineRun if all WhenConditions match + It: default Pipeline bundle should be used and no additional Pipeline params should be added to the PipelineRun if one of the WhenConditions does not match + + Describe: A secret with dummy quay.io credentials is created in the testing namespace + It: should override the shared secret + It: should not be possible to push to quay.io repo (PipelineRun should fail)