testutil/fakestorage: inline go code and remove contrib/httpserver

It's 12 lines of code total; we may as well write it as part of building;
it looks to be the only place this is used, so we can remove the contrib
directory, which should not be used by anyone.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-08-07 10:50:10 +02:00
parent d49a354cb2
commit 50789e2bab
3 changed files with 18 additions and 17 deletions

View File

@@ -1,4 +0,0 @@
FROM busybox
EXPOSE 80/tcp
COPY httpserver .
CMD ["./httpserver"]

View File

@@ -1,12 +0,0 @@
package main
import (
"log"
"net/http"
)
func main() {
fs := http.FileServer(http.Dir("/static"))
http.Handle("/", fs)
log.Panic(http.ListenAndServe(":80", nil)) // #nosec G114 -- Ignoring for test-code: G114: Use of net/http serve function that has no support for setting timeouts (gosec)
}

View File

@@ -40,7 +40,24 @@ func ensureHTTPServerImage(t testing.TB) {
assert.NilError(t, err, "could not find go executable to build http server")
tmp := t.TempDir()
cmd := exec.Command(goCmd, "build", "-o", filepath.Join(tmp, "httpserver"), "../contrib/httpserver")
const httpServer = `package main
import (
"log"
"net/http"
)
func main() {
fs := http.FileServer(http.Dir("/static"))
http.Handle("/", fs)
log.Panic(http.ListenAndServe(":80", nil)) // #nosec G114 -- Ignoring for test-code: G114: Use of net/http serve function that has no support for setting timeouts (gosec)
}
`
src := filepath.Join(tmp, "main.go")
err = os.WriteFile(filepath.Join(tmp, "main.go"), []byte(httpServer), 0o0644)
assert.NilError(t, err)
cmd := exec.Command(goCmd, "build", "-o", filepath.Join(tmp, "httpserver"), src)
cmd.Env = append(os.Environ(), []string{
"CGO_ENABLED=0",
"GOOS=" + goos,