Repository: sonatype-nexus-community/nancy
Pull request #99 (2020-03-17 20:36:04)

Testdata per package
Use a `testdata` folder per package.

Keeps it clearer which package is using which data, etc.

Obsoletes PR #97 

cc @bhamail / @DarthHater



Patch:
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 44e9d35..9e5c01a 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -26,7 +26,7 @@ jobs:
       - run: go get -u github.com/jstemmer/go-junit-report
       - run: go test ./... -v 2>&1 -p=1 | go-junit-report > $TEST_RESULTS/gotest/report.xml
       - run: go build 
-      - run: cd testdata/dep && ../../nancy Gopkg.lock && cd -
+      - run: cd packages/testdata && ../../nancy Gopkg.lock && cd -
       - run: ./nancy go.sum
       - run: go list -m all | ./nancy
       - save_cache:
diff --git a/testdata/nancyignores/commented b/configuration/testdata/commented
similarity index 100%
rename from testdata/nancyignores/commented
rename to configuration/testdata/commented
diff --git a/testdata/nancyignores/emptyFile b/configuration/testdata/emptyFile
similarity index 100%
rename from testdata/nancyignores/emptyFile
rename to configuration/testdata/emptyFile
diff --git a/testdata/nancyignores/lotsOfRandomWhitespace b/configuration/testdata/lotsOfRandomWhitespace
similarity index 100%
rename from testdata/nancyignores/lotsOfRandomWhitespace
rename to configuration/testdata/lotsOfRandomWhitespace
diff --git a/testdata/nancyignores/normalIgnore b/configuration/testdata/normalIgnore
similarity index 100%
rename from testdata/nancyignores/normalIgnore
rename to configuration/testdata/normalIgnore
diff --git a/testdata/nancyignores/untilsAndComments b/configuration/testdata/untilsAndComments
similarity index 100%
rename from testdata/nancyignores/untilsAndComments
rename to configuration/testdata/untilsAndComments
diff --git a/testdata/nancyignores/untilsBadDateFormat b/configuration/testdata/untilsBadDateFormat
similarity index 100%
rename from testdata/nancyignores/untilsBadDateFormat
rename to configuration/testdata/untilsBadDateFormat
diff --git a/testdata/nancyignores/untilsInvaild b/configuration/testdata/untilsInvaild
similarity index 100%
rename from testdata/nancyignores/untilsInvaild
rename to configuration/testdata/untilsInvaild
diff --git a/packages/Gopkg.lock b/packages/Gopkg.lock
deleted file mode 100644
index bc476a6..0000000
--- a/packages/Gopkg.lock
+++ /dev/null
@@ -1,104 +0,0 @@
-# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
-
-
-[[projects]]
-  branch = "master"
-  digest = "1:b02e5e3f836f077a3249d1dfe3c57d305e007f71a98f2e69c170a2dd8d2b266c"
-  name = "github.com/AndreasBriese/bbloom"
-  packages = ["."]
-  pruneopts = "UT"
-  revision = "343706a395b76e5ca5c7dca46a5d937b48febc74"
-
-[[projects]]
-  digest = "1:9f3b30d9f8e0d7040f729b82dcbc8f0dead820a133b3147ce355fc451f32d761"
-  name = "gopkg.in/BurntSushi/toml"
-  packages = ["."]
-  pruneopts = "UT"
-  revision = "3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005"
-  version = "v0.3.1" 
-
-[[projects]]
-  digest = "1:5f5090f05382959db941fa45acbeb7f4c5241aa8ac0f8f4393dec696e5953f53"
-  name = "github.com/dgraph-io/badger"
-  packages = [
-    ".",
-    "options",
-    "protos",
-    "skl",
-    "table",
-    "y",
-  ]
-  pruneopts = "UT"
-  revision = "99233d725dbdd26d156c61b2f42ae1671b794656"
-  version = "v1.5.4"
-
-[[projects]]
-  branch = "master"
-  digest = "1:8583eab935e3d99d3a7ac489cd2ee7c8e95eecd7c64ab1fc8382746dacaf8563"
-  name = "github.com/dgryski/go-farm"
-  packages = ["."]
-  pruneopts = "UT"
-  revision = "2de33835d10275975374b37b2dcfd22c9020a1f5"
-
-[[projects]]
-  digest = "1:97df918963298c287643883209a2c3f642e6593379f97ab400c2a2e219ab647d"
-  name = "github.com/golang/protobuf"
-  packages = ["proto"]
-  pruneopts = "UT"
-  revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5"
-  version = "v1.2.0"
-
-[[projects]]
-  branch = "master"
-  digest = "1:be40f095cd741773905744f16c1f7a21fd9226ccd0529f019deb7da6d667f71c"
-  name = "github.com/logrusorgru/aurora"
-  packages = ["."]
-  pruneopts = "UT"
-  revision = "a7b3b318ed4e1ae5b80602b08627267303c68572"
-
-[[projects]]
-  digest = "1:40e195917a951a8bf867cd05de2a46aaf1806c50cf92eebf4c16f78cd196f747"
-  name = "github.com/pkg/errors"
-  packages = ["."]
-  pruneopts = "UT"
-  revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
-  version = "v0.8.0"
-
-[[projects]]
-  digest = "1:81e02c4edb639c80559c0650f9401d3e2dcc3256d1fa215382bb7c83c1db9126"
-  name = "github.com/shopspring/decimal"
-  packages = ["."]
-  pruneopts = "UT"
-  revision = "cd690d0c9e2447b1ef2a129a6b7b49077da89b8e"
-  version = "1.1.0"
-
-[[projects]]
-  branch = "master"
-  digest = "1:efaa752dec586e4475fc77cc84a3a0718d19084e2e716e282fc78d7a0f75a7f7"
-  name = "golang.org/x/net"
-  packages = [
-    "internal/timeseries",
-    "trace",
-  ]
-  pruneopts = "UT"
-  revision = "927f97764cc334a6575f4b7a1584a147864d5723"
-
-[[projects]]
-  branch = "master"
-  digest = "1:5b7594f7c43cb5fc8f31c3f4a9f6a61ee798dbd5fcb36b70cb3d4780aad4c509"
-  name = "golang.org/x/sys"
-  packages = ["unix"]
-  pruneopts = "UT"
-  revision = "9a3f9b0469bbc6b8802087ae5c0af9f61502de01"
-
-[solve-meta]
-  analyzer-name = "dep"
-  analyzer-version = 1
-  input-imports = [
-    "github.com/BurntSushi/toml",
-    "github.com/dgraph-io/badger",
-    "github.com/logrusorgru/aurora",
-    "github.com/shopspring/decimal",
-  ]
-  solver-name = "gps-cdcl"
-  solver-version = 1


Test patch:
diff --git a/configuration/parse_test.go b/configuration/parse_test.go
index 513d37e..9d8f2aa 100644
--- a/configuration/parse_test.go
+++ b/configuration/parse_test.go
@@ -28,16 +28,16 @@ import (
 )
 
 func TestConfigParse(t *testing.T) {
-	file, _ := os.Open("../testdata/nancyignores/normalIgnore")
-	emptyFile, _ := os.Open("../testdata/nancyignores/emptyFile")
-	lotsOfRandomNewlinesFile, _ := os.Open("../testdata/nancyignores/lotsOfRandomWhitespace")
-	commentedFile, _ := os.Open("../testdata/nancyignores/commented")
-	untilsFile, _ := os.Open("../testdata/nancyignores/untilsAndComments")
-	invalidUntilsFile, _ := os.Open("../testdata/nancyignores/untilsInvaild")
+	file, _ := os.Open("testdata/normalIgnore")
+	emptyFile, _ := os.Open("testdata/emptyFile")
+	lotsOfRandomNewlinesFile, _ := os.Open("testdata/lotsOfRandomWhitespace")
+	commentedFile, _ := os.Open("testdata/commented")
+	untilsFile, _ := os.Open("testdata/untilsAndComments")
+	invalidUntilsFile, _ := os.Open("testdata/untilsInvaild")
 	invalidUntilLine, _ := bufio.NewReader(invalidUntilsFile).ReadString('\n')
 	invalidUntilLine = strings.TrimSpace(invalidUntilLine)
 
-	invalidDateUntilsFile, _ := os.Open("../testdata/nancyignores/untilsBadDateFormat")
+	invalidDateUntilsFile, _ := os.Open("testdata/untilsBadDateFormat")
 	invalidDateUntilLine, _ := bufio.NewReader(invalidDateUntilsFile).ReadString('\n')
 	invalidDateUntilLine = strings.TrimSpace(invalidDateUntilLine)
 
diff --git a/packages/dep_int_test.go b/packages/dep_int_test.go
index c52a533..0e0179b 100644
--- a/packages/dep_int_test.go
+++ b/packages/dep_int_test.go
@@ -81,13 +81,19 @@ func doGoPathSimulatedSetup(t *testing.T) (string, string, error) {
 	if e != nil {
 		t.Error(e)
 	}
-	lockBytes, _ := ioutil.ReadFile("../testdata/dep/Gopkg.lock")
+	lockBytes, e := ioutil.ReadFile("testdata/Gopkg.lock")
+	if e != nil {
+		t.Error(e)
+	}
 	e = ioutil.WriteFile(fmt.Sprint(projectDir, "/Gopkg.lock"), lockBytes, 0644)
 	if e != nil {
 		t.Error(e)
 	}
 
-	tomlBytes, _ := ioutil.ReadFile("../testdata/dep/Gopkg.toml")
+	tomlBytes, e := ioutil.ReadFile("testdata/Gopkg.toml")
+	if e != nil {
+		t.Error(e)
+	}
 	e = ioutil.WriteFile(fmt.Sprint(projectDir, "/Gopkg.toml"), tomlBytes, 0644)
 	if e != nil {
 		t.Error(e)
diff --git a/packages/mod_test.go b/packages/mod_test.go
index 9f6e5a7..536bbe9 100644
--- a/packages/mod_test.go
+++ b/packages/mod_test.go
@@ -19,7 +19,7 @@ import (
 	"github.com/sonatype-nexus-community/nancy/types"
 )
 
-var testGoSumName = "go.sum"
+var testGoSumName = "testdata/go.sum"
 
 // Simulate calling parse.GopkgLock()
 func getProjectList() (projectList types.ProjectList) {
diff --git a/testdata/dep/Gopkg.lock b/packages/testdata/Gopkg.lock
similarity index 100%
rename from testdata/dep/Gopkg.lock
rename to packages/testdata/Gopkg.lock
diff --git a/testdata/dep/Gopkg.toml b/packages/testdata/Gopkg.toml
similarity index 100%
rename from testdata/dep/Gopkg.toml
rename to packages/testdata/Gopkg.toml
diff --git a/packages/go.sum b/packages/testdata/go.sum
similarity index 100%
rename from packages/go.sum
rename to packages/testdata/go.sum
diff --git a/parse/parse_test.go b/parse/parse_test.go
index 080ffbe..06b2703 100644
--- a/parse/parse_test.go
+++ b/parse/parse_test.go
@@ -20,7 +20,7 @@ import (
 )
 
 func TestGoSum(t *testing.T) {
-	deps, err := GoSum("../testdata/parse/go.sum")
+	deps, err := GoSum("testdata/go.sum")
 	if err != nil {
 		t.Error(err)
 	}
diff --git a/testdata/parse/go.sum b/parse/testdata/go.sum
similarity index 100%
rename from testdata/parse/go.sum
rename to parse/testdata/go.sum
diff --git a/testdata/parse/Gopkg.lock b/testdata/parse/Gopkg.lock
deleted file mode 100644
index bc476a6..0000000
--- a/testdata/parse/Gopkg.lock
+++ /dev/null
@@ -1,104 +0,0 @@
-# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
-
-
-[[projects]]
-  branch = "master"
-  digest = "1:b02e5e3f836f077a3249d1dfe3c57d305e007f71a98f2e69c170a2dd8d2b266c"
-  name = "github.com/AndreasBriese/bbloom"
-  packages = ["."]
-  pruneopts = "UT"
-  revision = "343706a395b76e5ca5c7dca46a5d937b48febc74"
-
-[[projects]]
-  digest = "1:9f3b30d9f8e0d7040f729b82dcbc8f0dead820a133b3147ce355fc451f32d761"
-  name = "gopkg.in/BurntSushi/toml"
-  packages = ["."]
-  pruneopts = "UT"
-  revision = "3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005"
-  version = "v0.3.1" 
-
-[[projects]]
-  digest = "1:5f5090f05382959db941fa45acbeb7f4c5241aa8ac0f8f4393dec696e5953f53"
-  name = "github.com/dgraph-io/badger"
-  packages = [
-    ".",
-    "options",
-    "protos",
-    "skl",
-    "table",
-    "y",
-  ]
-  pruneopts = "UT"
-  revision = "99233d725dbdd26d156c61b2f42ae1671b794656"
-  version = "v1.5.4"
-
-[[projects]]
-  branch = "master"
-  digest = "1:8583eab935e3d99d3a7ac489cd2ee7c8e95eecd7c64ab1fc8382746dacaf8563"
-  name = "github.com/dgryski/go-farm"
-  packages = ["."]
-  pruneopts = "UT"
-  revision = "2de33835d10275975374b37b2dcfd22c9020a1f5"
-
-[[projects]]
-  digest = "1:97df918963298c287643883209a2c3f642e6593379f97ab400c2a2e219ab647d"
-  name = "github.com/golang/protobuf"
-  packages = ["proto"]
-  pruneopts = "UT"
-  revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5"
-  version = "v1.2.0"
-
-[[projects]]
-  branch = "master"
-  digest = "1:be40f095cd741773905744f16c1f7a21fd9226ccd0529f019deb7da6d667f71c"
-  name = "github.com/logrusorgru/aurora"
-  packages = ["."]
-  pruneopts = "UT"
-  revision = "a7b3b318ed4e1ae5b80602b08627267303c68572"
-
-[[projects]]
-  digest = "1:40e195917a951a8bf867cd05de2a46aaf1806c50cf92eebf4c16f78cd196f747"
-  name = "github.com/pkg/errors"
-  packages = ["."]
-  pruneopts = "UT"
-  revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
-  version = "v0.8.0"
-
-[[projects]]
-  digest = "1:81e02c4edb639c80559c0650f9401d3e2dcc3256d1fa215382bb7c83c1db9126"
-  name = "github.com/shopspring/decimal"
-  packages = ["."]
-  pruneopts = "UT"
-  revision = "cd690d0c9e2447b1ef2a129a6b7b49077da89b8e"
-  version = "1.1.0"
-
-[[projects]]
-  branch = "master"
-  digest = "1:efaa752dec586e4475fc77cc84a3a0718d19084e2e716e282fc78d7a0f75a7f7"
-  name = "golang.org/x/net"
-  packages = [
-    "internal/timeseries",
-    "trace",
-  ]
-  pruneopts = "UT"
-  revision = "927f97764cc334a6575f4b7a1584a147864d5723"
-
-[[projects]]
-  branch = "master"
-  digest = "1:5b7594f7c43cb5fc8f31c3f4a9f6a61ee798dbd5fcb36b70cb3d4780aad4c509"
-  name = "golang.org/x/sys"
-  packages = ["unix"]
-  pruneopts = "UT"
-  revision = "9a3f9b0469bbc6b8802087ae5c0af9f61502de01"
-
-[solve-meta]
-  analyzer-name = "dep"
-  analyzer-version = 1
-  input-imports = [
-    "github.com/BurntSushi/toml",
-    "github.com/dgraph-io/badger",
-    "github.com/logrusorgru/aurora",
-    "github.com/shopspring/decimal",
-  ]
-  solver-name = "gps-cdcl"
-  solver-version = 1