Skip to content

Commit

Permalink
test(vulnfeeds): make flaky tests skippable on Cloud Build (#3154)
Browse files Browse the repository at this point in the history
`cves.TestExtractGitCommit` and `cves.ValidateAndCanonicalizeLink` are
consistently failing on Cloud Build for git.kernel.org, which makes me
believe Cloud Build's egress IPs may have been blocked.

Rather than remove these tests entirely, this makes them skippable on
Cloud Build, and skips them, to unblock PRs that are currently
unmergeable due to these test failures.
  • Loading branch information
andrewpollock authored Feb 13, 2025
1 parent 8b6c210 commit 7c0077c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ steps:
id: 'vulnfeed-tests'
dir: vulnfeeds
args: ['bash', '-ex', 'run_tests.sh']
env:
- 'BUILD_ID=$BUILD_ID'
waitFor: ['init']

- name: 'gcr.io/oss-vdb/ci'
Expand Down
14 changes: 12 additions & 2 deletions vulnfeeds/cves/versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ func TestExtractGitCommit(t *testing.T) {
inputCommitType CommitType
expectedAffectedCommit AffectedCommit
expectFailure bool
skipOnCloudBuild bool
}{
{
description: "Valid GitHub commit URL",
Expand Down Expand Up @@ -590,6 +591,7 @@ func TestExtractGitCommit(t *testing.T) {
Repo: "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git",
Fixed: "ee1fee900537b5d9560e9f937402de5ddc8412f3",
},
skipOnCloudBuild: true, // observing indications of IP denylisting as at 2025-02-13
},
{
description: "Valid GitWeb commit URL",
Expand Down Expand Up @@ -628,6 +630,9 @@ func TestExtractGitCommit(t *testing.T) {
}

for _, tc := range tests {
if _, ok := os.LookupEnv("BUILD_ID"); ok && tc.skipOnCloudBuild {
t.Skipf("test %q: running on Cloud Build", tc.description)
}
got, err := extractGitCommit(tc.inputLink, tc.inputCommitType)
if err != nil && !tc.expectFailure {
t.Errorf("test %q: extractGitCommit for %q (%q) errored unexpectedly: %#v", tc.description, tc.inputLink, tc.inputCommitType, err)
Expand Down Expand Up @@ -1062,6 +1067,7 @@ func TestValidateAndCanonicalizeLink(t *testing.T) {
args args
wantCanonicalLink string
wantErr bool
skipOnCloudBuild bool
}{
{
name: "A link that 404's",
Expand All @@ -1078,10 +1084,14 @@ func TestValidateAndCanonicalizeLink(t *testing.T) {
},
wantCanonicalLink: "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ee1fee900537b5d9560e9f937402de5ddc8412f3",
wantErr: false,
skipOnCloudBuild: true, // observing indications of IP denylisting as at 2025-02-13
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if _, ok := os.LookupEnv("BUILD_ID"); ok && tt.skipOnCloudBuild {
t.Skipf("test %q: running on Cloud Build", tt.name)
}
gotCanonicalLink, err := ValidateAndCanonicalizeLink(tt.args.link)
if (err != nil) != tt.wantErr {
t.Errorf("ValidateAndCanonicalizeLink() error = %v, wantErr %v", err, tt.wantErr)
Expand Down Expand Up @@ -1109,7 +1119,7 @@ func TestCommit(t *testing.T) {
args: args{
u: "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ee1fee900537b5d9560e9f937402de5ddc8412f3",
},
want: "ee1fee900537b5d9560e9f937402de5ddc8412f3",
want: "ee1fee900537b5d9560e9f937402de5ddc8412f3",
wantErr: false,
},
}
Expand All @@ -1125,4 +1135,4 @@ func TestCommit(t *testing.T) {
}
})
}
}
}

0 comments on commit 7c0077c

Please sign in to comment.