Skip to content

Commit dab548b

Browse files
committed
Add missing TestMain file for the voice package
1 parent 109a41c commit dab548b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

voice/main_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package voice
2+
3+
import (
4+
"crypto/tls"
5+
"log"
6+
"net"
7+
"net/http"
8+
"net/http/httptest"
9+
"os"
10+
"testing"
11+
12+
"github.com/messagebird/go-rest-api"
13+
)
14+
15+
func testClient(status int, body []byte) (*messagebird.Client, func()) {
16+
mbServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
17+
w.Header().Set("Content-Type", "application/json")
18+
w.WriteHeader(status)
19+
w.Write(body)
20+
}))
21+
addr := mbServer.Listener.Addr().String()
22+
transport := &http.Transport{
23+
DialTLS: func(netw, _ string) (net.Conn, error) {
24+
return tls.Dial(netw, addr, &tls.Config{InsecureSkipVerify: true})
25+
},
26+
}
27+
mbClient := &messagebird.Client{
28+
AccessKey: "test_gshuPaZoeEG6ovbc8M79w0QyM",
29+
HTTPClient: &http.Client{Transport: transport},
30+
}
31+
if testing.Verbose() {
32+
mbClient.DebugLog = log.New(os.Stdout, "DEBUG", log.Lshortfile)
33+
}
34+
return mbClient, func() { mbServer.Close() }
35+
}

0 commit comments

Comments
 (0)