mirror of
https://github.com/coder/terraform-provider-envbuilder.git
synced 2025-08-26 11:27:14 +00:00
fix: set MagicDir to tempdir when performing cache probe (#48)
* fix: set MagicDir to tempdir when performing cache probe * chore: update envbuilder to b7781d8 * imgutil: get default envbuilder binary path from envbuilder options
This commit is contained in:
parent
6137223cea
commit
4077a87dca
8 changed files with 67 additions and 35 deletions
testutil/registrytest
|
@ -2,6 +2,7 @@ package registrytest
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
@ -13,12 +14,31 @@ import (
|
|||
// New starts a new Docker registry listening on localhost.
|
||||
// It will automatically shut down when the test finishes.
|
||||
// It will store data in dir.
|
||||
func New(t testing.TB, dir string) string {
|
||||
func New(t testing.TB, dir string, mws ...func(http.Handler) http.Handler) string {
|
||||
t.Helper()
|
||||
regHandler := registry.New(registry.WithBlobHandler(registry.NewDiskBlobHandler(dir)))
|
||||
for _, mw := range mws {
|
||||
regHandler = mw(regHandler)
|
||||
}
|
||||
regSrv := httptest.NewServer(regHandler)
|
||||
t.Cleanup(func() { regSrv.Close() })
|
||||
regSrvURL, err := url.Parse(regSrv.URL)
|
||||
require.NoError(t, err)
|
||||
return fmt.Sprintf("localhost:%s", regSrvURL.Port())
|
||||
}
|
||||
|
||||
func BasicAuthMW(t testing.TB, username, password string) func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if username != "" || password != "" {
|
||||
authUser, authPass, ok := r.BasicAuth()
|
||||
if !ok || username != authUser || password != authPass {
|
||||
t.Logf("basic auth failed: got user %q, pass %q", authUser, authPass)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
}
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue