Browse Source

test: add govet to tests

Jonathan Boulle 11 years ago
parent
commit
341c7190d3
4 changed files with 28 additions and 20 deletions
  1. 1 0
      .travis.yml
  2. 17 17
      discovery/discovery_test.go
  3. 3 3
      main.go
  4. 7 0
      test

+ 1 - 0
.travis.yml

@@ -4,6 +4,7 @@ go:
 
 
 install:
 install:
  - go get code.google.com/p/go.tools/cmd/cover
  - go get code.google.com/p/go.tools/cmd/cover
+ - go get code.google.com/p/go.tools/cmd/vet
 
 
 script:
 script:
  - ./test
  - ./test

+ 17 - 17
discovery/discovery_test.go

@@ -98,7 +98,7 @@ func TestCheckCluster(t *testing.T) {
 	}{
 	}{
 		{
 		{
 			// self is in the size range
 			// self is in the size range
-			client.Nodes{
+			[]*client.Node{
 				{Key: "/1000/_config/size", Value: "3", CreatedIndex: 1},
 				{Key: "/1000/_config/size", Value: "3", CreatedIndex: 1},
 				{Key: self, CreatedIndex: 2},
 				{Key: self, CreatedIndex: 2},
 				{Key: "/1000/2", CreatedIndex: 3},
 				{Key: "/1000/2", CreatedIndex: 3},
@@ -110,7 +110,7 @@ func TestCheckCluster(t *testing.T) {
 		},
 		},
 		{
 		{
 			// self is in the size range
 			// self is in the size range
-			client.Nodes{
+			[]*client.Node{
 				{Key: "/1000/_config/size", Value: "3", CreatedIndex: 1},
 				{Key: "/1000/_config/size", Value: "3", CreatedIndex: 1},
 				{Key: "/1000/2", CreatedIndex: 2},
 				{Key: "/1000/2", CreatedIndex: 2},
 				{Key: "/1000/3", CreatedIndex: 3},
 				{Key: "/1000/3", CreatedIndex: 3},
@@ -122,7 +122,7 @@ func TestCheckCluster(t *testing.T) {
 		},
 		},
 		{
 		{
 			// self is out of the size range
 			// self is out of the size range
-			client.Nodes{
+			[]*client.Node{
 				{Key: "/1000/_config/size", Value: "3", CreatedIndex: 1},
 				{Key: "/1000/_config/size", Value: "3", CreatedIndex: 1},
 				{Key: "/1000/2", CreatedIndex: 2},
 				{Key: "/1000/2", CreatedIndex: 2},
 				{Key: "/1000/3", CreatedIndex: 3},
 				{Key: "/1000/3", CreatedIndex: 3},
@@ -134,7 +134,7 @@ func TestCheckCluster(t *testing.T) {
 		},
 		},
 		{
 		{
 			// self is not in the cluster
 			// self is not in the cluster
-			client.Nodes{
+			[]*client.Node{
 				{Key: "/1000/_config/size", Value: "3", CreatedIndex: 1},
 				{Key: "/1000/_config/size", Value: "3", CreatedIndex: 1},
 				{Key: "/1000/2", CreatedIndex: 2},
 				{Key: "/1000/2", CreatedIndex: 2},
 				{Key: "/1000/3", CreatedIndex: 3},
 				{Key: "/1000/3", CreatedIndex: 3},
@@ -143,7 +143,7 @@ func TestCheckCluster(t *testing.T) {
 			3,
 			3,
 		},
 		},
 		{
 		{
-			client.Nodes{
+			[]*client.Node{
 				{Key: "/1000/_config/size", Value: "3", CreatedIndex: 1},
 				{Key: "/1000/_config/size", Value: "3", CreatedIndex: 1},
 				{Key: "/1000/2", CreatedIndex: 2},
 				{Key: "/1000/2", CreatedIndex: 2},
 				{Key: "/1000/3", CreatedIndex: 3},
 				{Key: "/1000/3", CreatedIndex: 3},
@@ -154,7 +154,7 @@ func TestCheckCluster(t *testing.T) {
 		},
 		},
 		{
 		{
 			// bad size key
 			// bad size key
-			client.Nodes{
+			[]*client.Node{
 				{Key: "/1000/_config/size", Value: "bad", CreatedIndex: 1},
 				{Key: "/1000/_config/size", Value: "bad", CreatedIndex: 1},
 			},
 			},
 			ErrBadSizeKey,
 			ErrBadSizeKey,
@@ -162,7 +162,7 @@ func TestCheckCluster(t *testing.T) {
 		},
 		},
 		{
 		{
 			// no size key
 			// no size key
-			client.Nodes{},
+			[]*client.Node{},
 			ErrSizeNotFound,
 			ErrSizeNotFound,
 			0,
 			0,
 		},
 		},
@@ -210,9 +210,9 @@ func TestCheckCluster(t *testing.T) {
 
 
 func TestWaitNodes(t *testing.T) {
 func TestWaitNodes(t *testing.T) {
 	all := client.Nodes{
 	all := client.Nodes{
-		{Key: "/1000/1", CreatedIndex: 2},
-		{Key: "/1000/2", CreatedIndex: 3},
-		{Key: "/1000/3", CreatedIndex: 4},
+		0: {Key: "/1000/1", CreatedIndex: 2},
+		1: {Key: "/1000/2", CreatedIndex: 3},
+		2: {Key: "/1000/3", CreatedIndex: 4},
 	}
 	}
 
 
 	tests := []struct {
 	tests := []struct {
@@ -325,9 +325,9 @@ func TestCreateSelf(t *testing.T) {
 
 
 func TestNodesToCluster(t *testing.T) {
 func TestNodesToCluster(t *testing.T) {
 	nodes := client.Nodes{
 	nodes := client.Nodes{
-		{Key: "/1000/1", Value: "1=1.1.1.1", CreatedIndex: 1},
-		{Key: "/1000/2", Value: "2=2.2.2.2", CreatedIndex: 2},
-		{Key: "/1000/3", Value: "3=3.3.3.3", CreatedIndex: 3},
+		0: {Key: "/1000/1", Value: "1=1.1.1.1", CreatedIndex: 1},
+		1: {Key: "/1000/2", Value: "2=2.2.2.2", CreatedIndex: 2},
+		2: {Key: "/1000/3", Value: "3=3.3.3.3", CreatedIndex: 3},
 	}
 	}
 	w := "1=1.1.1.1,2=2.2.2.2,3=3.3.3.3"
 	w := "1=1.1.1.1,2=2.2.2.2,3=3.3.3.3"
 
 
@@ -339,10 +339,10 @@ func TestNodesToCluster(t *testing.T) {
 
 
 func TestSortableNodes(t *testing.T) {
 func TestSortableNodes(t *testing.T) {
 	ns := client.Nodes{
 	ns := client.Nodes{
-		{CreatedIndex: 5},
-		{CreatedIndex: 1},
-		{CreatedIndex: 3},
-		{CreatedIndex: 4},
+		0: {CreatedIndex: 5},
+		1: {CreatedIndex: 1},
+		2: {CreatedIndex: 3},
+		3: {CreatedIndex: 4},
 	}
 	}
 	// add some randomness
 	// add some randomness
 	for i := 0; i < 10000; i++ {
 	for i := 0; i < 10000; i++ {

+ 3 - 3
main.go

@@ -107,11 +107,11 @@ func init() {
 	fs.Var(&flagtypes.IPAddressPort{}, "peer-bind-addr", "DEPRECATED: Use -listen-peer-urls instead.")
 	fs.Var(&flagtypes.IPAddressPort{}, "peer-bind-addr", "DEPRECATED: Use -listen-peer-urls instead.")
 
 
 	for _, f := range ignored {
 	for _, f := range ignored {
-		fs.Var(&pkg.IgnoredFlag{f}, f, "")
+		fs.Var(&pkg.IgnoredFlag{Name: f}, f, "")
 	}
 	}
 
 
-	fs.Var(&pkg.DeprecatedFlag{"peers"}, "peers", "DEPRECATED: Use -initial-cluster instead")
-	fs.Var(&pkg.DeprecatedFlag{"peers-file"}, "peers-file", "DEPRECATED: Use -initial-cluster instead")
+	fs.Var(&pkg.DeprecatedFlag{Name: "peers"}, "peers", "DEPRECATED: Use -initial-cluster instead")
+	fs.Var(&pkg.DeprecatedFlag{Name: "peers-file"}, "peers-file", "DEPRECATED: Use -initial-cluster instead")
 }
 }
 
 
 func main() {
 func main() {

+ 7 - 0
test

@@ -49,4 +49,11 @@ if [ -n "${fmtRes}" ]; then
 	exit 255
 	exit 255
 fi
 fi
 
 
+echo "Checking govet..."
+vetRes=$(go vet $TEST)
+if [ -n "${vetRes}" ]; then
+	echo -e "govet checking failed:\n${vetRes}"
+	exit 255
+fi
+
 echo "Success"
 echo "Success"