-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Local integration tests #256
Local integration tests #256
Conversation
kokoro is going to love this, I can just feel it |
wut |
ab753a6
to
a7dc7b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really great, thanks for fixing all of this!
DEVELOPMENT.md
Outdated
|
||
#### Troubleshooting | ||
|
||
If you see errors due to `container-diff` failing, try pulling the base images (specified in [the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realized we could also get rid of this problem by using fully qualified images for all the Dockerfiles, so once this goes through hopefully we won't need this section!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooooo nice! and it's in, so I'll remove this from the doc
DEVELOPMENT.md
Outdated
```shell | ||
export GCS_BUCKET="gs://<your bucket>" | ||
export IMAGE_REPO="gcr.io/somerepo" | ||
go test -v --bucket $GCS_BUCKET --repo $IMAGE_REPO -run TestLayers/test_layer_Dockerfile_test_copy_bucket |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have the flags here anyway, it might be easier to just pass in the names instead of having env variables as an extra step?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kk sounds good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay so I'm going to do something halfway to what you are suggesting, just removing the export lines so it looks like this:
go test -v --bucket $GCS_BUCKET --repo $IMAGE_REPO -run TestLayers/test_layer_Dockerfile_test_copy_bucket`
One alternative would be to hardcode some defaults, but i think this makes it hard for ppl to know what they need to change:
go test -v --bucket gs://kaniko-test-bucket --repo gcr.io/kaniko-test -run TestLayers/test_layer_Dockerfile_test_copy_bucket`
Or we could do something like this, which is what I used to do all the time, but the thing is you can't copy and paste it:
go test -v --bucket <your bucket> --repo <your repo> -run TestLayers/test_layer_Dockerfile_test_copy_bucket`
I like leaving the env vars in b/c then if ppl use env vars they can copy & paste the command from the doc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure, SGTM!
integration/gcs.go
Outdated
if err != nil { | ||
return "", fmt.Errorf("Failed to create temporary directoy to hold tarball: %s", err) | ||
} | ||
uuid := randomString(32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be simpler to use a timestamp here, since the context will be deleted anyway!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh good call!
integration/integration_test.go
Outdated
t.Error(err) | ||
t.Fail() | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func checkLayers(image1, image2 string, offset int) error { | ||
func checkLayers(t *testing.T, image1, image2 string, offset int) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to pass t in here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh thanks for catching that @sharifelgamal I'll remove it - I had tried out calling t.Helper()
in this function to change the line number reported for failures, but I ended up thinking it's better reporting the line number inside checkLayers
a7dc7b3
to
a7a357b
Compare
a7a357b
to
395d012
Compare
395d012
to
0c119fb
Compare
LGTM, I think you just need to rebase & this should be ready to merge! |
0c119fb
to
eb91562
Compare
HERE WE GO that flake better not happen, that would be ironic <.< |
integration/images.go:68:1:warning: singleSnapshotImages is unused (deadcode)
integration/images.go:29:1:warning: singleSnapshotFlag is unused (deadcode) No flake, but a lint error! |
To allow contributors to run the integration tests with their own GCS buckets and image repos (since not all contributors will have accesss to the projects used by the kaniko maintainers) this updates the integration tests so that these can be provided on the command line. This allows tests to be run individually, without using `make integration-test`. Previously, part of the test setup was done in the shell script (creating the context tarball that is required for the tests that build images with context). Instead it will be done in the test iself, so we can use `go test` to run tests individually if we want to. If we are running only one individual test, we don't want to build all of the images, so this commit creates a builder which tracks which images it has built and can be used by a tests to check if it should build an image before running, or it will use the images that have already been built by a previous test. The name of the context tarball has also been made unique (it includes the unix timestamp) to avoid potential test flakes if two tests using the same GCS bucket run simultaneously.
eb91562
to
b5a4d76
Compare
7th time's a charm! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome.
When starting to look into #251 I wanted to try to reproduce the test flakes locally but I immediately ran into two problems:
integration_tests.sh
to work, b/c it contains important setup, and this makes it a bit tough to run tests individually(1) Can be resolved by adding me to these projects, but it turns out the tests can work just fine using a different project and bucket, so I've updated the tests such that these values can be provided as arguments to the tests.
(2) Now the setup (i.e. the creation of the build context) is done as part of the tests themselves, so we can run the tests directly with
go test
.Bonuses:
TestRun
being run beforeTestLayers
becauseTestRun
would actually build the images with docker and kaniko - this means running tests fromTestLayers
individually did not work. Now the tests will check if the images have been built before trying to use them, build them if they haven't been built, or use the previously built images if they have been.