Skip to content

Commit

Permalink
Simplify tests by using GinkgoT().TempDir() (#1265)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear authored Dec 16, 2024
1 parent 09b9143 commit ef1a35f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
7 changes: 2 additions & 5 deletions analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package gosec_test
import (
"errors"
"log"
"os"
"regexp"
"strings"

Expand Down Expand Up @@ -45,10 +44,8 @@ var _ = Describe("Analyzer", func() {
Context("when processing a package", func() {
It("should not report an error if the package contains no Go files", func() {
analyzer.LoadRules(rules.Generate(false).RulesInfo())
dir, err := os.MkdirTemp("", "empty")
defer os.RemoveAll(dir)
Expect(err).ShouldNot(HaveOccurred())
err = analyzer.Process(buildTags, dir)
dir := GinkgoT().TempDir()
err := analyzer.Process(buildTags, dir)
Expect(err).ShouldNot(HaveOccurred())
_, _, errors := analyzer.Report()
Expect(errors).To(BeEmpty())
Expand Down
10 changes: 2 additions & 8 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ var _ = Describe("Helpers", func() {
Context("when listing package paths", func() {
var dir string
JustBeforeEach(func() {
var err error
dir, err = os.MkdirTemp("", "gosec")
Expect(err).ShouldNot(HaveOccurred())
_, err = os.MkdirTemp(dir, "test*.go")
Expect(err).ShouldNot(HaveOccurred())
})
AfterEach(func() {
err := os.RemoveAll(dir)
dir = GinkgoT().TempDir()
_, err := os.MkdirTemp(dir, "test*.go")
Expect(err).ShouldNot(HaveOccurred())
})
It("should return the root directory as package path", func() {
Expand Down

0 comments on commit ef1a35f

Please sign in to comment.