From 0bf0dd22949fc6d0f76cb0936def6cb8acc99fb3 Mon Sep 17 00:00:00 2001 From: Tomas Nevrlka Date: Mon, 19 Feb 2024 15:18:21 +0100 Subject: [PATCH] refactor: move template filepaths map to const.go --- magefiles/testspecs/const.go | 8 ++++++++ magefiles/testspecs/ginkgosspec.go | 8 +------- magefiles/testspecs/templates.go | 19 +------------------ 3 files changed, 10 insertions(+), 25 deletions(-) create mode 100644 magefiles/testspecs/const.go diff --git a/magefiles/testspecs/const.go b/magefiles/testspecs/const.go new file mode 100644 index 0000000000..d453e1470b --- /dev/null +++ b/magefiles/testspecs/const.go @@ -0,0 +1,8 @@ +package testspecs + +const ( + TestFilePath = "templates/test_output_spec.tmpl" + FrameworkDescribePath = "templates/framework_describe_func.tmpl" + + SpecsPath = "templates/specs.tmpl" +) diff --git a/magefiles/testspecs/ginkgosspec.go b/magefiles/testspecs/ginkgosspec.go index db94efebc5..0bf9240a48 100644 --- a/magefiles/testspecs/ginkgosspec.go +++ b/magefiles/testspecs/ginkgosspec.go @@ -134,15 +134,9 @@ func generateGinkgoSpec(cwd string, destination string, dataFile string) error { // Doing this to avoid errcheck flagging this in a defer. // Refer to https://github.com/kisielk/errcheck // issues 101, 77, 55 - tmpl, err := GetTemplate("test-file") - if err != nil { - return err - } - - fullTemplatePath := fmt.Sprintf("%s/%s", cwd, tmpl) klog.Infof("Creating new test package directory and spec file %s.\n", destination) - _, err = ginkgoGenerateSpecCmd("--template", fullTemplatePath, "--template-data", dataFile) + _, err = ginkgoGenerateSpecCmd("--template", TestFilePath, "--template-data", dataFile) if err != nil { err = os.Remove(ginkgoFileName) if err != nil { diff --git a/magefiles/testspecs/templates.go b/magefiles/testspecs/templates.go index 3ef3ee0ed4..076752eddf 100644 --- a/magefiles/testspecs/templates.go +++ b/magefiles/testspecs/templates.go @@ -13,11 +13,6 @@ import ( "k8s.io/klog/v2" ) -var templates = map[string]string{ - "test-file": "templates/test_output_spec.tmpl", - "framework-describe": "templates/framework_describe_func.tmpl", -} - func NewTemplateData(specOutline TestOutline, destination string) *TemplateData { // This regex will find all the words that start with capital letter @@ -47,22 +42,10 @@ func NewTemplateData(specOutline TestOutline, destination string) *TemplateData return &TemplateData{Outline: specOutline, PackageName: dirName, FrameworkDescribeString: newSpecName} } -func GetTemplate(name string) (string, error) { - if s, ok := templates[name]; ok { - return s, nil - } - return "", fmt.Errorf("no Template found for %q", name) -} - func RenderFrameworkDescribeGoFile(t TemplateData) error { - - templatePath, err := GetTemplate("framework-describe") - if err != nil { - return err - } var describeFile = "pkg/framework/describe.go" - err = renderTemplate(describeFile, templatePath, t, true) + err := renderTemplate(describeFile, FrameworkDescribePath, t, true) if err != nil { klog.Errorf("failed to append to pkg/framework/describe.go with : %s", err) return err