Skip to content

Commit

Permalink
setup unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
hoanhan101 committed Apr 30, 2021
1 parent a50b8ef commit 837c77a
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 8 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ require (
github.com/creasty/defaults v1.5.1
github.com/go-resty/resty/v2 v2.6.0
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.0 // indirect
golang.org/x/tools v0.1.0 // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
github.com/creasty/defaults v1.5.1 h1:j8WexcS3d/t4ZmllX4GEkl4wIB/trOr035ajcLHCISM=
github.com/creasty/defaults v1.5.1/go.mod h1:FPZ+Y0WNrbqOVw+c6av63eyHUAl6pMHZwqLPvXUZGfY=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-resty/resty/v2 v2.6.0 h1:joIR5PNLM2EFqqESUjCMGXrWmXNHEU9CEiK813oKYS4=
github.com/go-resty/resty/v2 v2.6.0/go.mod h1:PwvJS6hvaPkjtjNg9ph+VrSD92bi5Zq73w/BIH7cC3Q=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down Expand Up @@ -35,3 +42,6 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
8 changes: 0 additions & 8 deletions veryfi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ func (c *httpClient) ProcessDocumentURL(opts scheme.DocumentURLOptions) (*scheme
return *out, nil
}

// get performs a GET request against Veryfi API.
// func (c *httpClient) get(uri string, params map[string]string, okScheme interface{}) error {
// errScheme := new(scheme.Error)
// _, err := c.setBaseURL().R().SetQueryParams(params).SetResult(okScheme).SetError(errScheme).Get(uri)
// return check(err, errScheme)

// }

// post performs a POST request against Veryfi API.
func (c *httpClient) post(uri string, body interface{}, okScheme interface{}) error {
errScheme := new(scheme.Error)
Expand Down
13 changes: 13 additions & 0 deletions veryfi/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package veryfi

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestUnitNewClientV7_NilConfig(t *testing.T) {
client, err := NewClientV7(nil)
assert.Nil(t, client)
assert.Error(t, err)
}
48 changes: 48 additions & 0 deletions veryfi/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package veryfi

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestUnitBuildURL(t *testing.T) {
tests := []struct {
in map[string]interface{}
expected string
}{
{
in: map[string]interface{}{
"host": "api.veryfi.com",
"path": []string{""},
},
expected: "https://api.veryfi.com",
},
{
in: map[string]interface{}{
"host": "api.veryfi.com",
"path": []string{"api"},
},
expected: "https://api.veryfi.com/api",
},
{
in: map[string]interface{}{
"host": "api.veryfi.com",
"path": []string{"api", "v7"},
},
expected: "https://api.veryfi.com/api/v7",
},
{
in: map[string]interface{}{
"host": "api.veryfi.com",
"path": []string{"api", "v7", "foo"},
},
expected: "https://api.veryfi.com/api/v7/foo",
},
}

for _, tt := range tests {
out := buildURL(tt.in["host"].(string), tt.in["path"].([]string)...)
assert.Equal(t, tt.expected, out)
}
}

0 comments on commit 837c77a

Please sign in to comment.