From 028b3d8e2366b08c18015471f9e84ea4c0b3f79a Mon Sep 17 00:00:00 2001 From: b1ron Date: Fri, 9 Jun 2023 14:53:03 +0200 Subject: [PATCH] only use fmt.Fprintf --- internal/jstest/jstest.go | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/internal/jstest/jstest.go b/internal/jstest/jstest.go index 1d3d0f6d1..191bf1814 100644 --- a/internal/jstest/jstest.go +++ b/internal/jstest/jstest.go @@ -152,7 +152,7 @@ func runShellWithScript(dir, script string) ([]byte, error) { dockerArgs := []string{"compose", "run", "-T", "--rm", "mongo"} shellArgs := []string{ "--verbose", "--norc", "mongodb://host.docker.internal:27017/", - "--eval", evalBuilder(script, nil), script, + "--eval", evalBuilder(script), script, } dockerArgs = append(dockerArgs, shellArgs...) @@ -165,33 +165,11 @@ func runShellWithScript(dir, script string) ([]byte, error) { } // evalBuilder creates the TestData object and sets the testName property for the shell. -// It optionally sets additional properties on the TestData object. -func evalBuilder(script string, obj map[string]string) string { +func evalBuilder(script string) string { var eb bytes.Buffer - eb.WriteString("TestData = new Object();") - eb.WriteByte(' ') + fmt.Fprintf(&eb, "TestData = new Object(); ") scriptName := filepath.Base(script) fmt.Fprintf(&eb, "TestData.testName = %q;", strings.TrimSuffix(scriptName, filepath.Ext(scriptName))) - if obj == nil { - return eb.String() - } - - eb.WriteByte(' ') - - // avoids extraneous space - i := len(obj) - 1 - - for key, value := range obj { - fmt.Fprintf(&eb, "TestData.%s = %s;", key, value) - - if i == 0 { - break - } - i-- - - eb.WriteByte(' ') - } - return eb.String() }