From 5de01f62bdf0707c114746518b65bb015b4dbe25 Mon Sep 17 00:00:00 2001 From: Gregory Haynes Date: Wed, 19 Sep 2018 22:23:17 +0000 Subject: [PATCH] Enforce all code dirs have tests In order to get accurate coverage results we attempt to always have a _test.go file in directories with code. Add a test to enfoce this in CI and add stub_tests.go to dirs which fail this test. --- cmd/controller/stub_test.go | 24 +++++++++++++++++++ cmd/sendevent/stub_test.go | 24 +++++++++++++++++++ cmd/webhook/stub_test.go | 24 +++++++++++++++++++ pkg/apis/channels/logkey/stub_test.go | 24 +++++++++++++++++++ pkg/apis/channels/stub_test.go | 24 +++++++++++++++++++ pkg/apis/eventing/logkey/stub_test.go | 24 +++++++++++++++++++ pkg/apis/eventing/stub_test.go | 24 +++++++++++++++++++ pkg/apis/feeds/logkey/stub_test.go | 24 +++++++++++++++++++ pkg/apis/feeds/stub_test.go | 24 +++++++++++++++++++ pkg/apis/flows/logkey/stub_test.go | 24 +++++++++++++++++++ pkg/apis/flows/stub_test.go | 24 +++++++++++++++++++ pkg/buses/gcppubsub/dispatcher/stub_test.go | 24 +++++++++++++++++++ pkg/buses/gcppubsub/provisioner/stub_test.go | 24 +++++++++++++++++++ pkg/buses/kafka/dispatcher/stub_test.go | 24 +++++++++++++++++++ pkg/buses/kafka/provisioner/stub_test.go | 24 +++++++++++++++++++ pkg/buses/stub/dispatcher/stub_test.go | 24 +++++++++++++++++++ pkg/controller/testing/stub_test.go | 24 +++++++++++++++++++ pkg/logconfig/stub_test.go | 24 +++++++++++++++++++ pkg/system/stub_test.go | 24 +++++++++++++++++++ test/presubmit-tests.sh | 25 ++++++++++++++++++++ 20 files changed, 481 insertions(+) create mode 100644 cmd/controller/stub_test.go create mode 100644 cmd/sendevent/stub_test.go create mode 100644 cmd/webhook/stub_test.go create mode 100644 pkg/apis/channels/logkey/stub_test.go create mode 100644 pkg/apis/channels/stub_test.go create mode 100644 pkg/apis/eventing/logkey/stub_test.go create mode 100644 pkg/apis/eventing/stub_test.go create mode 100644 pkg/apis/feeds/logkey/stub_test.go create mode 100644 pkg/apis/feeds/stub_test.go create mode 100644 pkg/apis/flows/logkey/stub_test.go create mode 100644 pkg/apis/flows/stub_test.go create mode 100644 pkg/buses/gcppubsub/dispatcher/stub_test.go create mode 100644 pkg/buses/gcppubsub/provisioner/stub_test.go create mode 100644 pkg/buses/kafka/dispatcher/stub_test.go create mode 100644 pkg/buses/kafka/provisioner/stub_test.go create mode 100644 pkg/buses/stub/dispatcher/stub_test.go create mode 100644 pkg/controller/testing/stub_test.go create mode 100644 pkg/logconfig/stub_test.go create mode 100644 pkg/system/stub_test.go diff --git a/cmd/controller/stub_test.go b/cmd/controller/stub_test.go new file mode 100644 index 00000000000..ee7bbe8c445 --- /dev/null +++ b/cmd/controller/stub_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import "testing" + +func TestStub(t *testing.T) { + // TODO: Implement tests in this directory, please. + // This file is used to make code coverage on this directly count. +} diff --git a/cmd/sendevent/stub_test.go b/cmd/sendevent/stub_test.go new file mode 100644 index 00000000000..ee7bbe8c445 --- /dev/null +++ b/cmd/sendevent/stub_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import "testing" + +func TestStub(t *testing.T) { + // TODO: Implement tests in this directory, please. + // This file is used to make code coverage on this directly count. +} diff --git a/cmd/webhook/stub_test.go b/cmd/webhook/stub_test.go new file mode 100644 index 00000000000..ee7bbe8c445 --- /dev/null +++ b/cmd/webhook/stub_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import "testing" + +func TestStub(t *testing.T) { + // TODO: Implement tests in this directory, please. + // This file is used to make code coverage on this directly count. +} diff --git a/pkg/apis/channels/logkey/stub_test.go b/pkg/apis/channels/logkey/stub_test.go new file mode 100644 index 00000000000..1110130e467 --- /dev/null +++ b/pkg/apis/channels/logkey/stub_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package logkey + +import "testing" + +func TestStub(t *testing.T) { + // TODO: Implement tests in this directory, please. + // This file is used to make code coverage on this directly count. +} diff --git a/pkg/apis/channels/stub_test.go b/pkg/apis/channels/stub_test.go new file mode 100644 index 00000000000..76eae57d597 --- /dev/null +++ b/pkg/apis/channels/stub_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package channels + +import "testing" + +func TestStub(t *testing.T) { + // TODO: Implement tests in this directory, please. + // This file is used to make code coverage on this directly count. +} diff --git a/pkg/apis/eventing/logkey/stub_test.go b/pkg/apis/eventing/logkey/stub_test.go new file mode 100644 index 00000000000..1110130e467 --- /dev/null +++ b/pkg/apis/eventing/logkey/stub_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package logkey + +import "testing" + +func TestStub(t *testing.T) { + // TODO: Implement tests in this directory, please. + // This file is used to make code coverage on this directly count. +} diff --git a/pkg/apis/eventing/stub_test.go b/pkg/apis/eventing/stub_test.go new file mode 100644 index 00000000000..2626ba07e9e --- /dev/null +++ b/pkg/apis/eventing/stub_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package eventing + +import "testing" + +func TestStub(t *testing.T) { + // TODO: Implement tests in this directory, please. + // This file is used to make code coverage on this directly count. +} diff --git a/pkg/apis/feeds/logkey/stub_test.go b/pkg/apis/feeds/logkey/stub_test.go new file mode 100644 index 00000000000..1110130e467 --- /dev/null +++ b/pkg/apis/feeds/logkey/stub_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package logkey + +import "testing" + +func TestStub(t *testing.T) { + // TODO: Implement tests in this directory, please. + // This file is used to make code coverage on this directly count. +} diff --git a/pkg/apis/feeds/stub_test.go b/pkg/apis/feeds/stub_test.go new file mode 100644 index 00000000000..713914ca8c0 --- /dev/null +++ b/pkg/apis/feeds/stub_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package feeds + +import "testing" + +func TestStub(t *testing.T) { + // TODO: Implement tests in this directory, please. + // This file is used to make code coverage on this directly count. +} diff --git a/pkg/apis/flows/logkey/stub_test.go b/pkg/apis/flows/logkey/stub_test.go new file mode 100644 index 00000000000..1110130e467 --- /dev/null +++ b/pkg/apis/flows/logkey/stub_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package logkey + +import "testing" + +func TestStub(t *testing.T) { + // TODO: Implement tests in this directory, please. + // This file is used to make code coverage on this directly count. +} diff --git a/pkg/apis/flows/stub_test.go b/pkg/apis/flows/stub_test.go new file mode 100644 index 00000000000..f1ad3d83e9b --- /dev/null +++ b/pkg/apis/flows/stub_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package flows + +import "testing" + +func TestStub(t *testing.T) { + // TODO: Implement tests in this directory, please. + // This file is used to make code coverage on this directly count. +} diff --git a/pkg/buses/gcppubsub/dispatcher/stub_test.go b/pkg/buses/gcppubsub/dispatcher/stub_test.go new file mode 100644 index 00000000000..ee7bbe8c445 --- /dev/null +++ b/pkg/buses/gcppubsub/dispatcher/stub_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import "testing" + +func TestStub(t *testing.T) { + // TODO: Implement tests in this directory, please. + // This file is used to make code coverage on this directly count. +} diff --git a/pkg/buses/gcppubsub/provisioner/stub_test.go b/pkg/buses/gcppubsub/provisioner/stub_test.go new file mode 100644 index 00000000000..ee7bbe8c445 --- /dev/null +++ b/pkg/buses/gcppubsub/provisioner/stub_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import "testing" + +func TestStub(t *testing.T) { + // TODO: Implement tests in this directory, please. + // This file is used to make code coverage on this directly count. +} diff --git a/pkg/buses/kafka/dispatcher/stub_test.go b/pkg/buses/kafka/dispatcher/stub_test.go new file mode 100644 index 00000000000..ee7bbe8c445 --- /dev/null +++ b/pkg/buses/kafka/dispatcher/stub_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import "testing" + +func TestStub(t *testing.T) { + // TODO: Implement tests in this directory, please. + // This file is used to make code coverage on this directly count. +} diff --git a/pkg/buses/kafka/provisioner/stub_test.go b/pkg/buses/kafka/provisioner/stub_test.go new file mode 100644 index 00000000000..ee7bbe8c445 --- /dev/null +++ b/pkg/buses/kafka/provisioner/stub_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import "testing" + +func TestStub(t *testing.T) { + // TODO: Implement tests in this directory, please. + // This file is used to make code coverage on this directly count. +} diff --git a/pkg/buses/stub/dispatcher/stub_test.go b/pkg/buses/stub/dispatcher/stub_test.go new file mode 100644 index 00000000000..ee7bbe8c445 --- /dev/null +++ b/pkg/buses/stub/dispatcher/stub_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import "testing" + +func TestStub(t *testing.T) { + // TODO: Implement tests in this directory, please. + // This file is used to make code coverage on this directly count. +} diff --git a/pkg/controller/testing/stub_test.go b/pkg/controller/testing/stub_test.go new file mode 100644 index 00000000000..f7133754ae5 --- /dev/null +++ b/pkg/controller/testing/stub_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package testing + +import "testing" + +func TestStub(t *testing.T) { + // TODO: Implement tests in this directory, please. + // This file is used to make code coverage on this directly count. +} diff --git a/pkg/logconfig/stub_test.go b/pkg/logconfig/stub_test.go new file mode 100644 index 00000000000..4cf27b6380d --- /dev/null +++ b/pkg/logconfig/stub_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package logconfig + +import "testing" + +func TestStub(t *testing.T) { + // TODO: Implement tests in this directory, please. + // This file is used to make code coverage on this directly count. +} diff --git a/pkg/system/stub_test.go b/pkg/system/stub_test.go new file mode 100644 index 00000000000..5588d53a093 --- /dev/null +++ b/pkg/system/stub_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package system + +import "testing" + +func TestStub(t *testing.T) { + // TODO: Implement tests in this directory, please. + // This file is used to make code coverage on this directly count. +} diff --git a/test/presubmit-tests.sh b/test/presubmit-tests.sh index a317f3487cb..020b775706f 100755 --- a/test/presubmit-tests.sh +++ b/test/presubmit-tests.sh @@ -31,6 +31,29 @@ CODE_PACKAGES_STR="${CODE_PACKAGES[*]}" CODE_PACKAGES_STR="./${CODE_PACKAGES_STR// /\/... .\/}/..." readonly CODE_PACKAGES_STR +# Check for subdirs which do not contain any test module but contain code. +# This is to prevent an issue where these directories are skipped in coverage +# reports resulting in inaccurately high coverage results. Fix by adding a +# stub_tests.go with no tests to these directories. +# This function namespaced with eventing to allow adding to test-infra without name collision +function check_eventing_subdirs_without_tests() { + ret=0 + for code_dir in "$1"; do + for dir in $(find $code_dir -type d); do + if echo "$dir" | grep -q "$2"; then + continue + fi + if ls -l $dir/*.go 1> /dev/null 2>&1; then + if ! ls -l $dir/*_test.go 1> /dev/null 2>&1; then + echo "Warning: no tests in directory: $dir" + ret=1 + fi + fi + done + done + return ${ret} +} + function build_tests() { header "Running build tests" local result=0 @@ -40,6 +63,8 @@ function build_tests() { # Check that we don't have any forbidden licenses in our images. subheader "Checking for forbidden licenses" check_licenses ./cmd/* || result=1 + subheader "Checking for subdirs with no tests" + check_eventing_subdirs_without_tests "${CODE_PACKAGES[*]}" "pkg/client" || result=1 return ${result} }