fix: missing imports in generated golang code fron testcatse (#457)

This commit is contained in:
WT 2024-05-27 21:05:03 +08:00 committed by GitHub
parent 775aab1d30
commit 1765d139c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View File

@ -19,6 +19,7 @@ import (
"bytes"
"html/template"
"net/http"
"strings"
_ "embed"
@ -41,6 +42,13 @@ func (g *golangGenerator) Generate(testSuite *testing.TestSuite, testcase *testi
buf := new(bytes.Buffer)
if err = tpl.Execute(buf, testcase); err == nil {
result = buf.String()
// Check if "bytes." is used in the generated code
if strings.Contains(result, "bytes.") {
// Only insert "bytes" import if it's not already included
if !strings.Contains(result, "\"bytes\"") {
result = strings.Replace(result, "import (", "import (\n\t\"bytes\"", 1)
}
}
}
}
return

View File

@ -13,6 +13,7 @@ limitations under the License.
package main
import (
"bytes"
"io"
"net/http"
)