當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Data.RenameDatabase方法代碼示例

本文整理匯總了Golang中github.com/influxdb/influxdb/meta.Data.RenameDatabase方法的典型用法代碼示例。如果您正苦於以下問題:Golang Data.RenameDatabase方法的具體用法?Golang Data.RenameDatabase怎麽用?Golang Data.RenameDatabase使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/influxdb/influxdb/meta.Data的用法示例。


在下文中一共展示了Data.RenameDatabase方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestData_RenameDatabaseUpdatesPrivileges

// 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)
	}
}
開發者ID:realgo,項目名稱:influxdb,代碼行數:28,代碼來源:data_test.go

示例2: TestData_RenameDatabase_ErrDatabaseCQConflict

// 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)
	}
}
開發者ID:realgo,項目名稱:influxdb,代碼行數:31,代碼來源:data_test.go

示例3: TestData_RenameDatabase

// 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)
	}
}
開發者ID:realgo,項目名稱:influxdb,代碼行數:15,代碼來源:data_test.go

示例4: TestData_RenameDatabase_ErrNameRequired

// 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)
	}
}
開發者ID:realgo,項目名稱:influxdb,代碼行數:13,代碼來源:data_test.go


注:本文中的github.com/influxdb/influxdb/meta.Data.RenameDatabase方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。