File tree Expand file tree Collapse file tree 3 files changed +55
-3
lines changed Expand file tree Collapse file tree 3 files changed +55
-3
lines changed Original file line number Diff line number Diff line change 1
- # speakeasy-auth-test-service
1
+ # speakeasy-api-test-service
2
+
3
+ This is a service designed to be built into a docker container and used along the test suite in the ` openapi-generation ` repo.
4
+
5
+ This will eventually replace our usage of ` httpbin ` as a test service, and contain tailor made endpoints for testing the generated SDKs.
Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
- "github.com/speakeasy-api/speakeasy-auth-test-service/internal/pagination"
5
- "github.com/speakeasy-api/speakeasy-auth-test-service/internal/responseHeaders"
6
4
"log"
7
5
"net/http"
8
6
7
+ "github.com/speakeasy-api/speakeasy-auth-test-service/internal/pagination"
8
+ "github.com/speakeasy-api/speakeasy-auth-test-service/internal/responseHeaders"
9
+ "github.com/speakeasy-api/speakeasy-auth-test-service/internal/retries"
10
+
9
11
"github.com/gorilla/mux"
10
12
"github.com/speakeasy-api/speakeasy-auth-test-service/internal/auth"
11
13
"github.com/speakeasy-api/speakeasy-auth-test-service/internal/requestbody"
@@ -22,6 +24,7 @@ func main() {
22
24
r .HandleFunc ("/pagination/limitoffset/page" , pagination .HandleLimitOffsetPage ).Methods (http .MethodGet , http .MethodPut )
23
25
r .HandleFunc ("/pagination/limitoffset/offset" , pagination .HandleLimitOffsetOffset ).Methods (http .MethodGet , http .MethodPut )
24
26
r .HandleFunc ("/pagination/cursor" , pagination .HandleCursor ).Methods (http .MethodGet , http .MethodPut )
27
+ r .HandleFunc ("/retries" , retries .HandleRetries ).Methods (http .MethodGet )
25
28
26
29
log .Println ("Listening on :8080" )
27
30
if err := http .ListenAndServe (":8080" , r ); err != nil {
Original file line number Diff line number Diff line change
1
+ package retries
2
+
3
+ import (
4
+ "net/http"
5
+ "strconv"
6
+ )
7
+
8
+ var callCounts = map [string ]int {}
9
+
10
+ func HandleRetries (w http.ResponseWriter , r * http.Request ) {
11
+ requestID := r .URL .Query ().Get ("request-id" )
12
+ numRetriesStr := r .URL .Query ().Get ("num-retries" )
13
+
14
+ numRetries := 3
15
+ if numRetriesStr != "" {
16
+ var err error
17
+ numRetries , err = strconv .Atoi (numRetriesStr )
18
+ if err != nil {
19
+ w .WriteHeader (http .StatusBadRequest )
20
+ _ , _ = w .Write ([]byte ("num-retries must be an integer" ))
21
+ return
22
+ }
23
+ }
24
+
25
+ if requestID == "" {
26
+ w .WriteHeader (http .StatusBadRequest )
27
+ _ , _ = w .Write ([]byte ("request-id is required" ))
28
+ return
29
+ }
30
+
31
+ _ , ok := callCounts [requestID ]
32
+ if ! ok {
33
+ callCounts [requestID ] = 0
34
+ }
35
+ callCounts [requestID ]++
36
+
37
+ if callCounts [requestID ] < numRetries {
38
+ w .WriteHeader (http .StatusInternalServerError )
39
+ _ , _ = w .Write ([]byte ("request failed please retry" ))
40
+ return
41
+ }
42
+
43
+ delete (callCounts , requestID )
44
+ w .WriteHeader (http .StatusOK )
45
+ }
You can’t perform that action at this time.
0 commit comments