Add worker test.
This commit is contained in:
parent
1e81862d5b
commit
d1b36d704c
@ -64,6 +64,8 @@ func initConfig() {
|
|||||||
ResultsExpireIn: 5,
|
ResultsExpireIn: 5,
|
||||||
}
|
}
|
||||||
machineryServer, _ = machinery.NewServer(machineryConfig)
|
machineryServer, _ = machinery.NewServer(machineryConfig)
|
||||||
|
newNullLogger := NewNullLogger()
|
||||||
|
log.DEBUG = newNullLogger
|
||||||
uaString = viper.GetString("relay_servicename") + " (golang net/http; Activity-Relay v0.2.1; " + hostURL.Host + ")"
|
uaString = viper.GetString("relay_servicename") + " (golang net/http; Activity-Relay v0.2.1; " + hostURL.Host + ")"
|
||||||
Actor.GenerateSelfKey(hostURL, &hostPrivatekey.PublicKey)
|
Actor.GenerateSelfKey(hostURL, &hostPrivatekey.PublicKey)
|
||||||
|
|
||||||
@ -84,9 +86,6 @@ func main() {
|
|||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
newNullLogger := NewNullLogger()
|
|
||||||
log.DEBUG = newNullLogger
|
|
||||||
|
|
||||||
workerID := uuid.NewV4()
|
workerID := uuid.NewV4()
|
||||||
worker := machineryServer.NewWorker(workerID.String(), 200)
|
worker := machineryServer.NewWorker(workerID.String(), 200)
|
||||||
err = worker.Launch()
|
err = worker.Launch()
|
||||||
|
122
worker/worker_test.go
Normal file
122
worker/worker_test.go
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
viper.Set("Actor_pem", "../misc/testKey.pem")
|
||||||
|
viper.Set("Relay_domain", "relay.yukimochi.example.org")
|
||||||
|
initConfig()
|
||||||
|
redisClient.FlushAll().Result()
|
||||||
|
|
||||||
|
// Load Config
|
||||||
|
code := m.Run()
|
||||||
|
os.Exit(code)
|
||||||
|
redisClient.FlushAll().Result()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRelayActivity(t *testing.T) {
|
||||||
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
data, _ := ioutil.ReadAll(r.Body)
|
||||||
|
if string(data) != "data" {
|
||||||
|
w.WriteHeader(500)
|
||||||
|
w.Write(nil)
|
||||||
|
} else {
|
||||||
|
w.WriteHeader(202)
|
||||||
|
w.Write(nil)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
err := relayActivity(s.URL, "data")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("Failed - Data transfar not collect")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRelayActivityNoHost(t *testing.T) {
|
||||||
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
}))
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
err := relayActivity("http://nohost.example.jp", "data")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("Failed - Error not reported.")
|
||||||
|
}
|
||||||
|
domain, _ := url.Parse("http://nohost.example.jp")
|
||||||
|
data, err := redisClient.HGet("relay:statistics:"+domain.Host, "last_error").Result()
|
||||||
|
if data == "" {
|
||||||
|
t.Fatal("Failed - Error not cached.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRelayActivityResp500(t *testing.T) {
|
||||||
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(500)
|
||||||
|
w.Write(nil)
|
||||||
|
}))
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
err := relayActivity(s.URL, "data")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("Failed - Error not reported.")
|
||||||
|
}
|
||||||
|
domain, _ := url.Parse(s.URL)
|
||||||
|
data, err := redisClient.HGet("relay:statistics:"+domain.Host, "last_error").Result()
|
||||||
|
if data == "" {
|
||||||
|
t.Fatal("Failed - Error not cached.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRegistorActivity(t *testing.T) {
|
||||||
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
data, _ := ioutil.ReadAll(r.Body)
|
||||||
|
if string(data) != "data" {
|
||||||
|
w.WriteHeader(500)
|
||||||
|
w.Write(nil)
|
||||||
|
} else {
|
||||||
|
w.WriteHeader(202)
|
||||||
|
w.Write(nil)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
err := registorActivity(s.URL, "data")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("Failed - Data transfar not collect")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRegistorActivityNoHost(t *testing.T) {
|
||||||
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
}))
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
err := registorActivity("http://nohost.example.jp", "data")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("Failed - Error not reported.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRegistorActivityResp500(t *testing.T) {
|
||||||
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(500)
|
||||||
|
w.Write(nil)
|
||||||
|
}))
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
err := registorActivity(s.URL, "data")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("Failed - Error not reported.")
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user