Exemplo n.º 1
0
func newTestServer(t *testing.T) (*httptest.Server, chan bool) {
	done := make(chan bool)
	tmpd, err := ioutil.TempDir("/tmp", "erickson")
	if err != nil {
		t.Fatal(err)
	}
	go func() {
		<-done
		if err := os.RemoveAll(tmpd); err != nil {
			t.Fatal(err)
		}
	}()
	db, err := db.NewBoltDB(tmpd + "/erickson.db")
	if err != nil {
		t.Fatal(err)
	}
	u, err := review.NewUser("bob", "supersecret")
	if err != nil {
		t.Fatal(err)
	}
	if err := db.CreateUser(u); err != nil {
		t.Fatal(err)
	}
	key := []byte("12345678901234567890123456789012")
	return httptest.NewServer(server.NewRootHandler(db, tmpd, key, mail.Nil, "")), done
}
Exemplo n.º 2
0
func TestServer(t *testing.T) {
	f, err := ioutil.TempFile("/tmp", "erickson")
	if err != nil {
		t.Fatal(err)
	}
	defer os.Remove(f.Name())

	db, err := db.NewBoltDB(f.Name())
	if err != nil {
		t.Fatal(err)
	}

	user, err := review.NewUser("testuser", "testpassword")
	if err != nil {
		t.Fatal(err)
	}
	if err := db.CreateUser(user); err != nil {
		t.Fatal(err)
	}

	wd, err := os.Getwd()
	if err != nil {
		t.Fatal(err)
	}
	handler := NewRootHandler(db, wd+"./..", []byte("12345678901234567890123456789012"), mail.Nil, "")

	server := httptest.NewUnstartedServer(handler)
	cert, err := tls.LoadX509KeyPair("test.crt", "test.key")
	if err != nil {
		t.Fatal(err)
	}
	tlsConfig := &tls.Config{
		InsecureSkipVerify: true, // testing only
		Certificates:       []tls.Certificate{cert},
	}
	server.TLS = tlsConfig
	server.StartTLS()
	defer server.Close()

	*handler.URL = server.URL
	url := server.URL

	client := newClient(t, url)
	url = create(t, client, url)
	read(t, client, url)
	annotate(t, client, url+"/rev/0")
	update(t, client, url)
	destroy(t, client, url)
}