-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor fixes add not implemented comment to sns model reset tests affecting new tests add debug message when listing sns topics remove merge remnants, minor fixups update listtopics test to handle new mock config
- Loading branch information
1 parent
233c2ed
commit 150a02b
Showing
12 changed files
with
326 additions
and
77 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package gosns | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/google/uuid" | ||
|
||
"github.com/Admiral-Piett/goaws/app" | ||
"github.com/Admiral-Piett/goaws/app/models" | ||
"github.com/Admiral-Piett/goaws/app/utils" | ||
|
||
"github.com/Admiral-Piett/goaws/app/interfaces" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func ListTopicsV1(req *http.Request) (int, interfaces.AbstractResponseBody) { | ||
requestBody := models.NewListTopicsRequest() | ||
ok := utils.REQUEST_TRANSFORMER(requestBody, req, false) | ||
if !ok { | ||
log.Error("Invalid Request - ListTopicsV1") | ||
return utils.CreateErrorResponseV1("InvalidParameterValue", false) | ||
} | ||
|
||
log.Debug("Listing Topics") | ||
arnList := make([]models.TopicArnResult, 0) | ||
|
||
for _, topic := range app.SyncTopics.Topics { | ||
ta := models.TopicArnResult{TopicArn: topic.Arn} | ||
arnList = append(arnList, ta) | ||
} | ||
|
||
requestId := uuid.NewString() | ||
respStruct := models.ListTopicsResponse{ | ||
Xmlns: models.BASE_XMLNS, | ||
Result: models.ListTopicsResult{Topics: models.TopicNamestype{Member: arnList}}, | ||
Metadata: app.ResponseMetadata{RequestId: requestId}, | ||
} | ||
|
||
return http.StatusOK, respStruct | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package gosns | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/Admiral-Piett/goaws/app/conf" | ||
"github.com/Admiral-Piett/goaws/app/interfaces" | ||
"github.com/Admiral-Piett/goaws/app/models" | ||
"github.com/Admiral-Piett/goaws/app/test" | ||
"github.com/Admiral-Piett/goaws/app/utils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestListTopicsV1_NoTopics(t *testing.T) { | ||
conf.LoadYamlConfig("../conf/mock-data/mock-config.yaml", "NoQueuesOrTopics") | ||
defer func() { | ||
test.ResetApp() | ||
utils.REQUEST_TRANSFORMER = utils.TransformRequest | ||
}() | ||
|
||
utils.REQUEST_TRANSFORMER = func(resultingStruct interfaces.AbstractRequestBody, req *http.Request, emptyRequestValid bool) (success bool) { | ||
v := resultingStruct.(*models.ListTopicsRequest) | ||
*v = models.ListTopicsRequest{ | ||
NextToken: "", | ||
} | ||
return true | ||
} | ||
|
||
_, r := test.GenerateRequestInfo("POST", "/", nil, true) | ||
code, res := ListTopicsV1(r) | ||
|
||
response, _ := res.(models.ListTopicsResponse) | ||
|
||
assert.Equal(t, http.StatusOK, code) | ||
assert.Equal(t, models.BASE_XMLNS, response.Xmlns) | ||
assert.NotEqual(t, "", response.Metadata) | ||
|
||
assert.Len(t, response.Result.Topics.Member, 0) | ||
} | ||
|
||
func TestListTopicsV1_BaseTopics(t *testing.T) { | ||
conf.LoadYamlConfig("../conf/mock-data/mock-config.yaml", "BaseUnitTests") | ||
defer func() { | ||
test.ResetApp() | ||
utils.REQUEST_TRANSFORMER = utils.TransformRequest | ||
}() | ||
|
||
utils.REQUEST_TRANSFORMER = func(resultingStruct interfaces.AbstractRequestBody, req *http.Request, emptyRequestValid bool) (success bool) { | ||
v := resultingStruct.(*models.ListTopicsRequest) | ||
*v = models.ListTopicsRequest{ | ||
NextToken: "", | ||
} | ||
return true | ||
} | ||
|
||
_, r := test.GenerateRequestInfo("POST", "/", nil, true) | ||
code, res := ListTopicsV1(r) | ||
|
||
response, _ := res.(models.ListTopicsResponse) | ||
|
||
assert.Equal(t, http.StatusOK, code) | ||
assert.Equal(t, models.BASE_XMLNS, response.Xmlns) | ||
assert.NotEqual(t, "", response.Metadata) | ||
|
||
assert.Len(t, response.Result.Topics.Member, 4) | ||
|
||
topicArnVisited := map[string]bool{} | ||
|
||
for _, member := range response.Result.Topics.Member { | ||
_, ok := topicArnVisited[member.TopicArn] | ||
assert.False(t, ok, fmt.Sprintf("Found duplicated listed arn entry: %s", member.TopicArn)) | ||
topicArnVisited[member.TopicArn] = true | ||
} | ||
} | ||
|
||
func TestListTopicsV1_request_transformer_error(t *testing.T) { | ||
conf.LoadYamlConfig("../conf/mock-data/mock-config.yaml", "BaseUnitTests") | ||
defer func() { | ||
test.ResetApp() | ||
utils.REQUEST_TRANSFORMER = utils.TransformRequest | ||
}() | ||
|
||
utils.REQUEST_TRANSFORMER = func(resultingStruct interfaces.AbstractRequestBody, req *http.Request, emptyRequestValid bool) (success bool) { | ||
return false | ||
} | ||
|
||
_, r := test.GenerateRequestInfo("POST", "/", nil, true) | ||
code, _ := ListTopicsV1(r) | ||
|
||
assert.Equal(t, http.StatusBadRequest, code) | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.