-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add team specific template generation (#1048)
* refactor: move template filepaths map to const.go * feat: add team specific template generation Allow teams to generate a Ginkgo spec from outline using their team specific templates. * docs: add team specific template generation * refactor: move testspecs package to pkg directory * fix: possible memory leak caused by defer * 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 * feat: test for mergeFiles function * chore: remove barebones template
- Loading branch information
Showing
12 changed files
with
371 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package testspecs | ||
|
||
const ( | ||
TestFilePath = "templates/test_output_spec.tmpl" | ||
FrameworkDescribePath = "templates/framework_describe_func.tmpl" | ||
|
||
SpecsPath = "templates/specs.tmpl" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package testspecs | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestMergeTemplates(t *testing.T) { | ||
cwd, err := os.Getwd() | ||
if err != nil { | ||
t.Fatal(err) | ||
return | ||
} | ||
|
||
tempDir, err := os.MkdirTemp(cwd, "test-merge-templates") | ||
if err != nil { | ||
t.Fatal(err) | ||
return | ||
} | ||
defer os.RemoveAll(tempDir) | ||
|
||
err = os.Chdir(tempDir) | ||
if err != nil { | ||
t.Fatal(err) | ||
return | ||
} | ||
|
||
var fileNames []string | ||
var expectedString string | ||
|
||
for i := 0; i < 10; i++ { | ||
file, err := os.CreateTemp(tempDir, "tempFile") | ||
if err != nil { | ||
t.Fatal(err) | ||
return | ||
} | ||
lineContent := fmt.Sprintf("This should be line number '%d' from '%s'", i, file.Name()) | ||
_, err = file.WriteString(lineContent) | ||
if err != nil { | ||
t.Fatal(err) | ||
return | ||
} | ||
expectedString += lineContent + "\n\n" | ||
fileNames = append(fileNames, file.Name()) | ||
} | ||
|
||
mergedFile, err := mergeTemplates(fileNames...) | ||
if err != nil { | ||
t.Errorf("failed to merge templates: %+v", err) | ||
return | ||
} | ||
|
||
mergedFile, err = os.Open(mergedFile.Name()) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
mergedFileBytes, err := os.ReadFile(mergedFile.Name()) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
|
||
mergedFileContent := string(mergedFileBytes) | ||
if mergedFileContent != expectedString { | ||
t.Errorf("content of merged file does not match the expected content") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
Oops, something went wrong.