func TestContextDatabases(t *testing.T) {
	// Create a temporary folder and ensure no database is contained within
	dir, err := ioutil.TempDir("", "")
	if err != nil {
		t.Fatalf("failed to create temporary data directory: %v", err)
	}
	defer os.RemoveAll(dir)

	if _, err := os.Stat(filepath.Join(dir, "database")); err == nil {
		t.Fatalf("non-created database already exists")
	}
	// Request the opening/creation of a database and ensure it persists to disk
	ctx := &ServiceContext{config: &Config{Name: "unit-test", DataDir: dir}}
	db, err := ctx.OpenDatabase("persistent", 0, 0)
	if err != nil {
		t.Fatalf("failed to open persistent database: %v", err)
	}
	db.Close()

	if _, err := os.Stat(filepath.Join(dir, "unit-test", "persistent")); err != nil {
		t.Fatalf("persistent database doesn't exists: %v", err)
	}
	// Request th opening/creation of an ephemeral database and ensure it's not persisted
	ctx = &ServiceContext{config: &Config{DataDir: ""}}
	db, err = ctx.OpenDatabase("ephemeral", 0, 0)
	if err != nil {
		t.Fatalf("failed to open ephemeral database: %v", err)
	}
	db.Close()

	if _, err := os.Stat(filepath.Join(dir, "ephemeral")); err == nil {
		t.Fatalf("ephemeral database exists")
	}
}
// Tests that databases are correctly created persistent or ephemeral based on
// the configured service context.
Tests that databases are correctly created persistent or ephemeral based on
the configured service context.
// Tests that databases are correctly created persistent or ephemeral based on // the configured service context .
func TestContextDatabases(t *testing.T) {
	dir, err := ioutil.TempDir("", "")
	if err != nil {
		t.Fatalf("failed to create temporary data directory: %v", err)
	}
	defer os.RemoveAll(dir)
	if _, err := os.Stat(filepath.Join(dir, "database")); err == nil {
		t.Fatalf("non-created database already exists")
	}
	ctx := &ServiceContext{config: &Config{Name: "unit-test", DataDir: dir}}
	db, err := ctx.OpenDatabase("persistent", 0, 0)
	if err != nil {
		t.Fatalf("failed to open persistent database: %v", err)
	}
	db.Close()
	if _, err := os.Stat(filepath.Join(dir, "unit-test", "persistent")); err != nil {
		t.Fatalf("persistent database doesn't exists: %v", err)
	}
	ctx = &ServiceContext{config: &Config{DataDir: ""}}
	db, err = ctx.OpenDatabase("ephemeral", 0, 0)
	if err != nil {
		t.Fatalf("failed to open ephemeral database: %v", err)
	}
	db.Close()
	if _, err := os.Stat(filepath.Join(dir, "ephemeral")); err == nil {
		t.Fatalf("ephemeral database exists")
	}
}
func TestContextDatabases ( t * testing . T ) { dir , err := ioutil . TempDir ( " " , " " ) if err != nil { t . Fatalf ( " " , err ) } defer os . RemoveAll ( dir ) if _ , err := os . Stat ( filepath . Join ( dir , " " ) ) ; err == nil { t . Fatalf ( " " ) } ctx := & ServiceContext { config : & Config { Name : " " , DataDir : dir } } db , err := ctx . OpenDatabase ( " " , 0 , 0 ) if err != nil { t . Fatalf ( " " , err ) } db . Close ( ) if _ , err := os . Stat ( filepath . Join ( dir , " " , " " ) ) ; err != nil { t . Fatalf ( " " , err ) } ctx = & ServiceContext { config : & Config { DataDir : " " } } db , err = ctx . OpenDatabase ( " " , 0 , 0 ) if err != nil { t . Fatalf ( " " , err ) } db . Close ( ) if _ , err := os . Stat ( filepath . Join ( dir , " " ) ) ; err == nil { t . Fatalf ( " " ) } }
Tests that databases are correctly created persistent or ephemeral based on
the configured service context.
Tests that databases are correctly created persistent or ephemeral based on the configured service context .
// Create a temporary folder and ensure no database is contained within // Request the opening/creation of a database and ensure it persists to disk // Request th opening/creation of an ephemeral database and ensure it's not persisted