@@ -2,20 +2,18 @@ package client
22
33import (
44 "context"
5- "fmt"
65 "net/http"
76 "net/http/httptest"
87 "testing"
98
109 "github.com/stretchr/testify/require"
1110)
1211
13- func TestCortexClient_X (t * testing.T ) {
12+ func TestCortexClient_DeleteRuleGroup (t * testing.T ) {
1413 requestCh := make (chan * http.Request , 1 )
1514
1615 ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1716 requestCh <- r
18- fmt .Fprintln (w , "hello" )
1917 }))
2018 defer ts .Close ()
2119
@@ -57,7 +55,7 @@ func TestCortexClient_X(t *testing.T) {
5755 expURLPath : "/api/v1/rules/My%2FNamespace/%2Ffirst-char-slash" ,
5856 },
5957 {
60- test : "special-characters-slash-first " ,
58+ test : "special-characters-slash-last " ,
6159 namespace : "My/Namespace" ,
6260 name : "last-char-slash/" ,
6361 expURLPath : "/api/v1/rules/My%2FNamespace/last-char-slash%2F" ,
@@ -69,7 +67,65 @@ func TestCortexClient_X(t *testing.T) {
6967
7068 req := <- requestCh
7169 require .Equal (t , tc .expURLPath , req .URL .EscapedPath ())
70+ require .Equal (t , http .MethodDelete , req .Method )
71+ })
72+ }
73+
74+ }
75+
76+ func TestCortexClient_DeleteRuleNamespace (t * testing.T ) {
77+ requestCh := make (chan * http.Request , 1 )
78+
79+ ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
80+ requestCh <- r
81+ }))
82+ defer ts .Close ()
7283
84+ client , err := New (Config {
85+ Address : ts .URL ,
86+ ID : "my-id" ,
87+ Key : "my-key" ,
88+ })
89+ require .NoError (t , err )
90+
91+ for _ , tc := range []struct {
92+ test string
93+ namespace string
94+ expURLPath string
95+ }{
96+ {
97+ test : "regular-characters" ,
98+ namespace : "my-namespace" ,
99+ expURLPath : "/api/v1/rules/my-namespace" ,
100+ },
101+ {
102+ test : "special-characters-spaces" ,
103+ namespace : "My: Namespace" ,
104+ expURLPath : "/api/v1/rules/My:%20Namespace" ,
105+ },
106+ {
107+ test : "special-characters-slashes" ,
108+ namespace : "My/Namespace" ,
109+ expURLPath : "/api/v1/rules/My%2FNamespace" ,
110+ },
111+ {
112+ test : "special-characters-slash-first" ,
113+ namespace : "/My/Namespace" ,
114+ expURLPath : "/api/v1/rules/%2FMy%2FNamespace" ,
115+ },
116+ {
117+ test : "special-characters-slash-last" ,
118+ namespace : "My/Namespace/" ,
119+ expURLPath : "/api/v1/rules/My%2FNamespace%2F" ,
120+ },
121+ } {
122+ t .Run (tc .test , func (t * testing.T ) {
123+ ctx := context .Background ()
124+ require .NoError (t , client .DeleteRuleNamespace (ctx , tc .namespace ))
125+
126+ req := <- requestCh
127+ require .Equal (t , tc .expURLPath , req .URL .EscapedPath ())
128+ require .Equal (t , http .MethodDelete , req .Method )
73129 })
74130 }
75131
0 commit comments