gearman-go/client/client_test.go

44 lines
947 B
Go
Raw Normal View History

package client
import (
"bitbucket.org/mikespook/gearman-go/common"
"testing"
)
var client *Client
func TestClientAddServer(t *testing.T) {
t.Log("Add local server 127.0.0.1:4730")
var err error
if client, err = New("tcp4", "127.0.0.1:4730"); err != nil {
t.Error(err)
}
}
func TestClientEcho(t *testing.T) {
client.JobHandler = func(job *Job) error {
echo := string(job.Data)
if echo == "Hello world" {
t.Log(echo)
} else {
t.Errorf("Invalid echo data: %s", job.Data)
}
return nil
}
client.Echo([]byte("Hello world"))
}
func TestClientDo(t *testing.T) {
if handle, err := client.Do("ToUpper", []byte("abcdef"), common.JOB_LOW|common.JOB_BG); err != nil {
t.Error(err)
} else {
t.Log(handle)
}
}
func TestClientClose(t *testing.T) {
if err := client.Close(); err != nil {
t.Error(err)
}
}