Skip to content

Commit

Permalink
Merge 7a0330f into b35746b
Browse files Browse the repository at this point in the history
  • Loading branch information
ozerovandrei committed Apr 18, 2018
2 parents b35746b + 7a0330f commit af4ec11
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 af4ec11

Please sign in to comment.