Skip to content

Commit 0a3d076

Browse files
committed
test: use custom tmp directory
1 parent 9982d37 commit 0a3d076

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

__snapshots__/main_test.snap

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,39 +60,39 @@ You must provide at least one path to either a lockfile or a directory containin
6060

6161
[TestRun_APIError/#00 - 1]
6262
Loaded the following OSV databases:
63-
api#http://127.0.0.1:42805 (using batches of 1000)
63+
api#http://127.0.0.1:37453 (using batches of 1000)
6464
RubyGems (%% vulnerabilities, including withdrawn - last updated %%)
6565

66-
/tmp/TestRun_APIError#003124218549/001/Gemfile.lock: found 1 package
67-
Using config at /tmp/TestRun_APIError#003124218549/001/.osv-detector.yml (0 ignores)
68-
Using db api#http://127.0.0.1:42805 (using batches of 1000)
66+
<tempdir>/Gemfile.lock: found 1 package
67+
Using config at <tempdir>/.osv-detector.yml (0 ignores)
68+
Using db api#http://127.0.0.1:37453 (using batches of 1000)
6969
Using db RubyGems (%% vulnerabilities, including withdrawn - last updated %%)
7070

7171
no known vulnerabilities found
7272

7373
---
7474

7575
[TestRun_APIError/#00 - 2]
76-
an api error occurred while trying to check the packages listed in /tmp/TestRun_APIError#003124218549/001/Gemfile.lock: api returned unexpected status (POST http://127.0.0.1:42805/querybatch 400)
76+
an api error occurred while trying to check the packages listed in <tempdir>/Gemfile.lock: api returned unexpected status (POST http://127.0.0.1:37453/querybatch 400)
7777

7878
---
7979

8080
[TestRun_APIError/#01 - 1]
8181
Loaded the following OSV databases:
82-
api#http://127.0.0.1:36893 (using batches of 1000)
82+
api#http://127.0.0.1:38803 (using batches of 1000)
8383
RubyGems (%% vulnerabilities, including withdrawn - last updated %%)
8484

85-
/tmp/TestRun_APIError#01238228472/001/Gemfile.lock: found 1 package
86-
Using config at /tmp/TestRun_APIError#01238228472/001/.osv-detector.yml (0 ignores)
87-
Using db api#http://127.0.0.1:36893 (using batches of 1000)
85+
<tempdir>/Gemfile.lock: found 1 package
86+
Using config at <tempdir>/.osv-detector.yml (0 ignores)
87+
Using db api#http://127.0.0.1:38803 (using batches of 1000)
8888
Using db RubyGems (%% vulnerabilities, including withdrawn - last updated %%)
8989

9090
no known vulnerabilities found
9191

9292
---
9393

9494
[TestRun_APIError/#01 - 2]
95-
an api error occurred while trying to check the packages listed in /tmp/TestRun_APIError#01238228472/001/Gemfile.lock: api response could not be parsed as json (POST http://127.0.0.1:36893/querybatch): invalid character '<' looking for beginning of value
95+
an api error occurred while trying to check the packages listed in <tempdir>/Gemfile.lock: api response could not be parsed as json (POST http://127.0.0.1:38803/querybatch): invalid character '<' looking for beginning of value
9696

9797
---
9898

main_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -859,12 +859,19 @@ func TestRun_APIError(t *testing.T) {
859859
t.Run("", func(t *testing.T) {
860860
t.Parallel()
861861

862-
tmp := t.TempDir()
862+
//nolint:usetesting // we need to customize the directory name to replace in snapshots
863+
p, err := os.MkdirTemp("", "osv-detector-test-*")
864+
if err != nil {
865+
t.Fatalf("could not create test directory: %v", err)
866+
}
863867

864-
var err error
868+
// ensure the test directory is removed when we're done testing
869+
t.Cleanup(func() {
870+
_ = os.RemoveAll(p)
871+
})
865872

866873
// create a file for scanning
867-
err = os.WriteFile(filepath.Join(tmp, "Gemfile.lock"), []byte(`
874+
err = os.WriteFile(filepath.Join(p, "Gemfile.lock"), []byte(`
868875
GEM
869876
remote: https://rubygems.org/
870877
specs:
@@ -880,7 +887,7 @@ GEM
880887
t.Cleanup(ts.Close)
881888

882889
// create a config file setting up our api server
883-
err = os.WriteFile(filepath.Join(tmp, ".osv-detector.yml"), []byte(`
890+
err = os.WriteFile(filepath.Join(p, ".osv-detector.yml"), []byte(`
884891
extra-databases:
885892
- url: `+ts.URL,
886893
), 0600)
@@ -892,7 +899,7 @@ extra-databases:
892899
// run the cli in our tmp directory
893900
testCli(t, cliTestCase{
894901
name: "",
895-
args: []string{tmp},
902+
args: []string{p},
896903
exit: 127,
897904
})
898905
})

0 commit comments

Comments
 (0)