-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
сreate a method to send a custom request
- Loading branch information
1 parent
86e93d7
commit 7162154
Showing
3 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package tonapi | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
||
"github.com/go-faster/errors" | ||
"github.com/stretchr/testify/require" | ||
"github.com/tonkeeper/tongo/ton" | ||
) | ||
|
||
var systemAccountID = ton.MustParseAccountID("Ef8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAU") | ||
|
||
func TestCustomRequest(t *testing.T) { | ||
client, err := New() | ||
if err != nil { | ||
t.Fatalf("failed to init tonapi client: %v", err) | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
method string | ||
path string | ||
query map[string]string | ||
err error | ||
}{ | ||
{ | ||
name: "fail to get account info - method not allowed", | ||
method: http.MethodPost, | ||
path: fmt.Sprintf("v2/accounts/%v", systemAccountID), | ||
err: errors.New("405 Method Not Allowed"), | ||
}, | ||
{ | ||
name: "ok to get account info", | ||
method: http.MethodGet, | ||
path: fmt.Sprintf("v2/accounts/%v", systemAccountID), | ||
err: nil, | ||
}, | ||
{ | ||
name: "fail with invalid account ID", | ||
method: http.MethodGet, | ||
path: "v2/accounts/invalidAccountID", | ||
err: errors.New("400 Bad Request"), | ||
}, | ||
{ | ||
name: "fail with non-existent path", | ||
method: http.MethodGet, | ||
path: "v2/nonexistentpath", | ||
err: errors.New("404 Not Found"), | ||
}, | ||
{ | ||
name: "ok to get collections", | ||
method: http.MethodGet, | ||
path: "v2/nfts/collections", | ||
query: map[string]string{"limit": "10"}, | ||
err: nil, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
resp, err := client.Request(context.Background(), tt.method, tt.path, tt.query, nil) | ||
if tt.err != nil { | ||
require.Error(t, err) | ||
require.Equal(t, tt.err.Error(), err.Error()) | ||
require.Nil(t, resp) | ||
} else { | ||
require.NoError(t, err) | ||
require.NotNil(t, resp) | ||
} | ||
time.Sleep(time.Millisecond * 100) // rps limit | ||
}) | ||
} | ||
} |
UQBcLFHC7OdsxJwNRnGrsIF1bYLeYhNb74yy4FoyQNmzJaz9