-
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.
- Loading branch information
1 parent
4e06d3d
commit 3e612da
Showing
32 changed files
with
3,406 additions
and
1,809 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
package gosns | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/Admiral-Piett/goaws/app" | ||
"github.com/Admiral-Piett/goaws/app/common" | ||
"github.com/Admiral-Piett/goaws/app/interfaces" | ||
"github.com/Admiral-Piett/goaws/app/models" | ||
"github.com/Admiral-Piett/goaws/app/utils" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func DeleteTopicV1(req *http.Request) (int, interfaces.AbstractResponseBody) { | ||
requestBody := models.NewDeleteTopicRequest() | ||
ok := utils.REQUEST_TRANSFORMER(requestBody, req, false) | ||
if !ok { | ||
log.Error("Invalid Request - DeleteTopicV1") | ||
return utils.CreateErrorResponseV1("InvalidParameterValue", false) | ||
} | ||
|
||
topicArn := requestBody.TopicArn | ||
uriSegments := strings.Split(topicArn, ":") | ||
topicName := uriSegments[len(uriSegments)-1] | ||
|
||
log.Info("Delete Topic - TopicName:", topicName) | ||
|
||
_, ok = app.SyncTopics.Topics[topicName] | ||
|
||
if !ok { | ||
return utils.CreateErrorResponseV1("TopicNotFound", false) | ||
} | ||
|
||
app.SyncTopics.Lock() | ||
delete(app.SyncTopics.Topics, topicName) | ||
app.SyncTopics.Unlock() | ||
uuid, _ := common.NewUUID() | ||
respStruct := models.DeleteTopicResponse{ | ||
Xmlns: "http://queue.amazonaws.com/doc/2012-11-05/", | ||
Metadata: app.ResponseMetadata{RequestId: uuid}, | ||
} | ||
|
||
return http.StatusOK, respStruct | ||
|
||
} | ||
package gosns | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/Admiral-Piett/goaws/app" | ||
"github.com/Admiral-Piett/goaws/app/common" | ||
"github.com/Admiral-Piett/goaws/app/interfaces" | ||
"github.com/Admiral-Piett/goaws/app/models" | ||
"github.com/Admiral-Piett/goaws/app/utils" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func DeleteTopicV1(req *http.Request) (int, interfaces.AbstractResponseBody) { | ||
requestBody := models.NewDeleteTopicRequest() | ||
ok := utils.REQUEST_TRANSFORMER(requestBody, req, false) | ||
if !ok { | ||
log.Error("Invalid Request - DeleteTopicV1") | ||
return utils.CreateErrorResponseV1("InvalidParameterValue", false) | ||
} | ||
|
||
topicArn := requestBody.TopicArn | ||
uriSegments := strings.Split(topicArn, ":") | ||
topicName := uriSegments[len(uriSegments)-1] | ||
|
||
log.Info("Delete Topic - TopicName:", topicName) | ||
|
||
_, ok = app.SyncTopics.Topics[topicName] | ||
|
||
if !ok { | ||
return utils.CreateErrorResponseV1("TopicNotFound", false) | ||
} | ||
|
||
app.SyncTopics.Lock() | ||
delete(app.SyncTopics.Topics, topicName) | ||
app.SyncTopics.Unlock() | ||
uuid, _ := common.NewUUID() | ||
respStruct := models.DeleteTopicResponse{ | ||
Xmlns: "http://queue.amazonaws.com/doc/2012-11-05/", | ||
Metadata: app.ResponseMetadata{RequestId: uuid}, | ||
} | ||
|
||
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 |
---|---|---|
@@ -1,88 +1,88 @@ | ||
package gosns | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/Admiral-Piett/goaws/app" | ||
"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 TestDeleteTopicV1_Success(t *testing.T) { | ||
conf.LoadYamlConfig("../conf/mock-data/mock-config.yaml", "BaseUnitTests") | ||
defer func() { | ||
test.ResetApp() | ||
utils.REQUEST_TRANSFORMER = utils.TransformRequest | ||
}() | ||
|
||
initial_num_topics := len(app.SyncTopics.Topics) | ||
|
||
topicName1 := "unit-topic1" | ||
|
||
utils.REQUEST_TRANSFORMER = func(resultingStruct interfaces.AbstractRequestBody, req *http.Request, emptyRequestValid bool) (success bool) { | ||
v := resultingStruct.(*models.DeleteTopicRequest) | ||
*v = models.DeleteTopicRequest{ | ||
TopicArn: "arn:aws:sns:region:accountID:" + topicName1, | ||
} | ||
return true | ||
} | ||
|
||
_, r := test.GenerateRequestInfo("POST", "/", nil, true) | ||
code, res := DeleteTopicV1(r) | ||
|
||
response, _ := res.(models.DeleteTopicResponse) | ||
|
||
assert.Equal(t, http.StatusOK, code) | ||
assert.Equal(t, models.BASE_XMLNS, response.Xmlns) | ||
assert.NotEqual(t, "", response.Metadata) | ||
|
||
topics := app.SyncTopics.Topics | ||
assert.Equal(t, initial_num_topics-1, len(topics)) | ||
_, ok := topics[topicName1] | ||
assert.False(t, ok) | ||
} | ||
|
||
func TestDeleteTopicV1_NotFound(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.DeleteTopicRequest) | ||
*v = models.DeleteTopicRequest{ | ||
TopicArn: "asdf", | ||
} | ||
return true | ||
} | ||
|
||
_, r := test.GenerateRequestInfo("POST", "/", nil, true) | ||
code, res := DeleteTopicV1(r) | ||
resp := res.(models.ErrorResponse) | ||
|
||
assert.Equal(t, http.StatusBadRequest, code) | ||
assert.Equal(t, resp.Result.Type, "Not Found") | ||
} | ||
|
||
func TestDeleteTopicV1_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, _ := DeleteTopicV1(r) | ||
|
||
assert.Equal(t, http.StatusBadRequest, code) | ||
} | ||
package gosns | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/Admiral-Piett/goaws/app" | ||
"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 TestDeleteTopicV1_Success(t *testing.T) { | ||
conf.LoadYamlConfig("../conf/mock-data/mock-config.yaml", "BaseUnitTests") | ||
defer func() { | ||
test.ResetApp() | ||
utils.REQUEST_TRANSFORMER = utils.TransformRequest | ||
}() | ||
|
||
initial_num_topics := len(app.SyncTopics.Topics) | ||
|
||
topicName1 := "unit-topic1" | ||
|
||
utils.REQUEST_TRANSFORMER = func(resultingStruct interfaces.AbstractRequestBody, req *http.Request, emptyRequestValid bool) (success bool) { | ||
v := resultingStruct.(*models.DeleteTopicRequest) | ||
*v = models.DeleteTopicRequest{ | ||
TopicArn: "arn:aws:sns:region:accountID:" + topicName1, | ||
} | ||
return true | ||
} | ||
|
||
_, r := test.GenerateRequestInfo("POST", "/", nil, true) | ||
code, res := DeleteTopicV1(r) | ||
|
||
response, _ := res.(models.DeleteTopicResponse) | ||
|
||
assert.Equal(t, http.StatusOK, code) | ||
assert.Equal(t, models.BASE_XMLNS, response.Xmlns) | ||
assert.NotEqual(t, "", response.Metadata) | ||
|
||
topics := app.SyncTopics.Topics | ||
assert.Equal(t, initial_num_topics-1, len(topics)) | ||
_, ok := topics[topicName1] | ||
assert.False(t, ok) | ||
} | ||
|
||
func TestDeleteTopicV1_NotFound(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.DeleteTopicRequest) | ||
*v = models.DeleteTopicRequest{ | ||
TopicArn: "asdf", | ||
} | ||
return true | ||
} | ||
|
||
_, r := test.GenerateRequestInfo("POST", "/", nil, true) | ||
code, res := DeleteTopicV1(r) | ||
resp := res.(models.ErrorResponse) | ||
|
||
assert.Equal(t, http.StatusBadRequest, code) | ||
assert.Equal(t, resp.Result.Type, "Not Found") | ||
} | ||
|
||
func TestDeleteTopicV1_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, _ := DeleteTopicV1(r) | ||
|
||
assert.Equal(t, http.StatusBadRequest, code) | ||
} |
Oops, something went wrong.