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

test: use T.TempDir to create temporary test directory #1686

Merged
merged 1 commit into from
Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions module/modmanager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package modmanager

import (
"context"
"os"
"testing"

"github.com/edaniels/golog"
Expand Down Expand Up @@ -38,9 +37,7 @@ func TestModManagerFunctions(t *testing.T) {
return logger
}

parentAddr, err := os.MkdirTemp("", "viam-test-*")
test.That(t, err, test.ShouldBeNil)
defer os.RemoveAll(parentAddr)
parentAddr := t.TempDir()
parentAddr += "/parent.sock"

myRobot.ModuleAddressFunc = func() (string, error) {
Expand Down
5 changes: 1 addition & 4 deletions vision/keypoints/briefdesc_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keypoints

import (
"os"
"testing"

"github.com/edaniels/golog"
Expand All @@ -14,9 +13,7 @@ func TestGenerateSamplePairs(t *testing.T) {
patchSize := 250
descSize := 128
offset := (patchSize / 2) - 1
tempDir, err := os.MkdirTemp("", "brief_sampling")
test.That(t, err, test.ShouldBeNil)
defer os.RemoveAll(tempDir)
tempDir := t.TempDir()
logger.Infof("writing sample points to %s", tempDir)
// create plotter
plotTmpImage := func(fileName string, sp *SamplePairs) {
Expand Down
4 changes: 1 addition & 3 deletions vision/keypoints/matching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"image"
"image/draw"
"math"
"os"
"testing"

"github.com/edaniels/golog"
Expand Down Expand Up @@ -42,8 +41,7 @@ func TestRangeInt(t *testing.T) {

func TestMatchDescriptors(t *testing.T) {
logger := golog.NewTestLogger(t)
tempDir, err := os.MkdirTemp("", "matching_keypoints")
test.That(t, err, test.ShouldBeNil)
tempDir := t.TempDir()

logger.Infof("writing sample points to %s", tempDir)
// load config
Expand Down
9 changes: 2 additions & 7 deletions vision/keypoints/orb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keypoints
import (
"image"
"image/draw"
"os"
"testing"

"github.com/edaniels/golog"
Expand Down Expand Up @@ -66,9 +65,7 @@ func TestComputeORBKeypoints(t *testing.T) {
test.That(t, len(descs), test.ShouldEqual, 58)
test.That(t, len(kps), test.ShouldEqual, 58)
// save the output image in a temp file
tempDir, err := os.MkdirTemp("", "compute_orb_keypoints")
test.That(t, err, test.ShouldBeNil)
defer os.RemoveAll(tempDir)
tempDir := t.TempDir()
logger.Infof("writing orb keypoint files to %s", tempDir)
keyImg := PlotKeypoints(imGray, kps)
test.That(t, keyImg, test.ShouldNotBeNil)
Expand Down Expand Up @@ -103,9 +100,7 @@ func TestMatchingWithRotation(t *testing.T) {
matchedLines := PlotMatchedLines(matchedOrbPts1, matchedOrbPts2, matchedKps1, matchedKps2, true)
test.That(t, matchedLines, test.ShouldNotBeNil)
// save the output image in a temp file
tempDir, err := os.MkdirTemp("", "match_rotated_points")
test.That(t, err, test.ShouldBeNil)
defer os.RemoveAll(tempDir)
tempDir := t.TempDir()
logger.Infof("writing orb keypoint files to %s", tempDir)
err = rimage.WriteImageToFile(tempDir+"/rotated_chess_orb.png", matchedLines)
test.That(t, err, test.ShouldBeNil)
Expand Down