Parcourir la source

Improve tests suite for nil pointer struct scans

When scanning structs, the test suite wasn't properly verifying that
a pointer field should be nil if the redis field doesn't exist.
Andrew Montgomery il y a 7 ans
Parent
commit
26fa1140da
1 fichiers modifiés avec 7 ajouts et 9 suppressions
  1. 7 9
      redis/scan_test.go

+ 7 - 9
redis/scan_test.go

@@ -223,6 +223,10 @@ var scanStructTests = []struct {
 			Sdp: &durationScan{Duration: time.Minute},
 		},
 	},
+	{"absent values",
+		[]string{},
+		&s1{},
+	},
 }
 
 func TestScanStruct(t *testing.T) {
@@ -416,17 +420,11 @@ var argsTests = []struct {
 	},
 	{"struct omitempty",
 		redis.Args{}.AddFlat(&struct {
-			I  int               `redis:"i,omitempty"`
-			U  uint              `redis:"u,omitempty"`
-			S  string            `redis:"s,omitempty"`
-			P  []byte            `redis:"p,omitempty"`
-			M  map[string]string `redis:"m,omitempty"`
-			Bt bool              `redis:"Bt,omitempty"`
-			Bf bool              `redis:"Bf,omitempty"`
+			Sdp *durationArg `redis:"Sdp,omitempty"`
 		}{
-			0, 0, "", []byte{}, map[string]string{}, true, false,
+			nil,
 		}),
-		redis.Args{"Bt", true},
+		redis.Args{},
 	},
 }