fix(create_project): use fmt.Fprintf in test fake (lint QF1012)

Follow-up to e3cdd23 — staticcheck QF1012 flagged w.Write([]byte(fmt.Sprintf(...)))
in the rewritten test's fake server. Behaviour unchanged; lint gate green.
This commit is contained in:
2026-07-01 22:53:15 +02:00
parent e3cdd23260
commit e30951ad72
@@ -61,13 +61,13 @@ func (f *fakeTemplateServer) handler(t *testing.T, tmpl, dest string) http.Handl
return return
} }
f.repoGetsPost++ f.repoGetsPost++
_, _ = w.Write([]byte(fmt.Sprintf(`{"name":%q,"full_name":"mathias/%s","default_branch":"main","clone_url":"c","html_url":"h","template":false}`, dest, dest))) _, _ = fmt.Fprintf(w, `{"name":%q,"full_name":"mathias/%s","default_branch":"main","clone_url":"c","html_url":"h","template":false}`, dest, dest)
case r.Method == http.MethodPost && p == "/api/v1/repos/mathias/"+tmpl+"/generate": case r.Method == http.MethodPost && p == "/api/v1/repos/mathias/"+tmpl+"/generate":
f.generated = true f.generated = true
w.WriteHeader(http.StatusCreated) w.WriteHeader(http.StatusCreated)
_, _ = w.Write([]byte(fmt.Sprintf(`{"name":%q,"full_name":"mathias/%s","default_branch":%q,"clone_url":"http://gitea.example.com/mathias/%s.git","html_url":"http://gitea.example.com/mathias/%s","template":false}`, _, _ = fmt.Fprintf(w, `{"name":%q,"full_name":"mathias/%s","default_branch":%q,"clone_url":"http://gitea.example.com/mathias/%s.git","html_url":"http://gitea.example.com/mathias/%s","template":false}`,
dest, dest, f.genBranch, dest, dest))) dest, dest, f.genBranch, dest, dest)
case r.Method == http.MethodGet && strings.HasPrefix(p, "/api/v1/repos/mathias/"+dest+"/git/trees/"): case r.Method == http.MethodGet && strings.HasPrefix(p, "/api/v1/repos/mathias/"+dest+"/git/trees/"):
var entries []string var entries []string
@@ -76,7 +76,7 @@ func (f *fakeTemplateServer) handler(t *testing.T, tmpl, dest string) http.Handl
} }
// include a tree (directory) entry to exercise the blob filter // include a tree (directory) entry to exercise the blob filter
entries = append(entries, `{"path":"cmd","type":"tree","sha":"treesha"}`) entries = append(entries, `{"path":"cmd","type":"tree","sha":"treesha"}`)
_, _ = w.Write([]byte(fmt.Sprintf(`{"sha":"root","tree":[%s],"truncated":false}`, strings.Join(entries, ",")))) _, _ = fmt.Fprintf(w, `{"sha":"root","tree":[%s],"truncated":false}`, strings.Join(entries, ","))
case r.Method == http.MethodGet && strings.HasPrefix(p, "/api/v1/repos/mathias/"+dest+"/contents/"): case r.Method == http.MethodGet && strings.HasPrefix(p, "/api/v1/repos/mathias/"+dest+"/contents/"):
path := strings.TrimPrefix(p, "/api/v1/repos/mathias/"+dest+"/contents/") path := strings.TrimPrefix(p, "/api/v1/repos/mathias/"+dest+"/contents/")
@@ -86,8 +86,8 @@ func (f *fakeTemplateServer) handler(t *testing.T, tmpl, dest string) http.Handl
_, _ = w.Write([]byte(`{"message":"not found"}`)) _, _ = w.Write([]byte(`{"message":"not found"}`))
return return
} }
_, _ = w.Write([]byte(fmt.Sprintf(`{"path":%q,"sha":"sha-%s","size":1,"content":%q,"encoding":"base64"}`, _, _ = fmt.Fprintf(w, `{"path":%q,"sha":"sha-%s","size":1,"content":%q,"encoding":"base64"}`,
path, strings.ReplaceAll(path, "/", "-"), encb64(body)))) path, strings.ReplaceAll(path, "/", "-"), encb64(body))
// POST = create (new/renamed file, no sha), PUT = update (existing, with sha). // POST = create (new/renamed file, no sha), PUT = update (existing, with sha).
case (r.Method == http.MethodPost || r.Method == http.MethodPut) && strings.HasPrefix(p, "/api/v1/repos/mathias/"+dest+"/contents/"): case (r.Method == http.MethodPost || r.Method == http.MethodPut) && strings.HasPrefix(p, "/api/v1/repos/mathias/"+dest+"/contents/"):