mirror of
https://github.com/ko-build/ko.git
synced 2025-02-01 19:14:40 +02:00
Add integration tests for various go mod corner cases. (#179)
* Add manual integration tests for various go mod corner cases. * Move integration test back and actually test the outputs. I realize now this is run in a travis CI job :) So I'll make it actually work. * Add _, gofmt * Add tools build constraint. * Stop redirecting stderr * Use local mode to support CI.
This commit is contained in:
parent
ab4ca8ec17
commit
6e4a93eee0
1
go.mod
1
go.mod
@ -7,6 +7,7 @@ require (
|
||||
github.com/docker/docker v1.4.2-0.20190924003213-a8608b5b67c7
|
||||
github.com/dprotaso/go-yit v0.0.0-20191028211022-135eb7262960
|
||||
github.com/fsnotify/fsnotify v1.4.7
|
||||
github.com/go-training/helloworld v0.0.0-20200225145412-ba5f4379d78b
|
||||
github.com/google/go-cmp v0.3.0
|
||||
github.com/google/go-containerregistry v0.0.0-20200310013544-4fe717a9b4cb
|
||||
github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc // indirect
|
||||
|
2
go.sum
2
go.sum
@ -114,6 +114,8 @@ github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh
|
||||
github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY=
|
||||
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/go-training/helloworld v0.0.0-20200225145412-ba5f4379d78b h1:0pOrjn0UzTcHdhDVdxrH8LwM7QLnAp8qiUtwXM04JEE=
|
||||
github.com/go-training/helloworld v0.0.0-20200225145412-ba5f4379d78b/go.mod h1:hGGmX3bRUkYkc9aKA6mkUxi6d+f1GmZF1je0FlVTgwU=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
||||
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d h1:3PaI8p3seN09VjbTYC/QWlUZdZ1qS1zGjy7LH2Wt07I=
|
||||
|
7
hack/tools.go
Normal file
7
hack/tools.go
Normal file
@ -0,0 +1,7 @@
|
||||
// +build tools
|
||||
|
||||
package hack
|
||||
|
||||
import (
|
||||
_ "github.com/go-training/helloworld"
|
||||
)
|
103
integration_test.sh
Normal file → Executable file
103
integration_test.sh
Normal file → Executable file
@ -1,2 +1,103 @@
|
||||
#!/bin/bash
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
ROOT_DIR=$(dirname $0)
|
||||
|
||||
pushd "$ROOT_DIR"
|
||||
|
||||
ROOT_DIR="$(pwd)"
|
||||
|
||||
echo "Running smoke test."
|
||||
go install ./cmd/ko
|
||||
ko apply -f ./cmd/ko/test -L
|
||||
ko apply -f ./cmd/ko/test -L
|
||||
|
||||
echo "Moving GOPATH into /tmp/ to test modules behavior."
|
||||
export ORIGINAL_GOPATH="$GOPATH"
|
||||
export GOPATH="$(mktemp -d)"
|
||||
|
||||
pushd "$GOPATH" || exit 1
|
||||
|
||||
echo "Copying ko to temp gopath."
|
||||
mkdir -p "$GOPATH/src/github.com/google/ko"
|
||||
cp -r "$ROOT_DIR/"* "$GOPATH/src/github.com/google/ko/"
|
||||
|
||||
echo "Downloading github.com/go-training/helloworld"
|
||||
go get -d github.com/go-training/helloworld
|
||||
|
||||
pushd "$GOPATH/src/github.com/google/ko" || exit 1
|
||||
|
||||
echo "Replacing hello world in vendor with TEST."
|
||||
sed -i 's/Hello World/TEST/g' ./vendor/github.com/go-training/helloworld/main.go
|
||||
|
||||
echo "Building ko"
|
||||
|
||||
RESULT="$(GO111MODULE="on" GOFLAGS="-mod=vendor" go build ./cmd/ko)"
|
||||
|
||||
echo "Beginning scenarios."
|
||||
|
||||
FILTER="[^ ]local[^ ]*"
|
||||
|
||||
echo "1. GOPATH mode should always create an image that outputs 'Hello World'"
|
||||
RESULT="$(GO111MODULE=off ./ko publish --local github.com/go-training/helloworld | grep "$FILTER" | xargs -I% docker run %)"
|
||||
if [[ "$RESULT" != *"Hello World"** ]]; then
|
||||
echo "Test FAILED. Saw $RESULT" && exit 1
|
||||
else
|
||||
echo "Test PASSED"
|
||||
fi
|
||||
|
||||
echo "2. Go module auto mode should create an image that outputs 'Hello World' when run outside the module."
|
||||
|
||||
pushd .. || exit 1
|
||||
RESULT="$(GO111MODULE=auto GOFLAGS="-mod=vendor" ./ko/ko publish --local github.com/go-training/helloworld | grep "$FILTER" | xargs -I% docker run %)"
|
||||
if [[ "$RESULT" != *"Hello World"* ]]; then
|
||||
echo "Test FAILED. Saw $RESULT" && exit 1
|
||||
else
|
||||
echo "Test PASSED"
|
||||
fi
|
||||
|
||||
popd || exit 1
|
||||
|
||||
echo "3. Auto inside the module with vendoring should output TEST"
|
||||
|
||||
RESULT="$(GO111MODULE=auto GOFLAGS="-mod=vendor" ./ko publish --local github.com/go-training/helloworld | grep "$FILTER" | xargs -I% docker run %)"
|
||||
if [[ "$RESULT" != *"TEST"* ]]; then
|
||||
echo "Test FAILED. Saw $RESULT" && exit 1
|
||||
else
|
||||
echo "Test PASSED"
|
||||
fi
|
||||
|
||||
echo "4. Auto inside the module without vendoring should output Hello World"
|
||||
RESULT="$(GO111MODULE=auto GOFLAGS="" ./ko publish --local github.com/go-training/helloworld | grep "$FILTER" | xargs -I% docker run %)"
|
||||
if [[ "$RESULT" != *"Hello World"* ]]; then
|
||||
echo "Test FAILED. Saw $RESULT" && exit 1
|
||||
else
|
||||
echo "Test PASSED"
|
||||
fi
|
||||
|
||||
echo "5. On inside the module with vendor should output TEST."
|
||||
RESULT="$(GO111MODULE=on GOFLAGS="-mod=vendor" ./ko publish --local github.com/go-training/helloworld | grep "$FILTER" | xargs -I% docker run %)"
|
||||
if [[ "$RESULT" != *"TEST"* ]]; then
|
||||
echo "Test FAILED. Saw $RESULT" && exit 1
|
||||
else
|
||||
echo "Test PASSED"
|
||||
fi
|
||||
|
||||
echo "6. On inside the module without vendor should output Hello World"
|
||||
RESULT="$(GO111MODULE=on GOFLAGS="" ./ko publish --local github.com/go-training/helloworld | grep "$FILTER" | xargs -I% docker run %)"
|
||||
if [[ "$RESULT" != *"Hello World"* ]]; then
|
||||
echo "Test FAILED. Saw $RESULT" && exit 1
|
||||
else
|
||||
echo "Test PASSED"
|
||||
fi
|
||||
|
||||
echo "7. On outside the module should fail."
|
||||
pushd .. || exit 1
|
||||
GO111MODULE=on ./ko/ko publish --local github.com/go-training/helloworld && exit 1
|
||||
|
||||
popd || exit 1
|
||||
popd || exit 1
|
||||
popd || exit 1
|
||||
|
||||
export GOPATH="$ORIGINAL_GOPATH"
|
||||
|
16
vendor/github.com/go-training/helloworld/.drone.yml
generated
vendored
Normal file
16
vendor/github.com/go-training/helloworld/.drone.yml
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
---
|
||||
kind: pipeline
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: backend
|
||||
image: golang:1.13-alpine
|
||||
environment:
|
||||
USERNAME:
|
||||
from_secret: username
|
||||
commands:
|
||||
- go build
|
||||
- go test
|
||||
- echo $USERNAME
|
||||
- echo $USERNAME > a.txt
|
||||
- cat a.txt
|
14
vendor/github.com/go-training/helloworld/.gitignore
generated
vendored
Normal file
14
vendor/github.com/go-training/helloworld/.gitignore
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, build with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
|
||||
.glide/
|
21
vendor/github.com/go-training/helloworld/LICENSE
generated
vendored
Normal file
21
vendor/github.com/go-training/helloworld/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 golang workshop
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
31
vendor/github.com/go-training/helloworld/README.md
generated
vendored
Normal file
31
vendor/github.com/go-training/helloworld/README.md
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
# helloworld
|
||||
|
||||
[![Build Status](https://cloud.drone.io/api/badges/go-training/helloworld/status.svg)](https://cloud.drone.io/go-training/helloworld)
|
||||
|
||||
Hello World for Golang
|
||||
|
||||
## Simple Command
|
||||
|
||||
Run golang program
|
||||
|
||||
```bash
|
||||
go run main.go
|
||||
```
|
||||
|
||||
Testing
|
||||
|
||||
```bash
|
||||
go test
|
||||
```
|
||||
|
||||
Build binary
|
||||
|
||||
```bash
|
||||
go build
|
||||
```
|
||||
|
||||
Install binary
|
||||
|
||||
```bash
|
||||
go install
|
||||
```
|
11
vendor/github.com/go-training/helloworld/main.go
generated
vendored
Normal file
11
vendor/github.com/go-training/helloworld/main.go
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func helloworld() string {
|
||||
return "Hello World!!"
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println(helloworld())
|
||||
}
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -66,6 +66,8 @@ github.com/go-openapi/jsonreference
|
||||
github.com/go-openapi/spec
|
||||
# github.com/go-openapi/swag v0.19.5
|
||||
github.com/go-openapi/swag
|
||||
# github.com/go-training/helloworld v0.0.0-20200225145412-ba5f4379d78b
|
||||
github.com/go-training/helloworld
|
||||
# github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d
|
||||
github.com/gogo/protobuf/proto
|
||||
github.com/gogo/protobuf/sortkeys
|
||||
|
Loading…
x
Reference in New Issue
Block a user