Skip to content

Commit

Permalink
Finish CreateQueueV1
Browse files Browse the repository at this point in the history
  • Loading branch information
dhumphreys01 committed Mar 5, 2024
1 parent 1babc4e commit fa5ea7b
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 37 deletions.
3 changes: 3 additions & 0 deletions app/fixtures/fixtures.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package fixtures

var BASE_URL = "http://region.host:port/accountID"
var BASE_ARN = "arn:aws:sqs:region:accountID"

var XMLNS = "http://queue.amazonaws.com/doc/2012-11-05/"
var REQUEST_ID = "request-id"
1 change: 1 addition & 0 deletions app/gosqs/gosqs.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ func GetQueueAttributes(w http.ResponseWriter, req *http.Request) {
attribs = append(attribs, attr)
}

// TODO - why do we just return the name and NOT the actual ARN here?
deadLetterTargetArn := ""
if queue.DeadLetterQueue != nil {
deadLetterTargetArn = queue.DeadLetterQueue.Name
Expand Down
1 change: 0 additions & 1 deletion app/models/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strconv"
)

// TODO - test me
// StringToInt this is a custom type that will allow our request bodies to support either a string OR an int.
// It has its own UnmarshalJSON method to handle both types automatically and it can return an `int`
// from the `Int` method.
Expand Down
18 changes: 18 additions & 0 deletions app/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,21 @@ type RedrivePolicy struct {
MaxReceiveCount StringToInt `json:"maxReceiveCount"`
DeadLetterTargetArn string `json:"deadLetterTargetArn"`
}

// UnmarshalJSON this will convert a JSON string of a Redrive Policy sub-doc (escaped characters and all) or
// a regular json document into the appropriate resulting struct.
func (r *RedrivePolicy) UnmarshalJSON(data []byte) error {
type basicRequest RedrivePolicy

err := json.Unmarshal(data, (*basicRequest)(r))
if err == nil {
return nil
}

tmp, _ := strconv.Unquote(string(data))
err = json.Unmarshal([]byte(tmp), (*basicRequest)(r))
if err != nil {
return err
}
return nil
}
51 changes: 51 additions & 0 deletions app/models/models_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package models

import (
"encoding/json"
"fmt"
"net/url"
"testing"

Expand Down Expand Up @@ -175,3 +177,52 @@ func TestCreateQueueRequest_SetAttributesFromForm_success_skips_invalid_values(t
assert.Equal(t, RedrivePolicy{}, cqr.Attributes.RedrivePolicy)
assert.Equal(t, map[string]interface{}(nil), cqr.Attributes.RedriveAllowPolicy)
}

func TestRedrivePolicy_UnmarshalJSON_handles_nested_json(t *testing.T) {
request := struct {
MaxReceiveCount int `json:"maxReceiveCount"`
DeadLetterTargetArn string `json:"deadLetterTargetArn"`
}{
MaxReceiveCount: 100,
DeadLetterTargetArn: "arn:redrive-queue",
}
b, _ := json.Marshal(request)
var r = RedrivePolicy{}
err := r.UnmarshalJSON(b)

assert.Nil(t, err)
assert.Equal(t, StringToInt(100), r.MaxReceiveCount)
assert.Equal(t, fmt.Sprintf("%s:%s", "arn", "redrive-queue"), r.DeadLetterTargetArn)
}

func TestRedrivePolicy_UnmarshalJSON_handles_escaped_string(t *testing.T) {
request := `{"maxReceiveCount":"100","deadLetterTargetArn":"arn:redrive-queue"}`
b, _ := json.Marshal(request)
var r = RedrivePolicy{}
err := r.UnmarshalJSON(b)

assert.Nil(t, err)
assert.Equal(t, StringToInt(100), r.MaxReceiveCount)
assert.Equal(t, fmt.Sprintf("%s:%s", "arn", "redrive-queue"), r.DeadLetterTargetArn)
}

func TestRedrivePolicy_UnmarshalJSON_invalid_json_request_returns_error(t *testing.T) {
request := fmt.Sprintf(`{\"maxReceiveCount\":\"100\",\"deadLetterTargetArn\":\"arn:redrive-queue\"}`)
var r = RedrivePolicy{}
err := r.UnmarshalJSON([]byte(request))

assert.Error(t, err)
assert.Equal(t, StringToInt(0), r.MaxReceiveCount)
assert.Equal(t, "", r.DeadLetterTargetArn)
}

func TestRedrivePolicy_UnmarshalJSON_invalid_type_returns_error(t *testing.T) {
request := `{"maxReceiveCount":true,"deadLetterTargetArn":"arn:redrive-queue"}`
b, _ := json.Marshal(request)
var r = RedrivePolicy{}
err := r.UnmarshalJSON(b)

assert.Error(t, err)
assert.Equal(t, StringToInt(0), r.MaxReceiveCount)
assert.Equal(t, "", r.DeadLetterTargetArn)
}
25 changes: 25 additions & 0 deletions app/utils/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ package utils

import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
urlLib "net/url"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"

"github.com/Admiral-Piett/goaws/app"
)

Expand Down Expand Up @@ -57,3 +63,22 @@ func GenerateRequestInfo(method, url string, body interface{}, isJson bool) (*ht
rr := httptest.NewRecorder()
return rr, req
}

// GenerateLocalProxyConfig use this to create AWS config that can be plugged into your sqs client, and
// force calls onto a local proxy. This is helpful for testing directly with an HTTP inspection tool
// such as Charles or Proxyman.
func GenerateLocalProxyConfig(proxyPort int) aws.Config {
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: false,
},
}
proxyURL, _ := urlLib.Parse(fmt.Sprintf("http://127.0.0.1:%d", proxyPort))
tr.Proxy = http.ProxyURL(proxyURL)
client := &http.Client{Transport: tr}

sdkConfig, _ := config.LoadDefaultConfig(context.TODO(),
config.WithHTTPClient(client),
)
return sdkConfig
}
15 changes: 14 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ go 1.18

require (
github.com/aws/aws-sdk-go v1.47.3
github.com/aws/aws-sdk-go-v2 v1.25.2
github.com/aws/aws-sdk-go-v2/config v1.27.4
github.com/aws/aws-sdk-go-v2/service/sqs v1.31.1
github.com/gavv/httpexpect/v2 v2.16.0
github.com/ghodss/yaml v1.0.0
github.com/gorilla/mux v1.8.0
Expand All @@ -17,6 +20,17 @@ require (
github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2 // indirect
github.com/ajg/form v1.5.1 // indirect
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.4 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.20.1 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.28.1 // indirect
github.com/aws/smithy-go v1.20.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
Expand All @@ -35,7 +49,6 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sanity-io/litter v1.5.5 // indirect
github.com/sergi/go-diff v1.0.0 // indirect
github.com/stretchr/objx v0.1.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.34.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
Expand Down
31 changes: 29 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,34 @@ github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/aws/aws-sdk-go v1.47.3 h1:e0H6NFXiniCpR8Lu3lTphVdRaeRCDLAeRyTHd1tJSd8=
github.com/aws/aws-sdk-go v1.47.3/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go-v2 v1.25.2 h1:/uiG1avJRgLGiQM9X3qJM8+Qa6KRGK5rRPuXE0HUM+w=
github.com/aws/aws-sdk-go-v2 v1.25.2/go.mod h1:Evoc5AsmtveRt1komDwIsjHFyrP5tDuF1D1U+6z6pNo=
github.com/aws/aws-sdk-go-v2/config v1.27.4 h1:AhfWb5ZwimdsYTgP7Od8E9L1u4sKmDW2ZVeLcf2O42M=
github.com/aws/aws-sdk-go-v2/config v1.27.4/go.mod h1:zq2FFXK3A416kiukwpsd+rD4ny6JC7QSkp4QdN1Mp2g=
github.com/aws/aws-sdk-go-v2/credentials v1.17.4 h1:h5Vztbd8qLppiPwX+y0Q6WiwMZgpd9keKe2EAENgAuI=
github.com/aws/aws-sdk-go-v2/credentials v1.17.4/go.mod h1:+30tpwrkOgvkJL1rUZuRLoxcJwtI/OkeBLYnHxJtVe0=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.2 h1:AK0J8iYBFeUk2Ax7O8YpLtFsfhdOByh2QIkHmigpRYk=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.2/go.mod h1:iRlGzMix0SExQEviAyptRWRGdYNo3+ufW/lCzvKVTUc=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.2 h1:bNo4LagzUKbjdxE0tIcR9pMzLR2U/Tgie1Hq1HQ3iH8=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.2/go.mod h1:wRQv0nN6v9wDXuWThpovGQjqF1HFdcgWjporw14lS8k=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.2 h1:EtOU5jsPdIQNP+6Q2C5e3d65NKT1PeCiQk+9OdzO12Q=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.2/go.mod h1:tyF5sKccmDz0Bv4NrstEr+/9YkSPJHrcO7UsUKf7pWM=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1 h1:EyBZibRTVAs6ECHZOw5/wlylS9OcTzwyjeQMudmREjE=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1/go.mod h1:JKpmtYhhPs7D97NL/ltqz7yCkERFW5dOlHyVl66ZYF8=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.2 h1:5ffmXjPtwRExp1zc7gENLgCPyHFbhEPwVTkTiH9niSk=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.2/go.mod h1:Ru7vg1iQ7cR4i7SZ/JTLYN9kaXtbL69UdgG0OQWQxW0=
github.com/aws/aws-sdk-go-v2/service/sqs v1.31.1 h1:124rVNP6NbCfBZwiX1kfjMQrnsJtnpKeB0GalkuqSXo=
github.com/aws/aws-sdk-go-v2/service/sqs v1.31.1/go.mod h1:YijRvM1SAmuiIQ9pjfwahIEE3HMHUkx9P5oplL/Jnj4=
github.com/aws/aws-sdk-go-v2/service/sso v1.20.1 h1:utEGkfdQ4L6YW/ietH7111ZYglLJvS+sLriHJ1NBJEQ=
github.com/aws/aws-sdk-go-v2/service/sso v1.20.1/go.mod h1:RsYqzYr2F2oPDdpy+PdhephuZxTfjHQe7SOBcZGoAU8=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.1 h1:9/GylMS45hGGFCcMrUZDVayQE1jYSIN6da9jo7RAYIw=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.1/go.mod h1:YjAPFn4kGFqKC54VsHs5fn5B6d+PCY2tziEa3U/GB5Y=
github.com/aws/aws-sdk-go-v2/service/sts v1.28.1 h1:3I2cBEYgKhrWlwyZgfpSO2BpaMY1LHPqXYk/QGlu2ew=
github.com/aws/aws-sdk-go-v2/service/sts v1.28.1/go.mod h1:uQ7YYKZt3adCRrdCBREm1CD3efFLOUNH77MrUCvx5oA=
github.com/aws/smithy-go v1.20.1 h1:4SZlSlMr36UEqC7XOyRVb27XMeZubNcBNN+9IgEPIQw=
github.com/aws/smithy-go v1.20.1/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E=
github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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=
Expand All @@ -20,8 +48,8 @@ github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
Expand Down Expand Up @@ -69,7 +97,6 @@ github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand Down
3 changes: 0 additions & 3 deletions smoke_tests/fixtures/fixtures.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
package fixtures

var REQUEST_ID = "00000000-0000-0000-0000-000000000000"

var BASE_URL = "http://region.host:port/accountID"
var BASE_ARN = "arn:aws:sqs:region:accountID"
2 changes: 1 addition & 1 deletion smoke_tests/fixtures/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var GetQueueAttributesRequestBodyXML = struct {
Action: "GetQueueAttributes",
Version: "2012-11-05",
Attribute1: "All",
QueueUrl: fmt.Sprintf("%s/new-queue-1", BASE_URL),
QueueUrl: fmt.Sprintf("%s/new-queue-1", af.BASE_URL),
}

var CreateQueueV1RequestBodyJSON = models.CreateQueueRequest{
Expand Down
4 changes: 3 additions & 1 deletion smoke_tests/fixtures/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package fixtures
import (
"fmt"

af "github.com/Admiral-Piett/goaws/app/fixtures"

"github.com/Admiral-Piett/goaws/app"
)

Expand Down Expand Up @@ -39,7 +41,7 @@ var BASE_GET_QUEUE_ATTRIBUTES_RESPONSE = app.GetQueueAttributesResponse{
},
{
Name: "QueueArn",
Value: fmt.Sprintf("%s:new-queue-1", BASE_ARN),
Value: fmt.Sprintf("%s:new-queue-1", af.BASE_ARN),
},
{
Name: "RedrivePolicy",
Expand Down
Loading

0 comments on commit fa5ea7b

Please sign in to comment.