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

Add test filename suffix #1785

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions internal/super/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package super

import (
"strings"

"github.com/onflow/flowkit/v2"
"github.com/onflow/flowkit/v2/output"

Expand Down Expand Up @@ -141,7 +143,8 @@ func generateTest(
state *flowkit.State,
) (result command.Result, err error) {
g := generator.NewGenerator("", state, logger, false, true)
name := util.StripCDCExtension(args[0])
err = g.Create(generator.TestTemplate{Name: name})
nameWithoutCdc := util.StripCDCExtension(args[0])
nameWithoutSuffix := strings.TrimSuffix(nameWithoutCdc, "_test")
err = g.Create(generator.TestTemplate{Name: nameWithoutSuffix})
return nil, err
}
2 changes: 1 addition & 1 deletion internal/super/generator/contract_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (c ContractTemplate) GetChildren() []TemplateItem {

return []TemplateItem{
TestTemplate{
Name: fmt.Sprintf("%s_test", c.Name),
Name: c.Name,
TemplatePath: "contract_init_test.cdc.tmpl",
Data: map[string]interface{}{
"ContractName": c.Name,
Expand Down
2 changes: 1 addition & 1 deletion internal/super/generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func TestGenerateTestTemplate(t *testing.T) {

g := NewGenerator("", state, logger, false, true)
err := g.Create(TestTemplate{
Name: "Foobar_test",
Name: "Foobar",
TemplatePath: "contract_init_test.cdc.tmpl",
Data: map[string]interface{}{
"ContractName": "Foobar",
Expand Down
22 changes: 9 additions & 13 deletions internal/super/generator/test_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,25 @@ type TestTemplate struct {

var _ TemplateItem = TestTemplate{}

func (o TestTemplate) GetType() string {
func (t TestTemplate) GetType() string {
return "test"
}

// GetName returns the name of the script or transaction
func (o TestTemplate) GetName() string {
return o.Name
}

// GetTemplate returns an empty string for scripts and transactions
func (o TestTemplate) GetTemplatePath() string {
if o.TemplatePath == "" {
func (t TestTemplate) GetTemplatePath() string {
if t.TemplatePath == "" {
return "empty_test.cdc.tmpl"
}

return o.TemplatePath
return t.TemplatePath
}

// GetData returns the data of the script or transaction
func (o TestTemplate) GetData() map[string]interface{} {
return o.Data
func (t TestTemplate) GetData() map[string]interface{} {
return t.Data
}

func (o TestTemplate) GetTargetPath() string {
return filepath.Join(DefaultCadenceDirectory, DefaultTestDirectory, util.AddCDCExtension(o.Name))
func (t TestTemplate) GetTargetPath() string {
baseName := t.Name + "_test"
return filepath.Join(DefaultCadenceDirectory, DefaultTestDirectory, util.AddCDCExtension(baseName))
}
1 change: 0 additions & 1 deletion internal/super/generator/transaction_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ type TransactionTemplate struct {

var _ TemplateItem = TransactionTemplate{}

// GetName returns the name of the script or transaction
func (o TransactionTemplate) GetType() string {
return "transaction"
}
Expand Down
Loading