Skip to content

Commit 3e612da

Browse files
dhumphreys01Admiral-Piett
authored andcommitted
Add PublishBatch for AWS JSON
1 parent 4e06d3d commit 3e612da

32 files changed

+3406
-1809
lines changed

app/gosns/delete_topic.go

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
1-
package gosns
2-
3-
import (
4-
"net/http"
5-
"strings"
6-
7-
"github.com/Admiral-Piett/goaws/app"
8-
"github.com/Admiral-Piett/goaws/app/common"
9-
"github.com/Admiral-Piett/goaws/app/interfaces"
10-
"github.com/Admiral-Piett/goaws/app/models"
11-
"github.com/Admiral-Piett/goaws/app/utils"
12-
13-
log "github.com/sirupsen/logrus"
14-
)
15-
16-
func DeleteTopicV1(req *http.Request) (int, interfaces.AbstractResponseBody) {
17-
requestBody := models.NewDeleteTopicRequest()
18-
ok := utils.REQUEST_TRANSFORMER(requestBody, req, false)
19-
if !ok {
20-
log.Error("Invalid Request - DeleteTopicV1")
21-
return utils.CreateErrorResponseV1("InvalidParameterValue", false)
22-
}
23-
24-
topicArn := requestBody.TopicArn
25-
uriSegments := strings.Split(topicArn, ":")
26-
topicName := uriSegments[len(uriSegments)-1]
27-
28-
log.Info("Delete Topic - TopicName:", topicName)
29-
30-
_, ok = app.SyncTopics.Topics[topicName]
31-
32-
if !ok {
33-
return utils.CreateErrorResponseV1("TopicNotFound", false)
34-
}
35-
36-
app.SyncTopics.Lock()
37-
delete(app.SyncTopics.Topics, topicName)
38-
app.SyncTopics.Unlock()
39-
uuid, _ := common.NewUUID()
40-
respStruct := models.DeleteTopicResponse{
41-
Xmlns: "http://queue.amazonaws.com/doc/2012-11-05/",
42-
Metadata: app.ResponseMetadata{RequestId: uuid},
43-
}
44-
45-
return http.StatusOK, respStruct
46-
47-
}
1+
package gosns
2+
3+
import (
4+
"net/http"
5+
"strings"
6+
7+
"github.com/Admiral-Piett/goaws/app"
8+
"github.com/Admiral-Piett/goaws/app/common"
9+
"github.com/Admiral-Piett/goaws/app/interfaces"
10+
"github.com/Admiral-Piett/goaws/app/models"
11+
"github.com/Admiral-Piett/goaws/app/utils"
12+
13+
log "github.com/sirupsen/logrus"
14+
)
15+
16+
func DeleteTopicV1(req *http.Request) (int, interfaces.AbstractResponseBody) {
17+
requestBody := models.NewDeleteTopicRequest()
18+
ok := utils.REQUEST_TRANSFORMER(requestBody, req, false)
19+
if !ok {
20+
log.Error("Invalid Request - DeleteTopicV1")
21+
return utils.CreateErrorResponseV1("InvalidParameterValue", false)
22+
}
23+
24+
topicArn := requestBody.TopicArn
25+
uriSegments := strings.Split(topicArn, ":")
26+
topicName := uriSegments[len(uriSegments)-1]
27+
28+
log.Info("Delete Topic - TopicName:", topicName)
29+
30+
_, ok = app.SyncTopics.Topics[topicName]
31+
32+
if !ok {
33+
return utils.CreateErrorResponseV1("TopicNotFound", false)
34+
}
35+
36+
app.SyncTopics.Lock()
37+
delete(app.SyncTopics.Topics, topicName)
38+
app.SyncTopics.Unlock()
39+
uuid, _ := common.NewUUID()
40+
respStruct := models.DeleteTopicResponse{
41+
Xmlns: "http://queue.amazonaws.com/doc/2012-11-05/",
42+
Metadata: app.ResponseMetadata{RequestId: uuid},
43+
}
44+
45+
return http.StatusOK, respStruct
46+
47+
}

app/gosns/delete_topic_test.go

Lines changed: 88 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,88 @@
1-
package gosns
2-
3-
import (
4-
"net/http"
5-
"testing"
6-
7-
"github.com/Admiral-Piett/goaws/app"
8-
"github.com/Admiral-Piett/goaws/app/conf"
9-
"github.com/Admiral-Piett/goaws/app/interfaces"
10-
"github.com/Admiral-Piett/goaws/app/models"
11-
"github.com/Admiral-Piett/goaws/app/test"
12-
"github.com/Admiral-Piett/goaws/app/utils"
13-
"github.com/stretchr/testify/assert"
14-
)
15-
16-
func TestDeleteTopicV1_Success(t *testing.T) {
17-
conf.LoadYamlConfig("../conf/mock-data/mock-config.yaml", "BaseUnitTests")
18-
defer func() {
19-
test.ResetApp()
20-
utils.REQUEST_TRANSFORMER = utils.TransformRequest
21-
}()
22-
23-
initial_num_topics := len(app.SyncTopics.Topics)
24-
25-
topicName1 := "unit-topic1"
26-
27-
utils.REQUEST_TRANSFORMER = func(resultingStruct interfaces.AbstractRequestBody, req *http.Request, emptyRequestValid bool) (success bool) {
28-
v := resultingStruct.(*models.DeleteTopicRequest)
29-
*v = models.DeleteTopicRequest{
30-
TopicArn: "arn:aws:sns:region:accountID:" + topicName1,
31-
}
32-
return true
33-
}
34-
35-
_, r := test.GenerateRequestInfo("POST", "/", nil, true)
36-
code, res := DeleteTopicV1(r)
37-
38-
response, _ := res.(models.DeleteTopicResponse)
39-
40-
assert.Equal(t, http.StatusOK, code)
41-
assert.Equal(t, models.BASE_XMLNS, response.Xmlns)
42-
assert.NotEqual(t, "", response.Metadata)
43-
44-
topics := app.SyncTopics.Topics
45-
assert.Equal(t, initial_num_topics-1, len(topics))
46-
_, ok := topics[topicName1]
47-
assert.False(t, ok)
48-
}
49-
50-
func TestDeleteTopicV1_NotFound(t *testing.T) {
51-
conf.LoadYamlConfig("../conf/mock-data/mock-config.yaml", "NoQueuesOrTopics")
52-
defer func() {
53-
test.ResetApp()
54-
utils.REQUEST_TRANSFORMER = utils.TransformRequest
55-
}()
56-
57-
utils.REQUEST_TRANSFORMER = func(resultingStruct interfaces.AbstractRequestBody, req *http.Request, emptyRequestValid bool) (success bool) {
58-
v := resultingStruct.(*models.DeleteTopicRequest)
59-
*v = models.DeleteTopicRequest{
60-
TopicArn: "asdf",
61-
}
62-
return true
63-
}
64-
65-
_, r := test.GenerateRequestInfo("POST", "/", nil, true)
66-
code, res := DeleteTopicV1(r)
67-
resp := res.(models.ErrorResponse)
68-
69-
assert.Equal(t, http.StatusBadRequest, code)
70-
assert.Equal(t, resp.Result.Type, "Not Found")
71-
}
72-
73-
func TestDeleteTopicV1_request_transformer_error(t *testing.T) {
74-
conf.LoadYamlConfig("../conf/mock-data/mock-config.yaml", "BaseUnitTests")
75-
defer func() {
76-
test.ResetApp()
77-
utils.REQUEST_TRANSFORMER = utils.TransformRequest
78-
}()
79-
80-
utils.REQUEST_TRANSFORMER = func(resultingStruct interfaces.AbstractRequestBody, req *http.Request, emptyRequestValid bool) (success bool) {
81-
return false
82-
}
83-
84-
_, r := test.GenerateRequestInfo("POST", "/", nil, true)
85-
code, _ := DeleteTopicV1(r)
86-
87-
assert.Equal(t, http.StatusBadRequest, code)
88-
}
1+
package gosns
2+
3+
import (
4+
"net/http"
5+
"testing"
6+
7+
"github.com/Admiral-Piett/goaws/app"
8+
"github.com/Admiral-Piett/goaws/app/conf"
9+
"github.com/Admiral-Piett/goaws/app/interfaces"
10+
"github.com/Admiral-Piett/goaws/app/models"
11+
"github.com/Admiral-Piett/goaws/app/test"
12+
"github.com/Admiral-Piett/goaws/app/utils"
13+
"github.com/stretchr/testify/assert"
14+
)
15+
16+
func TestDeleteTopicV1_Success(t *testing.T) {
17+
conf.LoadYamlConfig("../conf/mock-data/mock-config.yaml", "BaseUnitTests")
18+
defer func() {
19+
test.ResetApp()
20+
utils.REQUEST_TRANSFORMER = utils.TransformRequest
21+
}()
22+
23+
initial_num_topics := len(app.SyncTopics.Topics)
24+
25+
topicName1 := "unit-topic1"
26+
27+
utils.REQUEST_TRANSFORMER = func(resultingStruct interfaces.AbstractRequestBody, req *http.Request, emptyRequestValid bool) (success bool) {
28+
v := resultingStruct.(*models.DeleteTopicRequest)
29+
*v = models.DeleteTopicRequest{
30+
TopicArn: "arn:aws:sns:region:accountID:" + topicName1,
31+
}
32+
return true
33+
}
34+
35+
_, r := test.GenerateRequestInfo("POST", "/", nil, true)
36+
code, res := DeleteTopicV1(r)
37+
38+
response, _ := res.(models.DeleteTopicResponse)
39+
40+
assert.Equal(t, http.StatusOK, code)
41+
assert.Equal(t, models.BASE_XMLNS, response.Xmlns)
42+
assert.NotEqual(t, "", response.Metadata)
43+
44+
topics := app.SyncTopics.Topics
45+
assert.Equal(t, initial_num_topics-1, len(topics))
46+
_, ok := topics[topicName1]
47+
assert.False(t, ok)
48+
}
49+
50+
func TestDeleteTopicV1_NotFound(t *testing.T) {
51+
conf.LoadYamlConfig("../conf/mock-data/mock-config.yaml", "NoQueuesOrTopics")
52+
defer func() {
53+
test.ResetApp()
54+
utils.REQUEST_TRANSFORMER = utils.TransformRequest
55+
}()
56+
57+
utils.REQUEST_TRANSFORMER = func(resultingStruct interfaces.AbstractRequestBody, req *http.Request, emptyRequestValid bool) (success bool) {
58+
v := resultingStruct.(*models.DeleteTopicRequest)
59+
*v = models.DeleteTopicRequest{
60+
TopicArn: "asdf",
61+
}
62+
return true
63+
}
64+
65+
_, r := test.GenerateRequestInfo("POST", "/", nil, true)
66+
code, res := DeleteTopicV1(r)
67+
resp := res.(models.ErrorResponse)
68+
69+
assert.Equal(t, http.StatusBadRequest, code)
70+
assert.Equal(t, resp.Result.Type, "Not Found")
71+
}
72+
73+
func TestDeleteTopicV1_request_transformer_error(t *testing.T) {
74+
conf.LoadYamlConfig("../conf/mock-data/mock-config.yaml", "BaseUnitTests")
75+
defer func() {
76+
test.ResetApp()
77+
utils.REQUEST_TRANSFORMER = utils.TransformRequest
78+
}()
79+
80+
utils.REQUEST_TRANSFORMER = func(resultingStruct interfaces.AbstractRequestBody, req *http.Request, emptyRequestValid bool) (success bool) {
81+
return false
82+
}
83+
84+
_, r := test.GenerateRequestInfo("POST", "/", nil, true)
85+
code, _ := DeleteTopicV1(r)
86+
87+
assert.Equal(t, http.StatusBadRequest, code)
88+
}

0 commit comments

Comments
 (0)