|
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