Skip to content

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

@Dannyb48

Description

@Dannyb48

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

})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions