Skip to content

Commit

Permalink
Include Owner value in Subscriptions and SubscriptionsByTopic responses
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdaly3 authored and Admiral-Piett committed Jan 9, 2024
1 parent a1441eb commit ba9b48a
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/gosns/gosns.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func ListSubscriptions(w http.ResponseWriter, req *http.Request) {
for _, topic := range app.SyncTopics.Topics {
for _, sub := range topic.Subscriptions {
tar := app.TopicMemberResult{TopicArn: topic.Arn, Protocol: sub.Protocol,
SubscriptionArn: sub.SubscriptionArn, Endpoint: sub.EndPoint}
SubscriptionArn: sub.SubscriptionArn, Endpoint: sub.EndPoint, Owner: app.CurrentEnvironment.AccountID}
respStruct.Result.Subscriptions.Member = append(respStruct.Result.Subscriptions.Member, tar)
}
}
Expand All @@ -330,7 +330,7 @@ func ListSubscriptionsByTopic(w http.ResponseWriter, req *http.Request) {

for _, sub := range topic.Subscriptions {
tar := app.TopicMemberResult{TopicArn: topic.Arn, Protocol: sub.Protocol,
SubscriptionArn: sub.SubscriptionArn, Endpoint: sub.EndPoint}
SubscriptionArn: sub.SubscriptionArn, Endpoint: sub.EndPoint, Owner: app.CurrentEnvironment.AccountID}
respStruct.Result.Subscriptions.Member = append(respStruct.Result.Subscriptions.Member, tar)
}
SendResponseBack(w, req, respStruct, content)
Expand Down
76 changes: 76 additions & 0 deletions app/gosns/gosns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,82 @@ func TestPublish_No_Queue_Error_handler_POST_Success(t *testing.T) {
}
}

func TestListSubscriptionByTopicResponse_No_Owner(t *testing.T) {

// set accountID to test value so it can be populated in response
app.CurrentEnvironment.AccountID = "100010001000"

// Create a request to pass to our handler. We don't have any query parameters for now, so we'll
// pass 'nil' as the third parameter.
req, err := http.NewRequest("POST", "/", nil)
if err != nil {
t.Fatal(err)
}

form := url.Values{}
form.Add("TopicArn", "arn:aws:sns:local:000000000000:UnitTestTopic1")
req.PostForm = form

// We create a ResponseRecorder (which satisfies http.ResponseWriter) to record the response.
rr := httptest.NewRecorder()
handler := http.HandlerFunc(ListSubscriptionsByTopic)

// Our handlers satisfy http.Handler, so we can call their ServeHTTP method
// directly and pass in our Request and ResponseRecorder.
handler.ServeHTTP(rr, req)

// Check the status code is what we expect.
if status := rr.Code; status != http.StatusOK {
t.Errorf("handler returned wrong status code: got %v want %v",
status, http.StatusOK)
}

// Check the response body is what we expect.
expected := `<Owner>` + app.CurrentEnvironment.AccountID + `</Owner>`
if !strings.Contains(rr.Body.String(), expected) {
t.Errorf("handler returned empty owner for subscription member: got %v want %v",
rr.Body.String(), expected)
}
}

func TestListSubscriptionsResponse_No_Owner(t *testing.T) {

// set accountID to test value so it can be populated in response
app.CurrentEnvironment.AccountID = "100010001000"

// Create a request to pass to our handler. We don't have any query parameters for now, so we'll
// pass 'nil' as the third parameter.
req, err := http.NewRequest("POST", "/", nil)
if err != nil {
t.Fatal(err)
}

form := url.Values{}
form.Add("TopicArn", "arn:aws:sns:local:000000000000:UnitTestTopic1")
req.PostForm = form

// We create a ResponseRecorder (which satisfies http.ResponseWriter) to record the response.
rr := httptest.NewRecorder()
handler := http.HandlerFunc(ListSubscriptions)

// Our handlers satisfy http.Handler, so we can call their ServeHTTP method
// directly and pass in our Request and ResponseRecorder.
handler.ServeHTTP(rr, req)

// Check the status code is what we expect.
if status := rr.Code; status != http.StatusOK {
t.Errorf("handler returned wrong status code: got %v want %v",
status, http.StatusOK)
}

// Check the response body is what we expect.
expected := `<Owner>` + app.CurrentEnvironment.AccountID + `</Owner>`
if !strings.Contains(rr.Body.String(), expected) {
t.Errorf("handler returned empty owner for subscription member: got %v want %v",
rr.Body.String(), expected)
}
}

func TestDeleteTopichandler_POST_Success(t *testing.T) {
// Create a request to pass to our handler. We don't have any query parameters for now, so we'll
// pass 'nil' as the third parameter.
Expand Down

0 comments on commit ba9b48a

Please sign in to comment.