gobeetle: use V=1 or V=2 to get more test verbosity
MODIFY
Makefile
Makefile
@@ -22,6 +22,13 @@ else
TAR := tar
endif
+ifeq ($(V), 2)
+ TV := -v
+endif
+ifeq ($(V), 1)
+ TV := -v
+endif
+
all: $(GO_TARGETS)
clean:
@@ -56,13 +63,13 @@ beetle: $(GO_SRC)/beetle.go $(GO_MODULES) $(GO_SRC)/a_main-packr.go
test: test-main test-server
test-main:
- cd $(GO_SRC) && go test
+ cd $(GO_SRC) && go test $(TV)
test-server:
- cd $(GO_SRC) && $(GO_ENV) go test -run TestServer
+ cd $(GO_SRC) && $(GO_ENV) go test $(TV) -run TestServer
test-consul:
- cd $(GO_SRC)/consul && $(GO_ENV) go test
+ cd $(GO_SRC)/consul && $(GO_ENV) go test $(TV)
.lint:
go get -u golang.org/x/lint/golint

MODIFY
go/config_test.go
go/config_test.go
package main
import (
- "fmt"
"testing"
)
func TestCanGetFailoverSetsFromConfig(t *testing.T) {
- fmt.Println("=== CanGetFailoverSetsFromConfig =================================")
c := Config{RedisServers: "a.xxx.com:6379,b.xxx.com:6379"}
expected := FailoverSets{{name: "system", spec: "a.xxx.com:6379,b.xxx.com:6379"}}
actual := c.FailoverSets()

MODIFY
go/consul/consul_test.go
go/consul/consul_test.go
@@ -38,7 +38,6 @@ func init() {
}
func TestConnect(t *testing.T) {
- fmt.Println("=== TestReadingDatacenters =======================================")
client := NewClient(testUrl, testToken, testApp)
client.Initialize()
if !reflect.DeepEqual(client.dataCenters, []string{"ams1", "ams2"}) {
@@ -49,7 +48,6 @@ func TestConnect(t *testing.T) {
}
}
func TestState(t *testing.T) {
- fmt.Println("=== TestUpdatingConsulState ======================================")
client := NewClient(testUrl, testToken, testApp)
client.Initialize()
value := strconv.Itoa(rand.Int())
@@ -66,7 +64,6 @@ func TestState(t *testing.T) {
}
func TestWatching(t *testing.T) {
- fmt.Println("=== TestWatchingConsulKeys =======================================")
client := NewClient(testUrl, testToken, testApp)
client.Initialize()
channel, err := client.WatchConfig()

MODIFY
go/redis_test.go
go/redis_test.go
package main
import (
- "fmt"
"os"
"testing"
)
func TestRedisIsMaster(t *testing.T) {
- fmt.Println("=== RedisIsMaster ================================================")
r := NewRedisShim("127.0.0.1:7001")
isMaster := r.IsMaster()
if !isMaster {
@@ -16,7 +14,6 @@ func TestRedisIsMaster(t *testing.T) {
}
func TestReadMasterFile(t *testing.T) {
- fmt.Println("=== ReadMasterFile ===============================================")
path := "/tmp/test_redis_read_master_file.txt"
if err := WriteRedisMasterFile(path, "127.0.0.1:7001"); err != nil {
t.Errorf("%s", err)
@@ -29,7 +26,6 @@ func TestReadMasterFile(t *testing.T) {
}
func TestRedisIsAvailable(t *testing.T) {
- fmt.Println("=== ReadIsAvailable ==============================================")
r := NewRedisShim("127.0.0.1:7001")
isAvailable := r.IsAvailable()
if !isAvailable {
@@ -38,7 +34,6 @@ func TestRedisIsAvailable(t *testing.T) {
}
func TestRedisNotAvailable(t *testing.T) {
- fmt.Println("=== ReadIsNotAvailable ===========================================")
r := NewRedisShim("127.0.0.1:7003")
isAvailable := r.IsAvailable()
if isAvailable {
@@ -47,7 +42,6 @@ func TestRedisNotAvailable(t *testing.T) {
}
func TestRedisMakeMaster(t *testing.T) {
- fmt.Println("=== RedisMakeMaster ==============================================")
r := NewRedisShim("127.0.0.1:7001")
err := r.MakeMaster()
if err != nil {
@@ -59,7 +53,6 @@ func TestRedisMakeMaster(t *testing.T) {
}
func TestRedisIsSlaveOf(t *testing.T) {
- fmt.Println("=== RedisIsSlaveOf ===============================================")
r := NewRedisShim("127.0.0.1:7002")
if !r.IsSlaveOf("127.0.0.1", 7001) {
t.Errorf("redis should be slave")

MODIFY
go/server_test.go
go/server_test.go
@@ -9,6 +9,7 @@ import (
"os/exec"
"reflect"
"regexp"
+ "strconv"
"strings"
"testing"
"time"
@@ -17,6 +18,7 @@ import (
)
var serverTestOptions = ServerOptions{Config: &Config{ClientTimeout: 1, RedisServers: "beetle/127.0.0.1:7001,127.0.0.1:7002"}}
+var testVerbosity int
func startAndWaitForText(cmd *exec.Cmd, text []string) {
pipe, err := cmd.StdoutPipe()
@@ -25,15 +27,21 @@ func startAndWaitForText(cmd *exec.Cmd, text []string) {
cmd.Process.Kill()
os.Exit(1)
}
+ if testVerbosity > 1 {
log.Println("starting redis server")
+ }
scanner := bufio.NewScanner(pipe)
cmd.Start()
for scanner.Scan() {
line := scanner.Text()
+ if testVerbosity > 1 {
log.Println(line)
+ }
for _, marker := range text {
if strings.Contains(line, marker) {
+ if testVerbosity > 1 {
log.Printf("redis server started: %s", marker)
+ }
return
}
}
@@ -41,7 +49,11 @@ func startAndWaitForText(cmd *exec.Cmd, text []string) {
}
func TestMain(m *testing.M) {
- if os.Getenv("V") != "1" {
+
+ if v, err := strconv.Atoi(os.Getenv("V")); err == nil {
+ testVerbosity = v
+ }
+ if testVerbosity == 0 {
log.SetOutput(ioutil.Discard)
}
cmd, err := exec.LookPath("redis-server")
@@ -62,7 +74,6 @@ func TestMain(m *testing.M) {
}
func TestServerManagingUnresponsiveClients(t *testing.T) {
- fmt.Println("=== ServerManagingUnresponsiveClients ============================")
s := NewServerState(serverTestOptions)
u := s.UnresponsiveClients()
if len(u) != 0 {
@@ -96,12 +107,11 @@ func TestServerManagingUnresponsiveClients(t *testing.T) {
func checkEqual(t *testing.T, actual, expected interface{}) {
if !reflect.DeepEqual(expected, actual) {
t.Errorf("expected %+v to be equal to %+v", actual, expected)
- // spew.Dump(actual, expected)
+ spew.Dump(actual, expected)
}
}
func TestSplitProperties(t *testing.T) {
- fmt.Println("=== SplitProperties ==============================================")
s, expected := "", []string{""}
actual := strings.Split(s, ",")
checkEqual(t, actual, expected)
@@ -125,7 +135,6 @@ func TestSplitProperties(t *testing.T) {
}
func TestSavingAndLoadingState(t *testing.T) {
- fmt.Println("=== TestSavingAndLoadingState ===================================")
s := NewServerState(serverTestOptions)
s.failovers[s.systemNames[0]].currentMaster = NewRedisShim("127.0.0.1:7001")
s.ClientSeen("xxx")
@@ -140,7 +149,6 @@ func TestSavingAndLoadingState(t *testing.T) {
}
func TestClientSeen(t *testing.T) {
- fmt.Println("=== TestClientSeen ===============================================")
s := NewServerState(serverTestOptions)
s.failovers[s.systemNames[0]].currentMaster = NewRedisShim("127.0.0.1:7001")
if s.ClientSeen("xxx") {
@@ -152,7 +160,6 @@ func TestClientSeen(t *testing.T) {
}
func TestUnknownClientIdsSorting(t *testing.T) {
- fmt.Println("=== TestUnknownClientIdsSorting ==================================")
s := NewServerState(serverTestOptions)
s.AddUnknownClientId("yyy")
s.AddUnknownClientId("aaa")

gobeetle: use V=1 or V=2 to get more test verbosity