Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/mimir/client/rules_test.go
4096 views
1
package client
2
3
import (
4
"context"
5
"fmt"
6
"net/http"
7
"net/http/httptest"
8
"testing"
9
10
"github.com/go-kit/log"
11
"github.com/prometheus/client_golang/prometheus"
12
"github.com/stretchr/testify/require"
13
"github.com/weaveworks/common/instrument"
14
)
15
16
func TestMimirClient_X(t *testing.T) {
17
requestCh := make(chan *http.Request, 1)
18
19
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
20
requestCh <- r
21
fmt.Fprintln(w, "hello")
22
}))
23
defer ts.Close()
24
25
client, err := New(log.NewNopLogger(), Config{
26
Address: ts.URL,
27
}, prometheus.NewHistogramVec(prometheus.HistogramOpts{}, instrument.HistogramCollectorBuckets))
28
require.NoError(t, err)
29
30
for _, tc := range []struct {
31
test string
32
namespace string
33
name string
34
expURLPath string
35
}{
36
{
37
test: "regular-characters",
38
namespace: "my-namespace",
39
name: "my-name",
40
expURLPath: "/prometheus/config/v1/rules/my-namespace/my-name",
41
},
42
{
43
test: "special-characters-spaces",
44
namespace: "My: Namespace",
45
name: "My: Name",
46
expURLPath: "/prometheus/config/v1/rules/My:%20Namespace/My:%20Name",
47
},
48
{
49
test: "special-characters-slashes",
50
namespace: "My/Namespace",
51
name: "My/Name",
52
expURLPath: "/prometheus/config/v1/rules/My%2FNamespace/My%2FName",
53
},
54
{
55
test: "special-characters-slash-first",
56
namespace: "My/Namespace",
57
name: "/first-char-slash",
58
expURLPath: "/prometheus/config/v1/rules/My%2FNamespace/%2Ffirst-char-slash",
59
},
60
{
61
test: "special-characters-slash-last",
62
namespace: "My/Namespace",
63
name: "last-char-slash/",
64
expURLPath: "/prometheus/config/v1/rules/My%2FNamespace/last-char-slash%2F",
65
},
66
} {
67
t.Run(tc.test, func(t *testing.T) {
68
ctx := context.Background()
69
require.NoError(t, client.DeleteRuleGroup(ctx, tc.namespace, tc.name))
70
71
req := <-requestCh
72
require.Equal(t, tc.expURLPath, req.URL.EscapedPath())
73
})
74
}
75
}
76
77