示例#1
0
// Ensure that user privileges are updated correctly when database is renamed.
func TestData_RenameDatabaseUpdatesPrivileges(t *testing.T) {
	var data meta.Data
	for i := 0; i < 2; i++ {
		if err := data.CreateDatabase(fmt.Sprintf("db%d", i)); err != nil {
			t.Fatal(err)
		}
	}

	data.Users = []meta.UserInfo{{
		Name:  "susy",
		Hash:  "ABC123",
		Admin: true,
		Privileges: map[string]influxql.Privilege{
			"db1": influxql.AllPrivileges, "db0": influxql.ReadPrivilege}}}

	if err := data.RenameDatabase("db1", "db2"); err != nil {
		t.Fatal(err)
	} else if !reflect.DeepEqual(data.Users,
		[]meta.UserInfo{{
			Name:  "susy",
			Hash:  "ABC123",
			Admin: true,
			Privileges: map[string]influxql.Privilege{
				"db2": influxql.AllPrivileges, "db0": influxql.ReadPrivilege}}}) {
		t.Fatalf("unexpected user privileges: %#v", data.Users)
	}
}
示例#2
0
// Ensure that renaming a database returns an error if there is a possibly conflicting CQ
func TestData_RenameDatabase_ErrDatabaseCQConflict(t *testing.T) {
	var data meta.Data
	if err := data.CreateDatabase("db0"); err != nil {
		t.Fatal(err)
	} else if err := data.CreateDatabase("db1"); err != nil {
		t.Fatal(err)
	} else if err := data.CreateContinuousQuery("db0", "cq0", `CREATE CONTINUOUS QUERY cq0 ON db0 BEGIN SELECT count() INTO "foo"."default"."bar" FROM "foo"."foobar" END`); err != nil {
		t.Fatal(err)
	} else if err := data.CreateContinuousQuery("db1", "cq1", `CREATE CONTINUOUS QUERY cq1 ON db1 BEGIN SELECT count() INTO "db1"."default"."bar" FROM "db0"."foobar" END`); err != nil {
		t.Fatal(err)
	} else if err := data.CreateContinuousQuery("db1", "cq2", `CREATE CONTINUOUS QUERY cq2 ON db1 BEGIN SELECT count() INTO "db0"."default"."bar" FROM "db1"."foobar" END`); err != nil {
		t.Fatal(err)
	} else if err := data.CreateContinuousQuery("db1", "noconflict", `CREATE CONTINUOUS QUERY noconflict ON db1 BEGIN SELECT count() INTO "db1"."default"."bar" FROM "db1"."foobar" END`); err != nil {
		t.Fatal(err)
	} else if err := data.RenameDatabase("db0", "db2"); err == nil {
		t.Fatalf("unexpected rename database success despite cq conflict")
	} else if err := data.DropContinuousQuery("db0", "cq0"); err != nil {
		t.Fatal(err)
	} else if err := data.RenameDatabase("db0", "db2"); err == nil {
		t.Fatalf("unexpected rename database success despite cq conflict")
	} else if err := data.DropContinuousQuery("db1", "cq1"); err != nil {
		t.Fatal(err)
	} else if err := data.RenameDatabase("db0", "db2"); err == nil {
		t.Fatalf("unexpected rename database success despite cq conflict")
	} else if err := data.DropContinuousQuery("db1", "cq2"); err != nil {
		t.Fatal(err)
	} else if err := data.RenameDatabase("db0", "db2"); err != nil {
		t.Fatal(err)
	}
}
示例#3
0
// Ensure a database can be renamed.
func TestData_RenameDatabase(t *testing.T) {
	var data meta.Data
	for i := 0; i < 2; i++ {
		if err := data.CreateDatabase(fmt.Sprintf("db%d", i)); err != nil {
			t.Fatal(err)
		}
	}

	if err := data.RenameDatabase("db1", "db2"); err != nil {
		t.Fatal(err)
	} else if !reflect.DeepEqual(data.Databases, []meta.DatabaseInfo{{Name: "db0"}, {Name: "db2"}}) {
		t.Fatalf("unexpected databases: %#v", data.Databases)
	}
}
示例#4
0
// Ensure that renaming a database without both old and new names returns an error.
func TestData_RenameDatabase_ErrNameRequired(t *testing.T) {
	var data meta.Data
	if err := data.RenameDatabase("", ""); err != meta.ErrDatabaseNameRequired {
		t.Fatalf("unexpected error: %s", err)
	}
	if err := data.RenameDatabase("from_foo", ""); err != meta.ErrDatabaseNameRequired {
		t.Fatalf("unexpected error: %s", err)
	}
	if err := data.RenameDatabase("", "to_foo"); err != meta.ErrDatabaseNameRequired {
		t.Fatalf("unexpected error: %s", err)
	}
}