diff --git a/tools/goctl/api/gogen/handler_test.tpl b/tools/goctl/api/gogen/handler_test.tpl index e99277324ed7..f461f4ddda65 100644 --- a/tools/goctl/api/gogen/handler_test.tpl +++ b/tools/goctl/api/gogen/handler_test.tpl @@ -62,8 +62,9 @@ func Test{{.HandlerName}}(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tt.setupMocks() - reqBody := []byte{} - {{if .HasRequest}}reqBody, err := json.Marshal(tt.reqBody) + var reqBody []byte + {{if .HasRequest}}var err error + reqBody, err = json.Marshal(tt.reqBody) require.NoError(t, err){{end}} req, err := http.NewRequest("POST", "/ut", bytes.NewBuffer(reqBody)) require.NoError(t, err)