Skip to content

Commit

Permalink
Generate new UID for each test run
Browse files Browse the repository at this point in the history
  • Loading branch information
Elliot Smith committed Nov 1, 2023
1 parent dd2e1a8 commit ca93d89
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ down: ## Stop application

test-api: ## Test the API endpoints
test-api: URL ?= http://localhost:9000
test-api: UID := $(shell ./signer/test-api UID)
test-api:
go build -o ./signer/test-api ./signer && \
chmod +x ./signer/test-api && \
./signer/test-api -expectedStatus=201 PUT $(URL)/lpas/{{UID}} '{"version":"1"}' && \
./signer/test-api -expectedStatus=400 PUT $(URL)/lpas/{{UID}} '{"version":"2"}' && \
./signer/test-api -expectedStatus=201 POST $(URL)/lpas/{{UID}}/updates '{"type":"BUMP_VERSION","changes":[{"key":"/version","old":"1","new":"2"}]}' && \
./signer/test-api -expectedStatus=200 GET $(URL)/lpas/{{UID}} '' | grep '"version":"2"' \
./signer/test-api -expectedStatus=201 REQUEST PUT $(URL)/lpas/$(UID) '{"version":"1"}' && \
./signer/test-api -expectedStatus=400 REQUEST PUT $(URL)/lpas/$(UID) '{"version":"2"}' && \
./signer/test-api -expectedStatus=201 REQUEST POST $(URL)/lpas/$(UID)/updates '{"type":"BUMP_VERSION","changes":[{"key":"/version","old":"1","new":"2"}]}' && \
./signer/test-api -expectedStatus=200 REQUEST GET $(URL)/lpas/$(UID) '' | grep '"version":"2"' \

create-tables:
docker compose run --rm aws dynamodb describe-table --table-name deeds || \
Expand Down
1 change: 1 addition & 0 deletions signer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ require github.com/aws/aws-sdk-go v1.46.6

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
)
2 changes: 2 additions & 0 deletions signer/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ github.com/aws/aws-sdk-go v1.46.6/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Ph
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
Expand Down
27 changes: 20 additions & 7 deletions signer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,43 @@ package main

import (
"flag"
"fmt"
"io"
"log"
"net/http"
"os"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws/session"
v4 "github.com/aws/aws-sdk-go/aws/signer/v4"
"github.com/google/uuid"
)

// call with UID to generate a UID, or with
// -expectedStatus=200 REQUEST <METHOD> <URL> <REQUEST BODY> to make a test request
func main() {
sess := session.Must(session.NewSession())
signer := v4.NewSigner(sess.Config.Credentials)

expectedStatusCode := flag.Int("expectedStatus", 200, "Expected response status code")
flag.Parse()

args := flag.Args()
method := args[0]

uid := "M-AL9A-7EY3-075D"
url := strings.Replace(args[1], "{{UID}}", uid, -1)
// early exit if we're just generating a UID
if args[0] == "UID" {
fmt.Print("M-" + strings.ToUpper(uuid.NewString()[9:23]))
os.Exit(0)
}

if args[0] != "REQUEST" {
panic("Unrecognised command")
}

sess := session.Must(session.NewSession())
signer := v4.NewSigner(sess.Config.Credentials)

body := strings.NewReader(args[2])
method := args[1]
url := args[2]
body := strings.NewReader(args[3])

req, err := http.NewRequest(method, url, body)
if err != nil {
Expand Down
Binary file removed signer/signer
Binary file not shown.

0 comments on commit ca93d89

Please sign in to comment.