ostree: move test server to separate package
Make it reusable for other packages
This commit is contained in:
parent
ef513329a1
commit
36d8cd1dd2
2 changed files with 48 additions and 42 deletions
37
internal/ostree/mock_ostree_repo/mock_repo.go
Normal file
37
internal/ostree/mock_ostree_repo/mock_repo.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package mock_ostree_repo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
)
|
||||
|
||||
type OSTreeTestRepo struct {
|
||||
OSTreeRef string
|
||||
Server *httptest.Server
|
||||
}
|
||||
|
||||
func (repo *OSTreeTestRepo) TearDown() {
|
||||
if repo == nil {
|
||||
return
|
||||
}
|
||||
repo.Server.Close()
|
||||
}
|
||||
|
||||
func Setup(ref string) *OSTreeTestRepo {
|
||||
repo := new(OSTreeTestRepo)
|
||||
repo.OSTreeRef = ref
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/refs/heads/"+ref, func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, "02604b2da6e954bd34b8b82a835e5a77d2b60ffa")
|
||||
})
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
// catch-all handler, return 404
|
||||
http.NotFound(w, r)
|
||||
})
|
||||
|
||||
repo.Server = httptest.NewServer(mux)
|
||||
|
||||
return repo
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue