Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ go-apidiff:
##@ Tests

.PHONY: test
test: test-unit test-integration test-testdata test-book ## Run the unit and integration tests (used in the CI)
test: test-unit test-integration test-testdata test-book test-license ## Run the unit and integration tests (used in the CI)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have a GA /ci job new only for this one to make it easier for us to know when/if fails?
I mean, i new target + GitHub actions?

Copy link
Contributor Author

@sanya301 sanya301 Jan 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So do you want a Github actions in addition to the script? I thought we wanted one or the other, otherwise it would be repetitive. It didn't seem like a lot of people were using the github action so I decided to go with the script

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggestion would be to call this one only in a GA that does this check.
Not call the test twice at all. That would mean not adding test-license in this target also.

The reason would be to make it easier for contributors to check why/what is falling in the ci.
However, that is just nit. It is passing on the tests now so I am ok with too.


.PHONY: test-unit
TEST_PKGS := ./pkg/... ./test/e2e/utils/...
Expand Down Expand Up @@ -134,3 +134,7 @@ test-e2e-ci: ## Run the end-to-end tests (used in the CI)`
.PHONY: test-book
test-book: ## Run the cronjob tutorial's unit tests to make sure we don't break it
cd ./docs/book/src/cronjob-tutorial/testdata/project && make test

.PHONY: test-license
test-license: ## Run the license check
./test/check-license.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*
Ideally, we should have one `<kind>_controller_test.go` for each controller scaffolded and called in the `suite_test.go`.
So, let's write our example test for the CronJob controller (`cronjob_controller_test.go.`)
*/

/*

Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -19,6 +14,11 @@ limitations under the License.
*/
// +kubebuilder:docs-gen:collapse=Apache License

/*
Ideally, we should have one `<kind>_controller_test.go` for each controller scaffolded and called in the `suite_test.go`.
So, let's write our example test for the CronJob controller (`cronjob_controller_test.go.`)
*/

/*
As usual, we start with the necessary imports. We also define some utility variables.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/*
When we created the CronJob API with `kubebuilder create api` in a [previous chapter](/cronjob-tutorial/new-api.md), Kubebuilder already did some test work for you.
Kubebuilder scaffolded a `controllers/suite_test.go` file that does the bare bones of setting up a test environment.

First, it will contain the necessary imports.
*/

/*
Copyright 2022 The Kubernetes authors.

Expand All @@ -21,6 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// +kubebuilder:docs-gen:collapse=Apache License

/*
When we created the CronJob API with `kubebuilder create api` in a [previous chapter](/cronjob-tutorial/new-api.md), Kubebuilder already did some test work for you.
Kubebuilder scaffolded a `controllers/suite_test.go` file that does the bare bones of setting up a test environment.

First, it will contain the necessary imports.
*/

package controllers

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright 2022 The Kubernetes 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 api

import (
Expand Down
34 changes: 34 additions & 0 deletions test/check-license.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Copyright 2021 The Kubernetes 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.

set -o errexit
set -o nounset
set -o pipefail

source $(dirname "$0")/common.sh

echo "Checking for license header..."
allfiles=$(listFiles|grep -v ./internal/bindata/...)
licRes=""
for file in $allfiles; do
if ! head -n4 "${file}" | grep -Eq "(Copyright|generated|GENERATED|Licensed)" ; then
licRes="${licRes}\n"$(echo -e " ${file}")
fi
done
if [ -n "${licRes}" ]; then
echo -e "license header checking failed:\n${licRes}"
exit 255
fi
10 changes: 10 additions & 0 deletions test/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,13 @@ function is_installed {
fi
return 1
}

function listPkgDirs() {
go list -f '{{.Dir}}' ./... | grep -v generated
}

#Lists all go files
function listFiles() {
# pipeline is much faster than for loop
listPkgDirs | xargs -I {} find {} \( -name '*.go' -o -name '*.sh' \) | grep -v generated
}