Last active
October 26, 2022 02:38
-
-
Save marcel-dempers/20db9822f14675171a6d2a2334f3c4d0 to your computer and use it in GitHub Desktop.
Mock server for load testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang:1.11.10-alpine3.9 as builder | |
# installing git | |
RUN apk update && apk upgrade && \ | |
apk add --no-cache git | |
# setting working directory | |
WORKDIR /go/src/app | |
# installing dependencies | |
RUN go get github.com/sirupsen/logrus | |
RUN go get github.com/buaazp/fasthttprouter | |
RUN go get github.com/valyala/fasthttp | |
COPY / /go/src/app/ | |
RUN go build -o mock | |
FROM alpine:3.9 | |
WORKDIR /go/src/app | |
COPY --from=builder /go/src/app/mock /go/src/app/mock | |
COPY *.json /app/mocks/ | |
EXPOSE 80 | |
CMD ["./mock"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"time" | |
"io/ioutil" | |
"log" | |
"github.com/buaazp/fasthttprouter" | |
"github.com/valyala/fasthttp" | |
) | |
var searchMock []byte | |
func Mock(ctx *fasthttp.RequestCtx) { | |
fmt.Println("mocked!") | |
ctx.Response.Header.Set("Content-Type", "application/json") | |
time.Sleep(700 * time.Millisecond) | |
ctx.Write(searchMock); | |
} | |
func main() { | |
m, e := ioutil.ReadFile("/app/mocks/response.json") | |
if e != nil { | |
fmt.Printf("Error reading mock file: %v\n", e) | |
os.Exit(1) | |
} | |
searchMock = m | |
fmt.Println("starting...") | |
router := fasthttprouter.New() | |
router.POST("/", Mock) | |
log.Fatal(fasthttp.ListenAndServe(":80", router.Handler)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"glossary": { | |
"title": "example glossary", | |
"GlossDiv": { | |
"title": "S", | |
"GlossList": { | |
"GlossEntry": { | |
"ID": "SGML", | |
"SortAs": "SGML", | |
"GlossTerm": "Standard Generalized Markup Language", | |
"Acronym": "SGML", | |
"Abbrev": "ISO 8879:1986", | |
"GlossDef": { | |
"para": "A meta-markup language, used to create markup languages such as DocBook.", | |
"GlossSeeAlso": ["GML", "XML"] | |
}, | |
"GlossSee": "markup" | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment