bottinagenda/pkg/bottinagenda/client_test.go
2024-10-03 17:18:01 -04:00

62 lines
1.1 KiB
Go

package bottinagenda
import (
"context"
"crypto/tls"
"net/http"
"testing"
"codeberg.org/vlbeaudoin/voki/v3"
"github.com/spf13/pflag"
)
func TestClient(t *testing.T) {
ctx := context.TODO()
set := pflag.NewFlagSet("test-client", pflag.ExitOnError)
if err := BindClientFlags(set); err != nil {
t.Fatal("bind client flags:", err)
}
cfg, err := ParseConfig()
if err != nil {
t.Fatal("parse config:", err)
}
//ctx := context.TODO()
var httpClient = &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: cfg.Client.API.TLS.SkipVerify,
},
},
}
client := &APIClient{Caller: voki.New(
httpClient,
"bottin_api",
defaultServerAPIKey,
defaultServerAPIPort,
"http",
)}
defer client.Caller.CloseIdleConnections()
t.Run("message", func(t *testing.T) {
msg, err := client.Message()
if err != nil {
t.Error(err)
}
t.Log("msg:", msg)
})
// test bottinagenda health, which tests bottin health
t.Run("health", func(t *testing.T) {
healthResponse, err := client.ReadHealth(ctx)
if err != nil {
t.Error(err)
}
t.Logf("healthResponse: %v", healthResponse)
})
}