Package list golang-github-stvp-tempredis / b9ce4e67-38d3-45d2-9c1c-409d65014d4d/main tempredis_test.go
b9ce4e67-38d3-45d2-9c1c-409d65014d4d/main

Tree @b9ce4e67-38d3-45d2-9c1c-409d65014d4d/main (Download .tar.gz)

tempredis_test.go @b9ce4e67-38d3-45d2-9c1c-409d65014d4d/mainraw · history · blame

package tempredis

import (
	"testing"

	"github.com/garyburd/redigo/redis"
)

func TestServer(t *testing.T) {
	server, err := Start(Config{"databases": "3"})
	if err != nil {
		t.Fatal(err)
	}
	defer server.Kill()

	r, err := redis.Dial("unix", server.Socket())
	if err != nil {
		t.Fatal(err)
	}
	defer r.Close()

	databases, err := redis.Strings(r.Do("CONFIG", "GET", "databases"))
	if err != nil {
		t.Fatal(err)
	}
	if databases[1] != "3" {
		t.Fatalf("databases config should be 3, but got %s", databases)
	}

	if err := server.Term(); err != nil {
		t.Fatal(err)
	}
	if err := server.Term(); err == nil {
		t.Fatal("stopping an already stopped server should fail")
	}
}

func TestStartWithDefaultConfig(t *testing.T) {
	server, err := Start(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer server.Kill()

	r, err := redis.Dial("unix", server.Socket())
	if err != nil {
		t.Fatal(err)
	}
	defer r.Close()

	_, err = r.Do("PING")
	if err != nil {
		t.Fatal(err)
	}
}

func TestStartFail(t *testing.T) {
	server, err := Start(Config{"oops": "borked"})
	if err == nil {
		t.Fatal("expected error, got nil")
	}
	defer server.Kill()
}