Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
negasus committed Aug 22, 2024
1 parent 09743b3 commit 46de156
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions raw_request_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package bot

import (
"context"
"io"
"net/http"
"strings"
"testing"
)

type clientMock struct {
requestURI string
}

func (c *clientMock) Do(req *http.Request) (*http.Response, error) {
c.requestURI = req.URL.RequestURI()
resp := http.Response{
StatusCode: 200,
Body: io.NopCloser(strings.NewReader(`{"ok":true}`)),
}
return &resp, nil
}

func Test_rawRequest_url(t *testing.T) {
cm := &clientMock{}
b := &Bot{
token: "XXX",
client: cm,
}

err := b.rawRequest(context.Background(), "foo", nil, nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

if cm.requestURI != "/botXXX/foo" {
t.Fatalf("unexpected requestURI: %s", cm.requestURI)
}
}

func Test_rawRequest_url_testEnv(t *testing.T) {
cm := &clientMock{}
b := &Bot{
token: "XXX",
client: cm,
testEnvironment: true,
}

err := b.rawRequest(context.Background(), "foo", nil, nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

if cm.requestURI != "/botXXX/test/foo" {
t.Fatalf("unexpected requestURI: %s", cm.requestURI)
}
}

0 comments on commit 46de156

Please sign in to comment.