Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
add tests for func NewClient
Browse files Browse the repository at this point in the history
  • Loading branch information
dimboknv committed Sep 21, 2022
1 parent 9feddd8 commit 3e3fe7c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"context"
"encoding/xml"
"fmt"
"github.com/pkg/errors"
"io"
"net/http"

"github.com/pkg/errors"
)

// Error reports an error and the Method, URL, response/request body that caused it
Expand Down
34 changes: 34 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package p24
import (
"context"
"encoding/xml"
"fmt"
"io"
"net/http"
"net/http/httptest"
Expand All @@ -12,6 +13,39 @@ import (
"github.com/stretchr/testify/require"
)

func TestNewClient(t *testing.T) {
logOutput := ""
log := LogFunc(func(format string, args ...interface{}) {
logOutput = fmt.Sprintf(format, args...)
})

doerOutput := ""
doer := DoFunc(func(req *http.Request) (*http.Response, error) {
doerOutput = req.Method
return nil, nil
})

merchant := Merchant{
ID: "id",
Pass: "pass",
}

cli := NewClient(ClientOpts{
HTTP: doer,
Merchant: merchant,
})
require.Equal(t, merchant, cli.merchant)
require.NotNil(t, cli.log)

req, _ := http.NewRequest(http.MethodPost, "http://localhost", http.NoBody)
_, _ = cli.http.Do(req)
require.Equal(t, http.MethodPost, doerOutput)

cli = NewClient(ClientOpts{Log: log})
cli.log.Logf("%s", "test")
require.Equal(t, "test", logOutput)
}

func TestClient_DoContext(t *testing.T) {
cases := []struct {
expected Response
Expand Down

0 comments on commit 3e3fe7c

Please sign in to comment.