-
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.
Merge branch 'feature-aws-json' into SNS-PublishBatch
- Loading branch information
Showing
10 changed files
with
383 additions
and
94 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 ListSubscriptionsV1(req *http.Request) (int, interfaces.AbstractResponseBody) { | ||
requestBody := models.NewListSubscriptionsRequest() | ||
ok := utils.REQUEST_TRANSFORMER(requestBody, req, false) | ||
if !ok { | ||
log.Error("Invalid Request - ListSubscriptionsV1") | ||
return utils.CreateErrorResponseV1("InvalidParameterValue", false) | ||
} | ||
|
||
log.Debug("Listing Subscriptions") | ||
requestId := uuid.NewString() | ||
respStruct := models.ListSubscriptionsResponse{} | ||
respStruct.Xmlns = models.BASE_XMLNS | ||
respStruct.Metadata.RequestId = requestId | ||
respStruct.Result.Subscriptions.Member = make([]models.TopicMemberResult, 0) | ||
|
||
for _, topic := range app.SyncTopics.Topics { | ||
for _, sub := range topic.Subscriptions { | ||
tar := models.TopicMemberResult{TopicArn: topic.Arn, Protocol: sub.Protocol, | ||
SubscriptionArn: sub.SubscriptionArn, Endpoint: sub.EndPoint, Owner: app.CurrentEnvironment.AccountID} | ||
respStruct.Result.Subscriptions.Member = append(respStruct.Result.Subscriptions.Member, tar) | ||
} | ||
} | ||
|
||
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,85 @@ | ||
package gosns | ||
|
||
import ( | ||
"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 TestListSubcriptionsV1_NoSubscriptions(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.ListSubscriptionsRequest) | ||
*v = models.ListSubscriptionsRequest{ | ||
NextToken: "", | ||
} | ||
return true | ||
} | ||
|
||
_, r := test.GenerateRequestInfo("POST", "/", nil, true) | ||
code, res := ListSubscriptionsV1(r) | ||
|
||
response, _ := res.(models.ListSubscriptionsResponse) | ||
|
||
assert.Equal(t, http.StatusOK, code) | ||
assert.Equal(t, models.BASE_XMLNS, response.Xmlns) | ||
assert.NotEqual(t, "", response.Metadata) | ||
|
||
assert.Len(t, response.Result.Subscriptions.Member, 0) | ||
} | ||
|
||
func TestListSubcriptionsV1_MultipleSubscriptions(t *testing.T) { | ||
conf.LoadYamlConfig("../conf/mock-data/mock-config.yaml", "Local") | ||
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.ListSubscriptionsRequest) | ||
*v = models.ListSubscriptionsRequest{ | ||
NextToken: "", | ||
} | ||
return true | ||
} | ||
|
||
_, r := test.GenerateRequestInfo("POST", "/", nil, true) | ||
code, res := ListSubscriptionsV1(r) | ||
|
||
response, _ := res.(models.ListSubscriptionsResponse) | ||
|
||
assert.Equal(t, http.StatusOK, code) | ||
assert.Equal(t, models.BASE_XMLNS, response.Xmlns) | ||
assert.NotEqual(t, "", response.Metadata) | ||
|
||
assert.Len(t, response.Result.Subscriptions.Member, 2) | ||
assert.NotEqual(t, response.Result.Subscriptions.Member[0].SubscriptionArn, response.Result.Subscriptions.Member[1].SubscriptionArn) | ||
} | ||
|
||
func TestListSubscriptionsV1_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, _ := ListSubscriptionsV1(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
Oops, something went wrong.