blob: 74c75067caba7a3aaf97b4211d2aa8df9ed5269f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package gitlabstub
import (
"net/http/httptest"
"os"
"github.com/gorilla/mux"
)
func NewUnstartedServer(opts ...Option) (*httptest.Server, error) {
wd, err := os.Getwd()
if err != nil {
return nil, err
}
conf := &config{
pagesRoot: wd,
}
for _, so := range opts {
so(conf)
}
if conf.pagesHandler == nil {
conf.pagesHandler = defaultAPIHandler(conf.delay, conf.pagesRoot)
}
router := mux.NewRouter()
router.HandleFunc("/api/v4/internal/pages", conf.pagesHandler)
authHandler := defaultAuthHandler()
router.HandleFunc("/oauth/token", authHandler)
userHandler := defaultUserHandler()
router.HandleFunc("/api/v4/user", userHandler)
router.HandleFunc("/api/v4/projects/{project_id:[0-9]+}/pages_access", handleAccessControlRequests)
router.PathPrefix("/").HandlerFunc(handleAccessControlArtifactRequests)
s := httptest.NewUnstartedServer(router)
s.TLS = conf.tlsConfig
return s, nil
}
|