Skip to content

Commit c87c06d

Browse files
authored
Merge pull request kubernetes#125850 from dims/fix-for-typecheck-does-not-notice-compile-errors-in-test-files
Fix for typecheck doesn't notice compile errors in test files
2 parents 6698fb7 + c230a45 commit c87c06d

File tree

7 files changed

+41
-12
lines changed

7 files changed

+41
-12
lines changed

hack/verify-typecheck.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
2626
cd "${KUBE_ROOT}"
2727

2828
kube::golang::setup_env
29+
kube::util::require-jq
30+
31+
if [[ $# == 0 ]]; then
32+
# Doing it this way is MUCH faster than simply saying "all", and there doesn't
33+
# seem to be a simpler way to express "this whole workspace".
34+
packages=()
35+
kube::util::read-array packages < <(
36+
go work edit -json | jq -r '.Use[].DiskPath + "/..."'
37+
)
38+
set -- "${packages[@]}"
39+
fi
2940

3041
ret=0
3142
TYPECHECK_SERIAL="${TYPECHECK_SERIAL:-false}"

staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/celcoststability_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,19 @@ func TestCelCostStability(t *testing.T) {
3737
}{
3838
{name: "integers",
3939
// 1st obj and schema args are for "self.val1" field, 2nd for "self.val2" and so on.
40-
obj: objs(math.MaxInt64, math.MaxInt64, math.MaxInt32, math.MaxInt32, math.MaxInt64, math.MaxInt64),
40+
obj: objs(int64(math.MaxInt64), int64(math.MaxInt64), int32(math.MaxInt32), int32(math.MaxInt32),
41+
int64(math.MaxInt64), int64(math.MaxInt64)),
4142
schema: schemas(integerType, integerType, int32Type, int32Type, int64Type, int64Type),
4243
expectCost: map[string]int64{
43-
ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%d", math.MaxInt64)): 11,
44+
ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%d", int64(math.MaxInt64))): 11,
4445
"self.val1 == self.val6": 5, // integer with no format is the same as int64
4546
"type(self.val1) == int": 4,
4647
fmt.Sprintf("self.val3 + 1 == %d + 1", math.MaxInt32): 5, // CEL integers are 64 bit
4748
},
4849
},
4950
{name: "numbers",
50-
obj: objs(math.MaxFloat64, math.MaxFloat64, math.MaxFloat32, math.MaxFloat32, math.MaxFloat64, math.MaxFloat64, int64(1)),
51+
obj: objs(float64(math.MaxFloat64), float64(math.MaxFloat64), float32(math.MaxFloat32), float32(math.MaxFloat32),
52+
float64(math.MaxFloat64), float64(math.MaxFloat64), int64(1)),
5153
schema: schemas(numberType, numberType, floatType, floatType, doubleType, doubleType, doubleType),
5254
expectCost: map[string]int64{
5355
ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%f", math.MaxFloat64)): 11,
@@ -1218,7 +1220,7 @@ func TestCelEstimatedCostStability(t *testing.T) {
12181220
// 1st obj and schema args are for "self.val1" field, 2nd for "self.val2" and so on.
12191221
schema: schemas(integerType, integerType, int32Type, int32Type, int64Type, int64Type),
12201222
expectCost: map[string]uint64{
1221-
ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%d", math.MaxInt64)): 8,
1223+
ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%d", int64(math.MaxInt64))): 8,
12221224
"self.val1 == self.val6": 4, // integer with no format is the same as int64
12231225
"type(self.val1) == int": 4,
12241226
fmt.Sprintf("self.val3 + 1 == %d + 1", math.MaxInt32): 5, // CEL integers are 64 bit

staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/validation_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ func TestValidationExpressions(t *testing.T) {
6767
// equality, comparisons and type specific functions
6868
{name: "integers",
6969
// 1st obj and schema args are for "self.val1" field, 2nd for "self.val2" and so on.
70-
obj: objs(math.MaxInt64, math.MaxInt64, math.MaxInt32, math.MaxInt32, math.MaxInt64, math.MaxInt64),
70+
obj: objs(int64(math.MaxInt64), int64(math.MaxInt64), int32(math.MaxInt32), int32(math.MaxInt32),
71+
int64(math.MaxInt64), int64(math.MaxInt64)),
7172
schema: schemas(integerType, integerType, int32Type, int32Type, int64Type, int64Type),
7273
valid: []string{
73-
ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%d", math.MaxInt64)),
74+
ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%d", int64(math.MaxInt64))),
7475
ValsEqualThemselvesAndDataLiteral("self.val3", "self.val4", fmt.Sprintf("%d", math.MaxInt32)),
75-
ValsEqualThemselvesAndDataLiteral("self.val5", "self.val6", fmt.Sprintf("%d", math.MaxInt64)),
76+
ValsEqualThemselvesAndDataLiteral("self.val5", "self.val6", fmt.Sprintf("%d", int64(math.MaxInt64))),
7677
"self.val1 == self.val6", // integer with no format is the same as int64
7778
"type(self.val1) == int",
7879
fmt.Sprintf("self.val3 + 1 == %d + 1", math.MaxInt32), // CEL integers are 64 bit
@@ -86,7 +87,8 @@ func TestValidationExpressions(t *testing.T) {
8687
},
8788
},
8889
{name: "numbers",
89-
obj: objs(math.MaxFloat64, math.MaxFloat64, math.MaxFloat32, math.MaxFloat32, math.MaxFloat64, math.MaxFloat64, int64(1)),
90+
obj: objs(float64(math.MaxFloat64), float64(math.MaxFloat64), float32(math.MaxFloat32), float32(math.MaxFloat32),
91+
float64(math.MaxFloat64), float64(math.MaxFloat64), int64(1)),
9092
schema: schemas(numberType, numberType, floatType, floatType, doubleType, doubleType, doubleType),
9193
valid: []string{
9294
ValsEqualThemselvesAndDataLiteral("self.val1", "self.val2", fmt.Sprintf("%f", math.MaxFloat64)),
@@ -2842,7 +2844,7 @@ func TestCELValidationLimit(t *testing.T) {
28422844
}{
28432845
{
28442846
name: "test limit",
2845-
obj: objs(math.MaxInt64),
2847+
obj: objs(int64(math.MaxInt64)),
28462848
schema: schemas(integerType),
28472849
valid: []string{
28482850
"self.val1 > 0",

staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/envelope_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build !windows
2+
// +build !windows
3+
14
/*
25
Copyright 2022 The Kubernetes Authors.
36

staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/grpc_service_unix_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build !windows
2+
// +build !windows
3+
14
/*
25
Copyright 2022 The Kubernetes Authors.
36

staging/src/k8s.io/component-base/logs/api/v1/types_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestVModule(t *testing.T) {
9696
},
9797
},
9898
{
99-
arg: fmt.Sprintf("invalidint32=%d", math.MaxInt32+1),
99+
arg: fmt.Sprintf("invalidint32=%d", uint(math.MaxInt32+1)),
100100
expectError: `parsing verbosity in "invalidint32=2147483648": strconv.ParseUint: parsing "2147483648": value out of range`,
101101
},
102102
}

staging/src/k8s.io/mount-utils/mount_linux_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"time"
3333

3434
"github.com/stretchr/testify/assert"
35+
"golang.org/x/exp/constraints"
3536
"golang.org/x/sys/unix"
3637
utilexec "k8s.io/utils/exec"
3738
testexec "k8s.io/utils/exec/testing"
@@ -814,9 +815,15 @@ func TestFormatTimeout(t *testing.T) {
814815
mu.Unlock()
815816
}
816817

818+
// Some platforms define unix.Statfs_t.Flags differently. Our need here is
819+
// pretty constrained, so some aggressive type-conversion is OK.
820+
func mkStatfsFlags[T1 constraints.Integer, T2 constraints.Integer](orig T1, add T2) T1 {
821+
return orig | T1(add)
822+
}
823+
817824
func TestGetUserNSBindMountOptions(t *testing.T) {
818825
var testCases = map[string]struct {
819-
flags int64
826+
flags int32 // smallest size used by any platform we care about
820827
mountoptions string
821828
}{
822829
"ro": {flags: unix.MS_RDONLY, mountoptions: "ro"},
@@ -831,7 +838,8 @@ func TestGetUserNSBindMountOptions(t *testing.T) {
831838
}
832839

833840
statfsMock := func(path string, buf *unix.Statfs_t) (err error) {
834-
*buf = unix.Statfs_t{Flags: testCases[path].flags}
841+
*buf = unix.Statfs_t{}
842+
buf.Flags = mkStatfsFlags(buf.Flags, testCases[path].flags)
835843
return nil
836844
}
837845

0 commit comments

Comments
 (0)