project-copacetic / copacetic

🧵 CLI tool for directly patching container images!
https://project-copacetic.github.io/copacetic/
Apache License 2.0
906 stars 60 forks source link

[QUESTION] How to run the tests ? #712

Closed 0xDagal closed 1 month ago

0xDagal commented 1 month ago

What is your question?

I tried to run the test with a make test but ran into this issue:

copacetic main*
❯ make test
=> Running unit tests on pkg libraries ...
go test ./pkg/... 
?       github.com/project-copacetic/copacetic/pkg/types    [no test files]
?       github.com/project-copacetic/copacetic/pkg/types/unversioned    [no test files]
?       github.com/project-copacetic/copacetic/pkg/types/v1alpha1   [no test files]
--- FAIL: TestNewClient (0.15s)
    --- FAIL: TestNewClient/custom_buildkit_addr (0.15s)
        --- FAIL: TestNewClient/custom_buildkit_addr/default_buildkit_addr (0.15s)
            buildkit_test.go:232: 
                    Error Trace:    /home/user/Projects/copacetic/pkg/buildkit/buildkit_test.go:232
                    Error:          Received unexpected error:
                                    could not use docker driver: failed to solve: requested experimental feature mergeop  has been disabled on the build server: only enabled with containerd image store backend
                                    requested experimental feature diffop  has been disabled on the build server: only enabled with containerd image store backend
                                    missing required buildkit functionality
                                    could not use buildx driver: listing workers for Build: failed to list workers: Unavailable: connection error: desc = "transport: Error while dialing: read /home/user/.docker/buildx/instances: is a directory"
                                    could not use buildkitd driver: %!w(<nil>)
                    Test:           TestNewClient/custom_buildkit_addr/default_buildkit_addr
panic: runtime error: invalid memory address or nil pointer dereference
    panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xc2e37b]

goroutine 15 [running]:
testing.tRunner.func1.2({0xcf2520, 0x15630c0})
    /home/user/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.1.linux-amd64/src/testing/testing.go:1631 +0x24a
testing.tRunner.func1()
    /home/user/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.1.linux-amd64/src/testing/testing.go:1634 +0x377
panic({0xcf2520?, 0x15630c0?})
    /home/user/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.1.linux-amd64/src/runtime/panic.go:770 +0x132
github.com/moby/buildkit/client.(*Client).Close(...)
    /home/user/go/pkg/mod/github.com/moby/buildkit@v0.15.0/client/client.go:219
panic({0xcf2520?, 0x15630c0?})
    /home/user/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.1.linux-amd64/src/runtime/panic.go:770 +0x132
github.com/moby/buildkit/client.(*Client).ControlClient(...)
    /home/user/go/pkg/mod/github.com/moby/buildkit@v0.15.0/client/client.go:181
github.com/moby/buildkit/client.(*Client).ListWorkers(0x0, {0xf5cad0, 0x15ee9e0}, {0x0, 0x0, 0x53b70a?})
    /home/user/go/pkg/mod/github.com/moby/buildkit@v0.15.0/client/workers.go:31 +0x104
github.com/moby/buildkit/client.(*Client).Build(0x0, {_, _}, {{0x0, 0x0, 0x0}, 0x0, 0x0, 0x0, {0x0, ...}, ...}, ...)
    /home/user/go/pkg/mod/github.com/moby/buildkit@v0.15.0/client/build.go:32 +0x14f
github.com/project-copacetic/copacetic/pkg/buildkit.ValidateClient({0xf5cad0?, 0x15ee9e0?}, 0xf51da0?)
    /home/user/Projects/copacetic/pkg/buildkit/drivers.go:65 +0x75
github.com/project-copacetic/copacetic/pkg/buildkit.TestNewClient.func1.4(0xc0003589c0)
    /home/user/Projects/copacetic/pkg/buildkit/buildkit_test.go:234 +0xba
testing.tRunner(0xc0003589c0, 0xe740e8)
    /home/user/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.1.linux-amd64/src/testing/testing.go:1689 +0xfb
created by testing.(*T).Run in goroutine 11
    /home/user/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.1.linux-amd64/src/testing/testing.go:1742 +0x390
FAIL    github.com/project-copacetic/copacetic/pkg/buildkit 0.161s
ok      github.com/project-copacetic/copacetic/pkg/buildkit/connhelpers (cached)
ok      github.com/project-copacetic/copacetic/pkg/patch    (cached)
ok      github.com/project-copacetic/copacetic/pkg/pkgmgr   (cached)
ok      github.com/project-copacetic/copacetic/pkg/report   (cached)
ok      github.com/project-copacetic/copacetic/pkg/test_utils   (cached)
ok      github.com/project-copacetic/copacetic/pkg/utils    (cached)
ok      github.com/project-copacetic/copacetic/pkg/vex  (cached)
FAIL

make: *** [Makefile:106 : test] Erreur 1

Should we have to run a buildkitd daemon or something before running the tests ? Or is it an issue with the test and this should be mocked ? I see that the issue is that we try to create a new client with empty bkOpts so it goes to autoClient which tries to connect to something, fails to do so, returns an error and then there is an assert.NoError

ashnamehrotra commented 1 month ago

@0xDagal if using default connection, you need to have containerd image store enabled for copa to work. You can check for ways to connect to buildkit in the copa documentation https://project-copacetic.github.io/copacetic/website/custom-address. When testing this, there seems to be a different error that comes up only on mac and not linux machines. I created an issue to track #713

0xDagal commented 1 month ago

Ok, I read the GitHub build workflow and added "features": { "containerd-snapshotter": true } to my /etc/docker/daemon.json it now works, thanks.