Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for passing in custom template data when using a template file for the bootstrap and generate commands #1100

Closed
Dannyb48 opened this issue Dec 15, 2022 · 4 comments · Fixed by #1110

Comments

@Dannyb48
Copy link
Contributor

Hi, we have a use case where currently we used Ginkgo for System Levels E2E API Tests. We leverage the generate and bootstrap commands with the --template to be able to get team members up and running coding new test specs.

That said there are times where we want to modify our template with more variables to inject other metadata during rendering rather than hardcoding it in or modifying it afterwards. Below is an example where we would want to render in the values for .TestSpecName, .FrameworkImport, .TestFeature, .TestComponent, .TestId as part of the generate command of our test spec template.

If you guys are OK with this I would be interested in contributing this to the commands

package {{.Package }}

/* This was generated from a template file. Please feel free to update as necessary */

import (
	. "github.com/onsi/ginkgo/v2"
	. "github.com/onsi/gomega"

    "fmt"
	"strings"
	"time"
    "encoding/json"
    "context"


    //framework imports edit as required
    {{ .FrameworkImport }}

)

var _ = framework.{{ .TestSpecName }}SuiteDescribe("{{ .TestSpecName }} tests", Label("{{ .TestFeature }}"), func() {

    /* note:
    - You may need to implement specific implementation of the service/domain you are trying to test if it
    not already there in the pkg/ packages
    */

	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())
	})



    Describe("{{ .TestSpecName }} scenario to test", Label("{{ .TestComponent }}"), func() {
        // Declare variables here.

        BeforeEach(func() {

        // Initialize variables here.
        // Assert setup here.

        })

        It("{{ .TestId }} does some test action", func() { 

        // Implement test and assertions here
        
        })
    
    })

})
@onsi
Copy link
Owner

onsi commented Dec 15, 2022

sure - how would you be passing the data in to the cli? pointing it at a json file?

@Dannyb48
Copy link
Contributor Author

@onsi yeah, or a yaml file

@onsi
Copy link
Owner

onsi commented Dec 16, 2022

ok makes sense then. i'm planning on adding support for configuring ginkgo via a file and i'm going to be using JSON - so my preference would be that we use JSON instead of yaml for this.

@Dannyb48
Copy link
Contributor Author

sure, no problem from me on standardizing on JSON. I'll see if I can get something relatively soon. Thank you for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants