/
testing.go
53 lines (42 loc) · 1.39 KB
/
testing.go
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
47
48
49
50
51
52
53
/*
This file contains testing helpers for the handlers package.
*/
package handlers
import (
"fmt"
"net/http"
"time"
osproject_v1 "github.com/openshift/api/project/v1"
core_v1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/clientcmd/api"
"github.com/kiali/kiali/business/authentication"
"github.com/kiali/kiali/kubernetes"
"github.com/kiali/kiali/util"
)
func mockClock() {
clockTime := time.Date(2017, 0o1, 15, 0, 0, 0, 0, time.UTC)
util.Clock = util.ClockMock{Time: clockTime}
}
type noPrivClient struct {
kubernetes.ClientInterface
}
func (n *noPrivClient) GetProjects(labelSelector string) ([]osproject_v1.Project, error) {
return nil, fmt.Errorf("Rejecting")
}
func (n *noPrivClient) GetProject(name string) (*osproject_v1.Project, error) {
return nil, fmt.Errorf("Rejecting")
}
func (n *noPrivClient) GetNamespace(namespace string) (*core_v1.Namespace, error) {
return nil, fmt.Errorf("Rejecting")
}
func (n *noPrivClient) GetNamespaces(labelSelector string) ([]core_v1.Namespace, error) {
return nil, fmt.Errorf("Rejecting")
}
// WithAuthInfo injects the given auth info into the request context of the given handler.
// Useful for testing only.
func WithAuthInfo(authInfo *api.AuthInfo, hf http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
context := authentication.SetAuthInfoContext(r.Context(), authInfo)
hf(w, r.WithContext(context))
}
}