summaryrefslogtreecommitdiff
path: root/internal/test/handler.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/test/handler.go')
-rw-r--r--internal/test/handler.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/internal/test/handler.go b/internal/test/handler.go
new file mode 100644
index 0000000..5c02629
--- /dev/null
+++ b/internal/test/handler.go
@@ -0,0 +1,25 @@
+package test
+
+import (
+ "net/http"
+ "sync"
+)
+
+// HandlerSet is a struct with a mutex that allows us to swap handlers while a test server is running
+type HandlerSet struct {
+ mu sync.Mutex
+ handler http.Handler
+}
+
+func (hs *HandlerSet) SetHandler(handler http.Handler) {
+ hs.mu.Lock()
+ hs.handler = handler
+ hs.mu.Unlock()
+}
+
+func (hs *HandlerSet) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ hs.mu.Lock()
+ handler := hs.handler
+ hs.mu.Unlock()
+ handler.ServeHTTP(w, r)
+}