aboutsummaryrefslogtreecommitdiff
path: root/spdxconv_test.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-01-06 15:46:14 +0700
committerShulhan <ms@kilabit.info>2026-01-06 15:46:14 +0700
commit7ba3a36f94b5dd274ecc932895a05072e6e0080c (patch)
tree0cc0e158853540b3b193c7842ee3301b2cd25500 /spdxconv_test.go
parent2cda75bc9385da199b4db5f6cc2692bfd694fcf1 (diff)
downloadspdxconv-7ba3a36f94b5dd274ecc932895a05072e6e0080c.tar.xz
all: refactoring loadConfig and scanForSCM
Previously, given the following command, $ spdxconv $path the loadConfig load the configuration from the path directory. This changes it to load the configuration from the current working directory where the tools run, not from $path directory. While for scanForSCM, previously its detect SCM from $path up to "/", now its scan from $path to current working directory only. While at it, we rename the dummySCM type to noSCM.
Diffstat (limited to 'spdxconv_test.go')
-rw-r--r--spdxconv_test.go55
1 files changed, 37 insertions, 18 deletions
diff --git a/spdxconv_test.go b/spdxconv_test.go
index 9c66aea..40bcc16 100644
--- a/spdxconv_test.go
+++ b/spdxconv_test.go
@@ -36,15 +36,19 @@ func TestNew(t *testing.T) {
var listCase = []testCase{{
dir: `.`,
exp: &SPDXConv{
+ curDir: tempDir,
dir: tempDir,
scmDir: tempDir,
scm: gitRoot,
},
+ }, {
+ dir: `/tmp`,
+ expError: `New: /tmp must be under the current directory`,
}}
var tc testCase
var conv *SPDXConv
for _, tc = range listCase {
- conv, err = New(`.`)
+ conv, err = New(tc.dir)
if err != nil {
test.Assert(t, tc.dir+`: error`, tc.expError, err.Error())
continue
@@ -128,25 +132,40 @@ func TestSPDXConv_scanFile(t *testing.T) {
}
func TestSPDXConv_scanFiles(t *testing.T) {
+ type testCase struct {
+ dir string
+ exp []string
+ }
+ t.Chdir(`testdata/`)
+ var listCase = []testCase{{
+ dir: `scan/`,
+ exp: []string{
+ `scan/.gitignore`,
+ `scan/test.go`,
+ `scan/test.html`,
+ `scan/test.sh`,
+ },
+ }, {
+ dir: `scan_no_scm/`,
+ exp: []string{
+ `scan_no_scm/test.go`,
+ `scan_no_scm/test.html`,
+ `scan_no_scm/test.sh`,
+ },
+ }}
+ var tc testCase
var conv *SPDXConv
var err error
-
- conv, err = New(`testdata/scan/`)
- if err != nil {
- t.Fatal(err)
- }
-
var got []string
- got, err = conv.scanFiles([]string{`testdata/scan/`})
- if err != nil {
- t.Fatal(err)
- }
-
- var exp = []string{
- `testdata/scan/.gitignore`,
- `testdata/scan/test.go`,
- `testdata/scan/test.html`,
- `testdata/scan/test.sh`,
+ for _, tc = range listCase {
+ conv, err = New(tc.dir)
+ if err != nil {
+ t.Fatal(err)
+ }
+ got, err = conv.scanFiles([]string{tc.dir})
+ if err != nil {
+ t.Fatal(err)
+ }
+ test.Assert(t, tc.dir, tc.exp, got)
}
- test.Assert(t, `scanFiles: testdata/scan/`, exp, got)
}