From 00d0a34583b01b44548f70cdc84348c137921ed5 Mon Sep 17 00:00:00 2001 From: Halvard Skogsrud Date: Tue, 26 Oct 2021 18:27:51 +1100 Subject: [PATCH] Add integration test config to repo Add files to repo instead of dynamically generate during the integration test. Also document default values of `dir` and `main`. --- README.md | 4 ++-- integration_test.sh | 29 ++--------------------------- test/build-configs/.ko.yaml | 21 +++++++++++++++++++++ test/build-configs/bar/cmd/main.go | 21 +++++++++++++++++++++ test/build-configs/bar/go.mod | 17 +++++++++++++++++ test/build-configs/foo/cmd/main.go | 21 +++++++++++++++++++++ test/build-configs/foo/go.mod | 17 +++++++++++++++++ 7 files changed, 101 insertions(+), 29 deletions(-) create mode 100644 test/build-configs/.ko.yaml create mode 100644 test/build-configs/bar/cmd/main.go create mode 100644 test/build-configs/bar/go.mod create mode 100644 test/build-configs/foo/cmd/main.go create mode 100644 test/build-configs/foo/go.mod diff --git a/README.md b/README.md index ccd4a00b41..515ce17d1a 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ configuration section in your `.ko.yaml`. ```yaml builds: - id: foo - dir: . + dir: . # default is . main: ./foobar/foo env: - GOPRIVATE=git.internal.example.com,source.developers.google.com @@ -148,7 +148,7 @@ builds: - -X main.version={{.Env.VERSION}} - id: bar dir: ./bar - main: . + main: . # default is . env: - GOCACHE=/workspace/.gocache ldflags: diff --git a/integration_test.sh b/integration_test.sh index c51747f185..46b4c15611 100755 --- a/integration_test.sh +++ b/integration_test.sh @@ -95,37 +95,12 @@ GO111MODULE=on ./ko/ko build --local github.com/go-training/helloworld && exit 1 popd || exit 1 echo "8. On outside with build config specifying the test module builds." -ko_exec_dir=$(pwd) -pushd "$(mktemp -d)" || exit 1 -for app in foo bar ; do - mkdir -p $app/cmd || exit 1 - pushd $app || exit 1 - GO111MODULE=on go mod init example.com/$app || exit 1 - cat << EOF > ./cmd/main.go || exit 1 -package main - -import "fmt" - -func main() { - fmt.Println("$app") -} -EOF - popd || exit 1 -done -cat << EOF > .ko.yaml || exit 1 -builds: -- id: foo-app - dir: ./foo - main: ./cmd -- id: bar-app - dir: ./bar - main: ./cmd -EOF +pushd test/build-configs || exit 1 for app in foo bar ; do # test both local and fully qualified import paths for prefix in example.com . ; do import_path=$prefix/$app/cmd - RESULT="$(GO111MODULE=on GOFLAGS="" "$ko_exec_dir"/ko publish --local $import_path | grep "$FILTER" | xargs -I% docker run %)" + RESULT="$(GO111MODULE=on GOFLAGS="" ../../ko build --local $import_path | grep "$FILTER" | xargs -I% docker run %)" if [[ "$RESULT" != *"$app"* ]]; then echo "Test FAILED for $import_path. Saw $RESULT but expected $app" && exit 1 else diff --git a/test/build-configs/.ko.yaml b/test/build-configs/.ko.yaml new file mode 100644 index 0000000000..c92d94308b --- /dev/null +++ b/test/build-configs/.ko.yaml @@ -0,0 +1,21 @@ +# Copyright 2021 Google LLC All Rights Reserved. +# +# 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. + +builds: +- id: foo-app + dir: ./foo + main: ./cmd +- id: bar-app + dir: ./bar + main: ./cmd diff --git a/test/build-configs/bar/cmd/main.go b/test/build-configs/bar/cmd/main.go new file mode 100644 index 0000000000..bde5a7f432 --- /dev/null +++ b/test/build-configs/bar/cmd/main.go @@ -0,0 +1,21 @@ +// Copyright 2021 Google LLC All Rights Reserved. +// +// 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 "fmt" + +func main() { + fmt.Println("bar") +} diff --git a/test/build-configs/bar/go.mod b/test/build-configs/bar/go.mod new file mode 100644 index 0000000000..fac14d9e39 --- /dev/null +++ b/test/build-configs/bar/go.mod @@ -0,0 +1,17 @@ +// Copyright 2021 Google LLC All Rights Reserved. +// +// 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. + +module example.com/bar + +go 1.16 diff --git a/test/build-configs/foo/cmd/main.go b/test/build-configs/foo/cmd/main.go new file mode 100644 index 0000000000..18cc492353 --- /dev/null +++ b/test/build-configs/foo/cmd/main.go @@ -0,0 +1,21 @@ +// Copyright 2021 Google LLC All Rights Reserved. +// +// 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 "fmt" + +func main() { + fmt.Println("foo") +} diff --git a/test/build-configs/foo/go.mod b/test/build-configs/foo/go.mod new file mode 100644 index 0000000000..9a4b1cec8e --- /dev/null +++ b/test/build-configs/foo/go.mod @@ -0,0 +1,17 @@ +// Copyright 2021 Google LLC All Rights Reserved. +// +// 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. + +module example.com/foo + +go 1.16