fedilogue/fedilogger/instance_test.go

61 lines
1.4 KiB
Go
Raw Normal View History

package main
import (
2022-01-01 02:26:39 +00:00
"net"
"net/http"
2022-01-01 02:26:39 +00:00
"reflect"
"testing"
"time"
2022-01-01 02:26:39 +00:00
"gitlab.com/khanzf/fedilogue/shared"
)
func TestBuildClient(t *testing.T) {
tr := &http.Transport{
2022-01-01 02:26:39 +00:00
MaxIdleConns: 2,
IdleConnTimeout: 3600 * time.Second,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
}
want := http.Client{Transport: tr}
have := BuildClient("testdomain.com")
if reflect.DeepEqual(want, have) {
t.Fatalf("TestBuildClient client different from expected.")
}
}
func TestBuildClientProxy(t *testing.T) {
// Currently not implemented
}
func TestGetRunnerNonExist(t *testing.T) {
2022-01-01 02:26:39 +00:00
// Currently not implemented
}
func TestGetRunnerExists(t *testing.T) {
defer func() {
2022-01-01 02:26:39 +00:00
runninginstances = map[string]shared.RunningInstance{}
}()
2022-01-01 02:26:39 +00:00
want_o := shared.RunningInstance{}
want_o.Client = BuildClient("some-non-existent-domain.tld")
want_o.Status = shared.KEEPALIVE
want_o.Recentactivities = shared.NewUniqueFifo(10)
want_o.Recentactors = shared.NewUniqueFifo(10)
runninginstances["some-non-existent-domain.tld"] = want_o
want_exists := true
_, have_exists := GetRunner("some-non-existent-domain.tld")
if have_exists != want_exists {
t.Fatalf("TestGetRunnerBlank expected %v, got %v", want_exists, have_exists)
}
2022-01-01 02:26:39 +00:00
// if reflect.DeepEqual(want_o, have_o) {
// t.Fatalf("TestGetRunnerExists failed, should have the same value")
// }
}