Skip to content

Commit

Permalink
Resell V2 - add client with a custom endpoint
Browse files Browse the repository at this point in the history
Users may want to use custom endpoint for the Resell V2 API.
This commit adds a new NewV2ResellClientWithEndpoint method, fixes
argument capitalization in the old NewV2ResellClient method and adds
simple tests.
  • Loading branch information
ozerovandrei committed Apr 18, 2018
1 parent b35746b commit 7a0330f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
16 changes: 14 additions & 2 deletions selvpcclient/resell/v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,23 @@ import (
const APIVersion = "v2"

// NewV2ResellClient initializes a new Resell client for the V2 API.
func NewV2ResellClient(TokenID string) *selvpcclient.ServiceClient {
func NewV2ResellClient(tokenID string) *selvpcclient.ServiceClient {
resellClient := &selvpcclient.ServiceClient{
HTTPClient: &http.Client{},
Endpoint: resell.Endpoint + "/" + APIVersion,
TokenID: TokenID,
TokenID: tokenID,
UserAgent: resell.UserAgent,
}

return resellClient
}

// NewV2ResellClientWithEndpoint initializes a new Resell client for the V2 API with custom endpoint.
func NewV2ResellClientWithEndpoint(tokenID, endpoint string) *selvpcclient.ServiceClient {
resellClient := &selvpcclient.ServiceClient{
HTTPClient: &http.Client{},
Endpoint: endpoint,
TokenID: tokenID,
UserAgent: resell.UserAgent,
}

Expand Down
43 changes: 43 additions & 0 deletions selvpcclient/resell/v2/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package v2

import (
"net/http"
"reflect"
"testing"

"github.com/selectel/go-selvpcclient/selvpcclient"
"github.com/selectel/go-selvpcclient/selvpcclient/resell"
)

func TestNewV2ResellClient(t *testing.T) {
token := "fakeID"
expected := &selvpcclient.ServiceClient{
HTTPClient: &http.Client{},
Endpoint: resell.Endpoint + "/" + APIVersion,
TokenID: token,
UserAgent: resell.UserAgent,
}

actual := NewV2ResellClient(token)

if !reflect.DeepEqual(expected, actual) {
t.Fatalf("expected %#v, but got %#v", expected, actual)
}
}

func TestNewV2ResellClientWithEndpoint(t *testing.T) {
token := "fakeID"
endpoint := "http://example.org"
expected := &selvpcclient.ServiceClient{
HTTPClient: &http.Client{},
Endpoint: endpoint,
TokenID: token,
UserAgent: resell.UserAgent,
}

actual := NewV2ResellClientWithEndpoint(token, endpoint)

if !reflect.DeepEqual(expected, actual) {
t.Fatalf("expected %#v, but got %#v", expected, actual)
}
}

0 comments on commit 7a0330f

Please sign in to comment.