Skip to content

Commit

Permalink
chore: unify provided templates and testOutline
Browse files Browse the repository at this point in the history
- Change the docs reflecting the changes
- Move all the provided templates and testOutline into a new
  templates/default directory
  • Loading branch information
tnevrlka committed Feb 26, 2024
1 parent 84f95b1 commit 1a5e5d1
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 29 deletions.
37 changes: 8 additions & 29 deletions docs/DeveloperGenerateTest.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 <path>/<to>/<outline> <path>/<to>/<team-specific-template> <subpath-under-tests>/<filename>.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.
```
Expand Down Expand Up @@ -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

```
```
23 changes: 23 additions & 0 deletions templates/default/barebones.tmpl
Original file line number Diff line number Diff line change
@@ -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 -}}
45 changes: 45 additions & 0 deletions templates/default/recommended.tmpl
Original file line number Diff line number Diff line change
@@ -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 }}
32 changes: 32 additions & 0 deletions templates/default/testOutline
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 1a5e5d1

Please sign in to comment.