From b54a38f0b5ce164c937d959ccf15da21318c5426 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink <17958158+jribbink@users.noreply.github.com> Date: Thu, 10 Oct 2024 10:18:12 -0700 Subject: [PATCH] Add test filename suffix (#1785) --- internal/super/generate.go | 7 ++++-- internal/super/generator/contract_template.go | 2 +- internal/super/generator/generator_test.go | 2 +- internal/super/generator/test_template.go | 22 ++++++++----------- .../super/generator/transaction_template.go | 1 - 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/internal/super/generate.go b/internal/super/generate.go index 9a3d2e9e0..ae78efb5f 100644 --- a/internal/super/generate.go +++ b/internal/super/generate.go @@ -19,6 +19,8 @@ package super import ( + "strings" + "github.com/onflow/flowkit/v2" "github.com/onflow/flowkit/v2/output" @@ -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 } diff --git a/internal/super/generator/contract_template.go b/internal/super/generator/contract_template.go index f8bbb5dd9..7ad0959ab 100644 --- a/internal/super/generator/contract_template.go +++ b/internal/super/generator/contract_template.go @@ -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, diff --git a/internal/super/generator/generator_test.go b/internal/super/generator/generator_test.go index f4fca000c..230df5955 100644 --- a/internal/super/generator/generator_test.go +++ b/internal/super/generator/generator_test.go @@ -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", diff --git a/internal/super/generator/test_template.go b/internal/super/generator/test_template.go index 49e13e718..11e8ae7ab 100644 --- a/internal/super/generator/test_template.go +++ b/internal/super/generator/test_template.go @@ -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)) } diff --git a/internal/super/generator/transaction_template.go b/internal/super/generator/transaction_template.go index 4accc1cdc..0869aef25 100644 --- a/internal/super/generator/transaction_template.go +++ b/internal/super/generator/transaction_template.go @@ -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" }