-
Notifications
You must be signed in to change notification settings - Fork 2.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
test: replace embedded Git repository with dynamically created repository #6824
Conversation
Signed-off-by: knqyf263 <knqyf263@gmail.com>
Signed-off-by: knqyf263 <knqyf263@gmail.com>
Signed-off-by: knqyf263 <knqyf263@gmail.com>
} | ||
|
||
func TestManager_Install(t *testing.T) { | ||
gs := setupGitRepository(t, "test_plugin", "testdata/test_plugin") | ||
t.Cleanup(gs.Close) | ||
|
||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
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.
I detected one problem with this test server:
this zip file doesn't contain nested dir:
- test_plugin.zip/plugin.yaml
But GitHub archive contains repo name dir
:
check https://github.com/aquasecurity/trivy-plugin-kubectl/archive/refs/heads/main.zip
- trivy-plugin-kubectl-main.zip/trivy-plugin-kubectl-main/plugin.yaml
I think we should handle this case, but perhaps in another PR.
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.
Good point. It's not introduced in this PR. I'll open another PR.
Signed-off-by: knqyf263 <knqyf263@gmail.com>
Signed-off-by: knqyf263 <knqyf263@gmail.com>
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.
LGTM
Description
Currently, Trivy includes a separate Git bare repository committed within its codebase for testing purposes. For example: https://github.com/aquasecurity/trivy/tree/29615be85e8bfeaf5a0cd51829b1898c55fa4274/pkg/plugin/testdata/test_plugin.git
While this approach allows us to focus on the logic of the code we want to test, it also has some drawbacks. In order to understand the state of this Git repository, we need to clone it and perform operations using
git
commands. Additionally, if we want to make small modifications, we need to use git commands, and it's not possible to review the changes made on GitHub since those changes are binary.To address these issues, this PR proposes using go-git to dynamically create the test Git repository during the testing process. Although there is a potential downside that if the process of creating this test repository is incorrect, the tests will fail to run properly, the benefits outweigh this risk, IMO. Using Go to create the repository makes it clearer what branches are being created, what tags are being assigned, and so on. This approach also makes it easier to make changes and conduct reviews on GitHub.
Checklist