MCPcopy
hub / github.com/dnote/dnote / TestSignOut

Function TestSignOut

pkg/cli/client/client_test.go:138–181  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

136}
137
138func TestSignOut(t *testing.T) {
139 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
140 if r.URL.String() == "/api/v3/signout" && r.Method == "POST" {
141 w.WriteHeader(http.StatusNoContent)
142 }
143 }))
144 defer ts.Close()
145
146 commonTs := startCommonTestServer()
147 defer commonTs.Close()
148
149 correctEndpoint := fmt.Sprintf("%s/api", ts.URL)
150 testClient := NewRateLimitedHTTPClient()
151
152 t.Run("success", func(t *testing.T) {
153 err := Signout(context.DnoteCtx{SessionKey: "somekey", APIEndpoint: correctEndpoint, HTTPClient: testClient}, "alice@example.com")
154 if err != nil {
155 t.Errorf("got signout request error: %+v", err.Error())
156 }
157 })
158
159 t.Run("server error", func(t *testing.T) {
160 endpoint := fmt.Sprintf("%s/bad-api", commonTs.URL)
161 err := Signout(context.DnoteCtx{SessionKey: "somekey", APIEndpoint: endpoint, HTTPClient: testClient}, "alice@example.com")
162 if err == nil {
163 t.Error("error should have been returned")
164 }
165 })
166
167 t.Run("accidentally pointing to a catch-all handler", func(t *testing.T) {
168 endpoint := fmt.Sprintf("%s", commonTs.URL)
169 err := Signout(context.DnoteCtx{SessionKey: "somekey", APIEndpoint: endpoint, HTTPClient: testClient}, "alice@example.com")
170
171 assert.Equal(t, errors.Cause(err), ErrContentTypeMismatch, "error cause mismatch")
172 })
173
174 // Gracefully handle a case where http client was not initialized in the context.
175 t.Run("nil HTTPClient", func(t *testing.T) {
176 err := Signout(context.DnoteCtx{SessionKey: "somekey", APIEndpoint: correctEndpoint}, "alice@example.com")
177 if err != nil {
178 t.Errorf("got signout request error: %+v", err.Error())
179 }
180 })
181}
182
183func TestRateLimitedTransport(t *testing.T) {
184 var requestCount atomic.Int32

Callers

nothing calls this directly

Calls 7

EqualFunction · 0.92
startCommonTestServerFunction · 0.85
NewRateLimitedHTTPClientFunction · 0.85
SignoutFunction · 0.85
WriteHeaderMethod · 0.80
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected