Browse Source

Rename DialTest to DialTestDB.

Also, add doc comments to the dial() and DialTestDB() functions.
Gary Burd 11 năm trước cách đây
mục cha
commit
e2941976df

+ 4 - 4
redis/conn_test.go

@@ -221,7 +221,7 @@ var testCommands = []struct {
 }
 }
 
 
 func TestDoCommands(t *testing.T) {
 func TestDoCommands(t *testing.T) {
-	c, err := redis.DialTest()
+	c, err := redis.DialTestDB()
 	if err != nil {
 	if err != nil {
 		t.Fatalf("error connection to database, %v", err)
 		t.Fatalf("error connection to database, %v", err)
 	}
 	}
@@ -240,7 +240,7 @@ func TestDoCommands(t *testing.T) {
 }
 }
 
 
 func TestPipelineCommands(t *testing.T) {
 func TestPipelineCommands(t *testing.T) {
-	c, err := redis.DialTest()
+	c, err := redis.DialTestDB()
 	if err != nil {
 	if err != nil {
 		t.Fatalf("error connection to database, %v", err)
 		t.Fatalf("error connection to database, %v", err)
 	}
 	}
@@ -266,7 +266,7 @@ func TestPipelineCommands(t *testing.T) {
 }
 }
 
 
 func TestBlankCommmand(t *testing.T) {
 func TestBlankCommmand(t *testing.T) {
-	c, err := redis.DialTest()
+	c, err := redis.DialTestDB()
 	if err != nil {
 	if err != nil {
 		t.Fatalf("error connection to database, %v", err)
 		t.Fatalf("error connection to database, %v", err)
 	}
 	}
@@ -293,7 +293,7 @@ func TestBlankCommmand(t *testing.T) {
 }
 }
 
 
 func TestError(t *testing.T) {
 func TestError(t *testing.T) {
-	c, err := redis.DialTest()
+	c, err := redis.DialTestDB()
 	if err != nil {
 	if err != nil {
 		t.Fatalf("error connection to database, %v", err)
 		t.Fatalf("error connection to database, %v", err)
 	}
 	}

+ 1 - 1
redis/pool_test.go

@@ -54,7 +54,7 @@ type poolDialer struct {
 func (d *poolDialer) dial() (Conn, error) {
 func (d *poolDialer) dial() (Conn, error) {
 	d.open += 1
 	d.open += 1
 	d.dialed += 1
 	d.dialed += 1
-	c, err := DialTest()
+	c, err := DialTestDB()
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}

+ 1 - 1
redis/pubsub_test.go

@@ -109,7 +109,7 @@ func expectPushed(t *testing.T, c redis.PubSubConn, message string, expected int
 }
 }
 
 
 func TestPushed(t *testing.T) {
 func TestPushed(t *testing.T) {
-	pc, err := redis.DialTest()
+	pc, err := redis.DialTestDB()
 	if err != nil {
 	if err != nil {
 		t.Fatalf("error connection to database, %v", err)
 		t.Fatalf("error connection to database, %v", err)
 	}
 	}

+ 2 - 1
redis/reply_test.go

@@ -80,8 +80,9 @@ func TestReply(t *testing.T) {
 	}
 	}
 }
 }
 
 
+// dial wraps DialTestDB() with a more suitable function name for examples.
 func dial() (redis.Conn, error) {
 func dial() (redis.Conn, error) {
-	return redis.DialTest()
+	return redis.DialTestDB()
 }
 }
 
 
 func ExampleBool() {
 func ExampleBool() {

+ 1 - 1
redis/script_test.go

@@ -33,7 +33,7 @@ func ExampleScript(c redis.Conn, reply interface{}, err error) {
 }
 }
 
 
 func TestScript(t *testing.T) {
 func TestScript(t *testing.T) {
-	c, err := redis.DialTest()
+	c, err := redis.DialTestDB()
 	if err != nil {
 	if err != nil {
 		t.Fatalf("error connection to database, %v", err)
 		t.Fatalf("error connection to database, %v", err)
 	}
 	}

+ 4 - 1
redis/test_test.go

@@ -37,7 +37,10 @@ func (t testConn) Close() error {
 	return t.Conn.Close()
 	return t.Conn.Close()
 }
 }
 
 
-func DialTest() (Conn, error) {
+// DialTestDB dials the local Redis server and selects database 9. To prevent
+// stomping on real data, DialTestDB fails if database 9 contains data. The
+// returned connection flushes database 9 on close.
+func DialTestDB() (Conn, error) {
 	c, err := DialTimeout("tcp", ":6379", 0, 1*time.Second, 1*time.Second)
 	c, err := DialTimeout("tcp", ":6379", 0, 1*time.Second, 1*time.Second)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err