Fix for typecheck doesn't notice compile errors in test files
- ensure we add all the staging modules so the _test files in there are "loaded" - use build tags to skip tests that fail to build in specific os/arch pairs Signed-off-by: Davanum Srinivas <davanum@gmail.com> Co-Authored-By: Tim Hockin <thockin@google.com>
This commit is contained in:
		| @@ -26,6 +26,17 @@ source "${KUBE_ROOT}/hack/lib/init.sh" | |||||||
| cd "${KUBE_ROOT}" | cd "${KUBE_ROOT}" | ||||||
|  |  | ||||||
| kube::golang::setup_env | kube::golang::setup_env | ||||||
|  | kube::util::require-jq | ||||||
|  |  | ||||||
|  | if [[ $# == 0 ]]; then | ||||||
|  |   # Doing it this way is MUCH faster than simply saying "all", and there doesn't | ||||||
|  |   # seem to be a simpler way to express "this whole workspace". | ||||||
|  |   packages=() | ||||||
|  |   kube::util::read-array packages < <( | ||||||
|  |       go work edit -json | jq -r '.Use[].DiskPath + "/..."' | ||||||
|  |   ) | ||||||
|  |   set -- "${packages[@]}" | ||||||
|  | fi | ||||||
|  |  | ||||||
| ret=0 | ret=0 | ||||||
| TYPECHECK_SERIAL="${TYPECHECK_SERIAL:-false}" | TYPECHECK_SERIAL="${TYPECHECK_SERIAL:-false}" | ||||||
|   | |||||||
| @@ -37,17 +37,19 @@ func TestCelCostStability(t *testing.T) { | |||||||
| 	}{ | 	}{ | ||||||
| 		{name: "integers", | 		{name: "integers", | ||||||
| 			// 1st obj and schema args are for "self.val1" field, 2nd for "self.val2" and so on. | 			// 1st obj and schema args are for "self.val1" field, 2nd for "self.val2" and so on. | ||||||
| 			obj:    objs(math.MaxInt64, math.MaxInt64, math.MaxInt32, math.MaxInt32, math.MaxInt64, math.MaxInt64), | 			obj: objs(int64(math.MaxInt64), int64(math.MaxInt64), int32(math.MaxInt32), int32(math.MaxInt32), | ||||||
|  | 				int64(math.MaxInt64), int64(math.MaxInt64)), | ||||||
| 			schema: schemas(integerType, integerType, int32Type, int32Type, int64Type, int64Type), | 			schema: schemas(integerType, integerType, int32Type, int32Type, int64Type, int64Type), | ||||||
| 			expectCost: map[string]int64{ | 			expectCost: map[string]int64{ | ||||||
| 				ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%d", math.MaxInt64)): 11, | 				ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%d", int64(math.MaxInt64))): 11, | ||||||
| 				"self.val1 == self.val6":                              5, // integer with no format is the same as int64 | 				"self.val1 == self.val6":                              5, // integer with no format is the same as int64 | ||||||
| 				"type(self.val1) == int":                              4, | 				"type(self.val1) == int":                              4, | ||||||
| 				fmt.Sprintf("self.val3 + 1 == %d + 1", math.MaxInt32): 5, // CEL integers are 64 bit | 				fmt.Sprintf("self.val3 + 1 == %d + 1", math.MaxInt32): 5, // CEL integers are 64 bit | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		{name: "numbers", | 		{name: "numbers", | ||||||
| 			obj:    objs(math.MaxFloat64, math.MaxFloat64, math.MaxFloat32, math.MaxFloat32, math.MaxFloat64, math.MaxFloat64, int64(1)), | 			obj: objs(float64(math.MaxFloat64), float64(math.MaxFloat64), float32(math.MaxFloat32), float32(math.MaxFloat32), | ||||||
|  | 				float64(math.MaxFloat64), float64(math.MaxFloat64), int64(1)), | ||||||
| 			schema: schemas(numberType, numberType, floatType, floatType, doubleType, doubleType, doubleType), | 			schema: schemas(numberType, numberType, floatType, floatType, doubleType, doubleType, doubleType), | ||||||
| 			expectCost: map[string]int64{ | 			expectCost: map[string]int64{ | ||||||
| 				ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%f", math.MaxFloat64)): 11, | 				ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%f", math.MaxFloat64)): 11, | ||||||
| @@ -1218,7 +1220,7 @@ func TestCelEstimatedCostStability(t *testing.T) { | |||||||
| 			// 1st obj and schema args are for "self.val1" field, 2nd for "self.val2" and so on. | 			// 1st obj and schema args are for "self.val1" field, 2nd for "self.val2" and so on. | ||||||
| 			schema: schemas(integerType, integerType, int32Type, int32Type, int64Type, int64Type), | 			schema: schemas(integerType, integerType, int32Type, int32Type, int64Type, int64Type), | ||||||
| 			expectCost: map[string]uint64{ | 			expectCost: map[string]uint64{ | ||||||
| 				ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%d", math.MaxInt64)): 8, | 				ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%d", int64(math.MaxInt64))): 8, | ||||||
| 				"self.val1 == self.val6":                              4, // integer with no format is the same as int64 | 				"self.val1 == self.val6":                              4, // integer with no format is the same as int64 | ||||||
| 				"type(self.val1) == int":                              4, | 				"type(self.val1) == int":                              4, | ||||||
| 				fmt.Sprintf("self.val3 + 1 == %d + 1", math.MaxInt32): 5, // CEL integers are 64 bit | 				fmt.Sprintf("self.val3 + 1 == %d + 1", math.MaxInt32): 5, // CEL integers are 64 bit | ||||||
|   | |||||||
| @@ -67,12 +67,13 @@ func TestValidationExpressions(t *testing.T) { | |||||||
| 		// equality, comparisons and type specific functions | 		// equality, comparisons and type specific functions | ||||||
| 		{name: "integers", | 		{name: "integers", | ||||||
| 			// 1st obj and schema args are for "self.val1" field, 2nd for "self.val2" and so on. | 			// 1st obj and schema args are for "self.val1" field, 2nd for "self.val2" and so on. | ||||||
| 			obj:    objs(math.MaxInt64, math.MaxInt64, math.MaxInt32, math.MaxInt32, math.MaxInt64, math.MaxInt64), | 			obj: objs(int64(math.MaxInt64), int64(math.MaxInt64), int32(math.MaxInt32), int32(math.MaxInt32), | ||||||
|  | 				int64(math.MaxInt64), int64(math.MaxInt64)), | ||||||
| 			schema: schemas(integerType, integerType, int32Type, int32Type, int64Type, int64Type), | 			schema: schemas(integerType, integerType, int32Type, int32Type, int64Type, int64Type), | ||||||
| 			valid: []string{ | 			valid: []string{ | ||||||
| 				ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%d", math.MaxInt64)), | 				ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%d", int64(math.MaxInt64))), | ||||||
| 				ValsEqualThemselvesAndDataLiteral("self.val3", "self.val4", fmt.Sprintf("%d", math.MaxInt32)), | 				ValsEqualThemselvesAndDataLiteral("self.val3", "self.val4", fmt.Sprintf("%d", math.MaxInt32)), | ||||||
| 				ValsEqualThemselvesAndDataLiteral("self.val5", "self.val6", fmt.Sprintf("%d", math.MaxInt64)), | 				ValsEqualThemselvesAndDataLiteral("self.val5", "self.val6", fmt.Sprintf("%d", int64(math.MaxInt64))), | ||||||
| 				"self.val1 == self.val6", // integer with no format is the same as int64 | 				"self.val1 == self.val6", // integer with no format is the same as int64 | ||||||
| 				"type(self.val1) == int", | 				"type(self.val1) == int", | ||||||
| 				fmt.Sprintf("self.val3 + 1 == %d + 1", math.MaxInt32), // CEL integers are 64 bit | 				fmt.Sprintf("self.val3 + 1 == %d + 1", math.MaxInt32), // CEL integers are 64 bit | ||||||
| @@ -86,7 +87,8 @@ func TestValidationExpressions(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		{name: "numbers", | 		{name: "numbers", | ||||||
| 			obj:    objs(math.MaxFloat64, math.MaxFloat64, math.MaxFloat32, math.MaxFloat32, math.MaxFloat64, math.MaxFloat64, int64(1)), | 			obj: objs(float64(math.MaxFloat64), float64(math.MaxFloat64), float32(math.MaxFloat32), float32(math.MaxFloat32), | ||||||
|  | 				float64(math.MaxFloat64), float64(math.MaxFloat64), int64(1)), | ||||||
| 			schema: schemas(numberType, numberType, floatType, floatType, doubleType, doubleType, doubleType), | 			schema: schemas(numberType, numberType, floatType, floatType, doubleType, doubleType, doubleType), | ||||||
| 			valid: []string{ | 			valid: []string{ | ||||||
| 				ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%f", math.MaxFloat64)), | 				ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%f", math.MaxFloat64)), | ||||||
| @@ -2842,7 +2844,7 @@ func TestCELValidationLimit(t *testing.T) { | |||||||
| 	}{ | 	}{ | ||||||
| 		{ | 		{ | ||||||
| 			name:   "test limit", | 			name:   "test limit", | ||||||
| 			obj:    objs(math.MaxInt64), | 			obj:    objs(int64(math.MaxInt64)), | ||||||
| 			schema: schemas(integerType), | 			schema: schemas(integerType), | ||||||
| 			valid: []string{ | 			valid: []string{ | ||||||
| 				"self.val1 > 0", | 				"self.val1 > 0", | ||||||
|   | |||||||
| @@ -1,3 +1,6 @@ | |||||||
|  | //go:build !windows | ||||||
|  | // +build !windows | ||||||
|  |  | ||||||
| /* | /* | ||||||
| Copyright 2022 The Kubernetes Authors. | Copyright 2022 The Kubernetes Authors. | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,3 +1,6 @@ | |||||||
|  | //go:build !windows | ||||||
|  | // +build !windows | ||||||
|  |  | ||||||
| /* | /* | ||||||
| Copyright 2022 The Kubernetes Authors. | Copyright 2022 The Kubernetes Authors. | ||||||
|  |  | ||||||
|   | |||||||
| @@ -96,7 +96,7 @@ func TestVModule(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			arg:         fmt.Sprintf("invalidint32=%d", math.MaxInt32+1), | 			arg:         fmt.Sprintf("invalidint32=%d", uint(math.MaxInt32+1)), | ||||||
| 			expectError: `parsing verbosity in "invalidint32=2147483648": strconv.ParseUint: parsing "2147483648": value out of range`, | 			expectError: `parsing verbosity in "invalidint32=2147483648": strconv.ParseUint: parsing "2147483648": value out of range`, | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -32,6 +32,7 @@ import ( | |||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
| 	"github.com/stretchr/testify/assert" | 	"github.com/stretchr/testify/assert" | ||||||
|  | 	"golang.org/x/exp/constraints" | ||||||
| 	"golang.org/x/sys/unix" | 	"golang.org/x/sys/unix" | ||||||
| 	utilexec "k8s.io/utils/exec" | 	utilexec "k8s.io/utils/exec" | ||||||
| 	testexec "k8s.io/utils/exec/testing" | 	testexec "k8s.io/utils/exec/testing" | ||||||
| @@ -814,9 +815,15 @@ func TestFormatTimeout(t *testing.T) { | |||||||
| 	mu.Unlock() | 	mu.Unlock() | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // Some platforms define unix.Statfs_t.Flags differently.  Our need here is | ||||||
|  | // pretty constrained, so some aggressive type-conversion is OK. | ||||||
|  | func mkStatfsFlags[T1 constraints.Integer, T2 constraints.Integer](orig T1, add T2) T1 { | ||||||
|  | 	return orig | T1(add) | ||||||
|  | } | ||||||
|  |  | ||||||
| func TestGetUserNSBindMountOptions(t *testing.T) { | func TestGetUserNSBindMountOptions(t *testing.T) { | ||||||
| 	var testCases = map[string]struct { | 	var testCases = map[string]struct { | ||||||
| 		flags        int64 | 		flags        int32 // smallest size used by any platform we care about | ||||||
| 		mountoptions string | 		mountoptions string | ||||||
| 	}{ | 	}{ | ||||||
| 		"ro":            {flags: unix.MS_RDONLY, mountoptions: "ro"}, | 		"ro":            {flags: unix.MS_RDONLY, mountoptions: "ro"}, | ||||||
| @@ -831,7 +838,8 @@ func TestGetUserNSBindMountOptions(t *testing.T) { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	statfsMock := func(path string, buf *unix.Statfs_t) (err error) { | 	statfsMock := func(path string, buf *unix.Statfs_t) (err error) { | ||||||
| 		*buf = unix.Statfs_t{Flags: testCases[path].flags} | 		*buf = unix.Statfs_t{} | ||||||
|  | 		buf.Flags = mkStatfsFlags(buf.Flags, testCases[path].flags) | ||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Davanum Srinivas
					Davanum Srinivas