2021-08-08 23:46:29 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-01-01 02:26:39 +00:00
|
|
|
"net"
|
2021-08-08 23:46:29 +00:00
|
|
|
"net/http"
|
2022-01-01 02:26:39 +00:00
|
|
|
"reflect"
|
2021-08-08 23:46:29 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
2022-01-01 02:26:39 +00:00
|
|
|
|
2025-01-24 04:36:22 +00:00
|
|
|
"git.farhan.codes/farhan/fedilogue/shared"
|
2021-08-08 23:46:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBuildClient(t *testing.T) {
|
|
|
|
tr := &http.Transport{
|
2022-01-01 02:26:39 +00:00
|
|
|
MaxIdleConns: 2,
|
2021-08-08 23:46:29 +00:00
|
|
|
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
|
2021-08-08 23:46:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetRunnerExists(t *testing.T) {
|
|
|
|
defer func() {
|
2022-01-01 02:26:39 +00:00
|
|
|
runninginstances = map[string]shared.RunningInstance{}
|
2021-08-08 23:46:29 +00:00
|
|
|
}()
|
|
|
|
|
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)
|
2021-08-08 23:46:29 +00:00
|
|
|
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")
|
|
|
|
// }
|
2021-08-08 23:46:29 +00:00
|
|
|
}
|