Fix a bug in StKey creation logic for dbInfoLayer
This change adds a test to verify if the change fixes
the bug. Error log from the newly added test before fixing
the bug:
--- FAIL: TestStKey (0.00s)
db_info_test.go:32: dbInfoLayer stkey expected to be
"$dbInfo:app1:db1" but found to be "$dbInfo:app1:app1:db1"
Change-Id: I7e468fc2f55c6132a829001e43251c58c9628c1c
diff --git a/services/syncbase/server/db_info.go b/services/syncbase/server/db_info.go
index 3598dd0..98216bc 100644
--- a/services/syncbase/server/db_info.go
+++ b/services/syncbase/server/db_info.go
@@ -37,7 +37,7 @@
}
func (d *dbInfoLayer) StKey() string {
- return util.JoinKeyParts(util.DbInfoPrefix, d.a.name, d.stKeyPart())
+ return util.JoinKeyParts(util.DbInfoPrefix, d.stKeyPart())
}
////////////////////////////////////////
diff --git a/services/syncbase/server/db_info_test.go b/services/syncbase/server/db_info_test.go
new file mode 100644
index 0000000..47db158
--- /dev/null
+++ b/services/syncbase/server/db_info_test.go
@@ -0,0 +1,30 @@
+// Copyright 2015 The Vanadium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package server
+
+import (
+ "testing"
+)
+
+type stk struct {
+ appName string
+ dbName string
+ stkey string
+}
+
+var stTestKey stk = stk{"app1", "db1", "$dbInfo:app1:db1"}
+
+var dbinfo *dbInfoLayer = &dbInfoLayer{
+ name: stTestKey.dbName,
+ a: &app{
+ name: stTestKey.appName,
+ },
+}
+
+func TestStKey(t *testing.T) {
+ if stTestKey.stkey != dbinfo.StKey() {
+ t.Errorf("dbInfoLayer stkey expected to be %q but found to be %q", stTestKey.stkey, dbinfo.StKey())
+ }
+}