Skip to content
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

Add analyzer acceptance tests #319

Merged
merged 7 commits into from
Jul 20, 2020
Merged

Add analyzer acceptance tests #319

merged 7 commits into from
Jul 20, 2020

Conversation

natalieparellano
Copy link
Member

Signed-off-by: Natalie Arellano narellano@vmware.com

Makefile Outdated Show resolved Hide resolved
@natalieparellano natalieparellano force-pushed the analyzer-acceptance branch 2 times, most recently from 2d2f155 to ffcaee8 Compare June 23, 2020 16:21
exporter_test.go Outdated Show resolved Hide resolved
output := h.Run(t, cmd)

h.AssertMatch(t, output, "2222 3333 .+ \\.")
h.AssertMatch(t, output, "2222 3333 .+ committed")
Copy link
Member Author

Choose a reason for hiding this comment

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

The staging directory is not chowned - is that expected?

Copy link
Member

Choose a reason for hiding this comment

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

It looks like the staging directory doesn't yet exist in the relevant cache fixture? If you are observing a staging dir with the wrong perms it is being created with the wrong perms which seems like an issue worth investigating.

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like it is being created with the wrong permissions:

        /cache:
        total 4
        drwxrwxr-x 4 2222 3333  128 Jun 26 19:59 .
        drwxr-xr-x 1 root root 4096 Jun 26 19:59 ..
        drwxrwxr-x 4 2222 3333  128 Aug 30  1754 committed
        drwxr-xr-x 2 root root   64 Jun 26 19:59 staging

What's interesting, when I add a staging directory to my fixture, it looks like that is ignored? At least, I don't see the foo.txt file that I inserted there. Will investigate...

Copy link
Member Author

Choose a reason for hiding this comment

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

Uggh I was probably doing something wrong - seeing different results now.

Copy link
Member Author

Choose a reason for hiding this comment

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

I still see that foo.txt is ignored, but staging has the correct permissions. I am not sure what changed other than the cache directory is now being provided as a volume vs. bind mount. What is interesting is that in the case where the user's group can write, I see that staging is chowned:

/cache:
total 16
drwxrwxr-x 4 9999 3333 4096 Jun 29 20:23 .
drwxr-xr-x 1 root root 4096 Jun 29 20:23 ..
drwxrwxr-x 2 9999 3333 4096 Jun 29 20:21 committed
drwxr-xr-x 2 2222 3333 4096 Jun 29 20:23 staging

Adding a note to investigate further. There is some weirdness here that I'm not understanding.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking at the code, if cacheDir != "" we always call cache.NewVolumeCache(cacheDir) which always recreates the staging directory (hence foo.txt was ignored). This happens after we drop privileges, so it makes sense that the uid & gid are 2222 & 3333. I have no idea why it was showing as owned by root before :/

Copy link
Member

Choose a reason for hiding this comment

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

Alright, let's keep an eye on it.

@natalieparellano natalieparellano force-pushed the analyzer-acceptance branch 3 times, most recently from 1342e05 to 3e2286f Compare June 23, 2020 19:11
@natalieparellano natalieparellano marked this pull request as ready for review June 23, 2020 19:28
@natalieparellano natalieparellano requested a review from a team as a code owner June 23, 2020 19:28
Copy link
Member

@ekcasey ekcasey left a comment

Choose a reason for hiding this comment

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

Overall this looks awesome!

At first I was going to suggest asserting on file contents but given that we do this extensively in the unit tests I think assert on file existence was the right call. It keeps these tests simple and should catch high level workflow errors w/o becoming unmaintainable.

Makefile Outdated Show resolved Hide resolved
acceptance/launcher_test.go Outdated Show resolved Hide resolved
acceptance/analyzer_test.go Show resolved Hide resolved
acceptance/analyzer_test.go Show resolved Hide resolved
acceptance/analyzer_test.go Show resolved Hide resolved
acceptance/analyzer_test.go Outdated Show resolved Hide resolved
acceptance/analyzer_test.go Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
acceptance/analyzer_test.go Outdated Show resolved Hide resolved
acceptance/launcher_test.go Outdated Show resolved Hide resolved
Copy link
Member

@dfreilich dfreilich left a comment

Choose a reason for hiding this comment

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

In general, looks really cool! As @jromero mentioned, the use of explicit bash commands made it a bit hard for me as a relative lifecycle outsider to understand what was happening, so it may benefit by having a clearer wrapper func to make things more explicit.

Great job adding it!

testhelpers/docker.go Show resolved Hide resolved
acceptance/analyzer_test.go Outdated Show resolved Hide resolved
acceptance/analyzer_test.go Show resolved Hide resolved
@ekcasey ekcasey linked an issue Jun 24, 2020 that may be closed by this pull request
7 tasks
testhelpers/docker.go Outdated Show resolved Hide resolved
@natalieparellano natalieparellano force-pushed the analyzer-acceptance branch 21 times, most recently from 8a64127 to 76b46e3 Compare July 16, 2020 19:56
- Reorganize test helpers
- Add small cross platform helpers (like variables)

Signed-off-by: Natalie Arellano <narellano@vmware.com>
@natalieparellano
Copy link
Member Author

@ekcasey I think this is ready for another round of review.

Copy link
Member

@ekcasey ekcasey left a comment

Choose a reason for hiding this comment

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

I am super pleased, this looks great!

I left a couple comments and questions but the only change I think is important to make before merging is the -cache-image+-daemon case. I am under the impression that combo should work. If for some reason it doesn't work, leave a test that asserts that it should work skipped or commented out and file a bug.

testhelpers/binaries.go Outdated Show resolved Hide resolved
testhelpers/binaries.go Outdated Show resolved Hide resolved
"testing"
)

func MakeAndCopyLauncher(t *testing.T, destDir string) {
Copy link
Member

Choose a reason for hiding this comment

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

Should this take goos as an arg like MakeAndCopyLifecycle does?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changing it to be consistent. FWIW the reason this didn't take a goos is because in practice when we're testing the launcher it's always either Linux or Windows, so runtime.GOOS + some logic to convert darwin -> linux is sufficient. For the lifecycle, because we test the version on darwin the function needed more flexibility. What I have now is explicitly passing daemon OS as the goos for the launcher.

testhelpers/binaries.go Outdated Show resolved Hide resolved
Comment on lines +26 to +39
func DockerCli(t *testing.T) dockercli.CommonAPIClient {
dockerCliOnce.Do(func() {
var dockerCliErr error
dockerCliVal, dockerCliErr = dockercli.NewClientWithOpts(dockercli.FromEnv, dockercli.WithVersion("1.38"))
AssertNil(t, dockerCliErr)
})
return dockerCliVal
}

func DockerBuild(t *testing.T, name, context string, ops ...DockerCmdOp) {
t.Helper()
args := formatArgs([]string{"-t", name, context}, ops...)
Run(t, exec.Command("docker", append([]string{"build"}, args...)...))
}
Copy link
Member

Choose a reason for hiding this comment

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

I am fine leaving this as is for now (I think I introduce this inconsistency in the launcher acceptance tests), but in the future we should decide whether we want to exec the docker cli or use the client library and be consistent about it (I lean towards the latter).

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree! I added a TODO for it in the code. Hopefully it will become consistent over time.

analyzeImage,
"/layers",
h.WithFlags(
"--env", "CNB_REGISTRY_AUTH={}",
Copy link
Member

Choose a reason for hiding this comment

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

Why do we bother to pass the empty CNB_REGISTRY_AUTH in places where we don't use it?

Copy link
Member

Choose a reason for hiding this comment

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

nvmd, comment on line 280 was illuminating. We should fix whatever causes that failure in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

Opened an issue: #339

acceptance/analyzer_test.go Outdated Show resolved Hide resolved
output := h.Run(t, cmd)

h.AssertMatch(t, output, "2222 3333 .+ \\.")
h.AssertMatch(t, output, "2222 3333 .+ committed")
Copy link
Member

Choose a reason for hiding this comment

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

Alright, let's keep an eye on it.

})
})

when("the provided cache directory is writeable by the CNB user's group", func() {
Copy link
Member

Choose a reason for hiding this comment

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

Having some test coverage for this logic makes me very happy :)

acceptance/analyzer_test.go Outdated Show resolved Hide resolved
Signed-off-by: Natalie Arellano <narellano@vmware.com>
@ekcasey ekcasey merged commit 63c5c6e into main Jul 20, 2020
@ekcasey ekcasey deleted the analyzer-acceptance branch July 20, 2020 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add acceptance tests
5 participants