Skip to content

Commit

Permalink
Merge pull request #3 from ocobleseqx/ecx_l2_conn_aside_servicetoken
Browse files Browse the repository at this point in the history
l2 connection - supported aside service token
  • Loading branch information
displague authored Feb 19, 2022
2 parents 614d5dc + 45139e6 commit bfa82b2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type L2Connection struct {
RedundantUUID *string
RedundancyType *string
Actions []L2ConnectionAction
ServiceToken *string
}

//L2ConnectionAdditionalInfo additional info object used in L2 connections
Expand Down
2 changes: 2 additions & 0 deletions internal/api/l2_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type L2ConnectionResponse struct {
RedundantUUID *string `json:"redundantUUID,omitempty"`
RedundancyType *string `json:"redundancyType,omitempty"`
ActionDetails []L2ConnectionActionDetail `json:"actionDetails,omitempty"`
VendorToken *string `json:"vendorToken,omitempty"`
}

//DeleteL2ConnectionResponse l2 connection delete response
Expand Down Expand Up @@ -70,6 +71,7 @@ type L2ConnectionRequest struct {
SellerRegion *string `json:"sellerRegion,omitempty"`
SellerMetroCode *string `json:"sellerMetroCode,omitempty"`
AuthorizationKey *string `json:"authorizationKey,omitempty"`
PrimaryServiceToken *string `json:"primaryServiceToken,omitempty"`
}

//CreateL2ConnectionResponse post l2 connection response
Expand Down
5 changes: 4 additions & 1 deletion rest_l2_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func mapGETToL2Connection(getResponse api.L2ConnectionResponse) *L2Connection {
RedundantUUID: getResponse.RedundantUUID,
RedundancyType: getResponse.RedundancyType,
Actions: mapL2ConnectionActionsAPIToDomain(getResponse.ActionDetails),
ServiceToken: getResponse.VendorToken,
}
}

Expand All @@ -198,7 +199,9 @@ func createL2ConnectionRequest(l2connection L2Connection) api.L2ConnectionReques
PrimaryZSideVlanCTag: l2connection.ZSideVlanCTag,
SellerRegion: l2connection.SellerRegion,
SellerMetroCode: l2connection.SellerMetroCode,
AuthorizationKey: l2connection.AuthorizationKey}
AuthorizationKey: l2connection.AuthorizationKey,
PrimaryServiceToken: l2connection.ServiceToken,
}
}

func createL2RedundantConnectionRequest(primary L2Connection, secondary L2Connection) api.L2ConnectionRequest {
Expand Down
36 changes: 35 additions & 1 deletion rest_l2_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,39 @@ func TestCreateDeviceL2Connection(t *testing.T) {
assert.Equal(t, uuid, respBody.PrimaryConnectionID, "UUID matches")
}

func TestCreateServiceTokenL2Connection(t *testing.T) {
//Given
respBody := api.CreateL2ConnectionResponse{}
if err := readJSONData("./test-fixtures/ecx_l2connection_post_resp.json", &respBody); err != nil {
assert.Failf(t, "Cannot read test response due to %s", err.Error())
}
reqBody := api.L2ConnectionRequest{}
testHc := &http.Client{}
httpmock.ActivateNonDefault(testHc)
httpmock.RegisterResponder("POST", fmt.Sprintf("%s/ecx/v3/l2/connections", baseURL),
func(r *http.Request) (*http.Response, error) {
if err := json.NewDecoder(r.Body).Decode(&reqBody); err != nil {
return httpmock.NewStringResponse(400, ""), nil
}
resp, _ := httpmock.NewJsonResponse(200, respBody)
return resp, nil
},
)
defer httpmock.DeactivateAndReset()
newConnection := testPrimaryConnection
newConnection.ServiceToken = String("serviceToken")

//When
ecxClient := NewClient(context.Background(), baseURL, testHc)
uuid, err := ecxClient.CreateL2Connection(newConnection)

//Then
assert.Nil(t, err, "Client should not return an error")
assert.NotNil(t, uuid, "Client should return a response")
verifyL2ConnectionRequest(t, newConnection, reqBody)
assert.Equal(t, uuid, respBody.PrimaryConnectionID, "UUID matches")
}

func TestCreateRedundantL2Connection(t *testing.T) {
//Given
respBody := api.CreateL2ConnectionResponse{}
Expand Down Expand Up @@ -319,7 +352,8 @@ func verifyL2ConnectionRequest(t *testing.T, conn L2Connection, req api.L2Connec
assert.Equal(t, conn.ZSideVlanCTag, req.PrimaryZSideVlanCTag, "PrimaryZSideVlanCTag matches")
assert.Equal(t, conn.SellerRegion, req.SellerRegion, "SellerRegion matches")
assert.Equal(t, conn.SellerMetroCode, req.SellerMetroCode, "SellerMetroCode matches")
assert.Equal(t, conn.AuthorizationKey, req.AuthorizationKey, "Authorization key matches")
assert.Equal(t, conn.AuthorizationKey, req.AuthorizationKey, "AuthorizationKey matches")
assert.Equal(t, conn.ServiceToken, req.PrimaryServiceToken, "PrimaryServiceToken matches")

assert.Equal(t, len(conn.AdditionalInfo), len(req.AdditionalInfo), "AdditionalInfo array size matches")
for i := range conn.AdditionalInfo {
Expand Down
1 change: 1 addition & 0 deletions test-fixtures/ecx_l2connection_get_resp.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"self": false,
"redundantUUID": "a653087c-f128-41d9-967d-c718223a72d6",
"namedTag": "Private",
"vendorToken": "a87166ad0-9e02-42b6-bfc3-b3696d53db12",
"additionalInfo": [
{
"name": "global",
Expand Down

0 comments on commit bfa82b2

Please sign in to comment.