Пример #1
0
func TestBackend(t *testing.T) {
	dsn := *dsn
	if env := os.Getenv("DSN"); env != "" {
		// for running in CI container
		dsn = env
	}

	db, err := sql.Open("postgres", dsn)
	if err != nil {
		t.Fatalf("sql.Open: %s", err)
	}

	// Drop all tables.
	for _, item := range schema {
		if _, err := db.Exec("DROP TABLE IF EXISTS " + item.Name + " CASCADE"); err != nil {
			t.Fatalf("failed to drop table %s: %s", item.Name, err)
		}
	}
	if _, err := db.Exec("DROP TABLE IF EXISTS gorp_migrations"); err != nil {
		t.Fatal(err)
	}

	// Recreate all tables.
	src := migrate.FileMigrationSource{"migrations"}
	if _, err := migrate.Exec(db, "postgres", src, migrate.Up); err != nil {
		t.Fatal(err)
	}

	// Define backend factory.
	var b *Backend
	defer func() {
		if b != nil {
			b.Close()
		}
	}()
	factory := func(heim *proto.Heim) (proto.Backend, error) {
		if b == nil {
			heim.Cluster = &cluster.TestCluster{}
			heim.PeerDesc = &cluster.PeerDesc{
				ID:      "testcase",
				Era:     "era",
				Version: "testver",
			}

			b, err = NewBackend(heim, dsn)
			if err != nil {
				return nil, err
			}
		}
		return &nonClosingBackend{b}, nil
	}

	// Run test suite.
	backend.IntegrationTest(t, factory)
}
Пример #2
0
func TestBackend(t *testing.T) {
	etcd, err := clustertest.StartEtcd()
	if err != nil {
		t.Fatal(err)
	}
	if etcd == nil {
		t.Fatal("etcd not available in PATH, can't test backend")
	}
	defer etcd.Shutdown()

	dsn := *dsn
	if env := os.Getenv("DSN"); env != "" {
		// for running in CI container
		dsn = env
	}

	db, err := sql.Open("postgres", dsn)
	if err != nil {
		t.Fatalf("sql.Open: %s", err)
	}

	// Drop all tables.
	for _, item := range schema {
		if _, err := db.Exec("DROP TABLE IF EXISTS " + item.Name + " CASCADE"); err != nil {
			t.Fatalf("failed to drop table %s: %s", item.Name, err)
		}
	}
	if _, err := db.Exec("DROP TABLE IF EXISTS gorp_migrations"); err != nil {
		t.Fatal(err)
	}

	// Recreate all tables.
	src := migrate.FileMigrationSource{"migrations"}
	if _, err := migrate.Exec(db, "postgres", src, migrate.Up); err != nil {
		t.Fatal(err)
	}

	// Start up backend.
	c := etcd.Join("/test", "testcase", "era")
	desc := &cluster.PeerDesc{
		ID:      "testcase",
		Era:     "era",
		Version: "testver",
	}
	b, err := NewBackend(scope.New(), dsn, c, desc)
	if err != nil {
		t.Fatal(err)
	}
	defer b.Close()

	// Run test suite.
	backend.IntegrationTest(t, func() proto.Backend { return nonClosingBackend{b} })
}
Пример #3
0
func TestIntegration(t *testing.T) {
	etcd, err := clustertest.StartEtcd()
	if err != nil {
		t.Fatal(err)
	}
	if etcd == nil {
		t.Fatal("can't test euphoria.io/heim/cluster/etcd: etcd not available in PATH")
	}
	defer etcd.Shutdown()

	backend.IntegrationTest(
		t, func(heim *proto.Heim) (proto.Backend, error) {
			heim.Cluster = etcd.Join("/test", "testcase", "era")
			return &mock.TestBackend{}, nil
		})
}
Пример #4
0
func TestIntegration(t *testing.T) {
	backend.IntegrationTest(t, func() proto.Backend { return &mock.TestBackend{} })
}
Пример #5
0
func TestBackend(t *testing.T) {
	backend.IntegrationTest(
		t, func(*proto.Heim) (proto.Backend, error) { return &mock.TestBackend{}, nil })
}
Пример #6
0
func TestBackend(t *testing.T) {
	dsn := *dsn
	if env := os.Getenv("DSN"); env != "" {
		// for running in CI container
		dsn = env
	}

	db, err := sql.Open("postgres", dsn)
	if err != nil {
		t.Fatalf("sql.Open: %s", err)
	}

	// Drop all tables.
	for _, item := range schema {
		if _, err := db.Exec("DROP TABLE IF EXISTS " + item.Name + " CASCADE"); err != nil {
			t.Fatalf("failed to drop table %s: %s", item.Name, err)
		}
	}
	for _, table := range []string{"gorp_migrations", "stats_sessions_analyzed", "stats_sessions_global", "stats_sessions_per_room"} {
		if _, err := db.Exec("DROP TABLE IF EXISTS " + table); err != nil {
			t.Fatal(err)
		}
	}
	for _, function := range []string{
		"stats_sessions_analyze()",
		"stats_sessions_global_find(timestamp with time zone, timestamp with time zone)",
		"stats_sessions_global_extend(timestamp with time zone, timestamp with time zone)",
		"stats_sessions_per_room_find(timestamp with time zone, timestamp with time zone)",
		"stats_sessions_per_room_extend(timestamp with time zone, timestamp with time zone)",
		"job_claim(text, text)",
		"job_steal(text, text)",
		"job_complete(bigint, integer, bytea)",
		"job_fail(bigint, integer, text, bytea)",
		"job_cancel(bigint)",
		"virtualize_address(text, inet)",
		"virtualize_inet4(text, inet)",
		"virtualize_inet6(text, inet)",
		"permute32(integer)",
	} {
		if _, err := db.Exec("DROP FUNCTION IF EXISTS " + function); err != nil {
			t.Fatal(err)
		}
	}

	// Recreate all tables.
	src := migrate.FileMigrationSource{"migrations"}
	if _, err := migrate.Exec(db, "postgres", src, migrate.Up); err != nil {
		t.Fatal(err)
	}

	// Define backend factory.
	var b *Backend
	defer func() {
		if b != nil {
			b.Close()
		}
	}()
	factory := func(heim *proto.Heim) (proto.Backend, error) {
		if b == nil {
			heim.Cluster = &cluster.TestCluster{}
			heim.PeerDesc = &cluster.PeerDesc{
				ID:      "testcase",
				Era:     "era",
				Version: "testver",
			}

			b, err = NewBackend(heim, dsn)
			if err != nil {
				return nil, err
			}
		}
		return &nonClosingBackend{b}, nil
	}

	// Run test suite.
	backend.IntegrationTest(t, factory)
}