Susumu Yata
null+****@clear*****
Tue Sep 12 10:38:55 JST 2017
Susumu Yata 2017-09-12 10:38:55 +0900 (Tue, 12 Sep 2017) New Revision: f77b0d18c95869dd57c8a204dc412229c3ed37d9 https://github.com/groonga/grnci/commit/f77b0d18c95869dd57c8a204dc412229c3ed37d9 Message: Add tests for DB.Config*. Modified files: v2/libgrn/db_test.go Modified: v2/libgrn/db_test.go (+78 -0) =================================================================== --- v2/libgrn/db_test.go 2017-09-12 10:35:08 +0900 (17da67d) +++ v2/libgrn/db_test.go 2017-09-12 10:38:55 +0900 (b5c1e08) @@ -149,6 +149,84 @@ func TestDBColumnRemoveInvalidColumn(t *testing.T) { } } +func TestDBConfigDelete(t *testing.T) { + db, dir := makeDB(t) + defer removeDB(db, dir) + + if err := db.ConfigSet("config_key", "config_value"); err != nil { + t.Fatalf("db.ConfigSet failed: %v", err) + } + if err := db.ConfigDelete("config_key"); err != nil { + t.Fatalf("db.ConfigDelete failed: %v", err) + } + value, err := db.ConfigGet("config_key") + if err != nil { + t.Fatalf("db.ConfigGet failed: %v", err) + } + if value != "" { + t.Fatalf("db.ConfigGet wrongly succeeded") + } +} + +func TestDBConfigDeleteInvalidKey(t *testing.T) { + db, dir := makeDB(t) + defer removeDB(db, dir) + + if err := db.ConfigDelete("no_such_key"); err == nil { + t.Fatalf("db.ConfigDelete wrongly succeeded") + } +} + +func TestDBConfigGetInvalidKey(t *testing.T) { + db, dir := makeDB(t) + defer removeDB(db, dir) + + value, err := db.ConfigGet("no_such_key") + if err != nil { + t.Fatalf("db.ConfigGet failed: %v", err) + } + if value != "" { + t.Fatalf("db.ConfigGet wrongly succeeded") + } +} + +func TestDBConfigSet(t *testing.T) { + db, dir := makeDB(t) + defer removeDB(db, dir) + + want := "config_value" + if err := db.ConfigSet("config_key", want); err != nil { + t.Fatalf("db.ConfigSet failed: %v", err) + } + value, err := db.ConfigGet("config_key") + if err != nil { + t.Fatalf("db.ConfigGet failed: %v", err) + } + if value != want { + t.Fatalf("db.ConfigGet failed: actual = %s, want = %s", value, want) + } +} + +func TestDBConfigSetOverwrite(t *testing.T) { + db, dir := makeDB(t) + defer removeDB(db, dir) + + want := "config_value" + if err := db.ConfigSet("config_key", "pre_config_value"); err != nil { + t.Fatalf("db.ConfigSet failed: %v", err) + } + if err := db.ConfigSet("config_key", want); err != nil { + t.Fatalf("db.ConfigSet failed: %v", err) + } + value, err := db.ConfigGet("config_key") + if err != nil { + t.Fatalf("db.ConfigGet failed: %v", err) + } + if value != want { + t.Fatalf("db.ConfigGet failed: actual = %s, want = %s", value, want) + } +} + // func TestDBDump(t *testing.T) { // client, err := NewHTTPClient("", nil) // if err != nil { -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20170912/79374112/attachment-0001.htm