github.com/joey-fossa/fossa-cli@v0.7.34-0.20190708193710-569f1e8679f0/buildtools/dep/dep_internal_test.go (about) 1 package dep 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/fossas/fossa-cli/pkg" 9 ) 10 11 func TestIsIgnored(t *testing.T) { 12 man := manifest{Ignored: []string{"apple", "orange*"}} 13 14 // File listed in ignored list is ignored. 15 valid := man.isIgnored("apple") 16 assert.Equal(t, valid, true) 17 18 // Wildcard entry properly ignores its own package. 19 valid = man.isIgnored("orange") 20 assert.Equal(t, valid, true) 21 22 // Wildcard entry properly ignores other packages. 23 valid = man.isIgnored("orange/blood") 24 assert.Equal(t, valid, true) 25 26 // File not listed in ignored list is not ignored. 27 valid = man.isIgnored("apple/fuji") 28 assert.Equal(t, valid, false) 29 } 30 31 func TestReadLockfile(t *testing.T) { 32 // Reading a valid lockfile returns expected data. 33 lock, err := readLockfile("testdata/Gopkg.lock") 34 expectedLockfile := lockfile{ 35 Projects: []Project{ 36 Project{ 37 Name: "cat/fossa", 38 Packages: []string{"."}, 39 Revision: "1", 40 Version: "v0.3.0", 41 }, 42 }, 43 normalized: map[string]pkg.Import{ 44 "cat/fossa": pkg.Import{ 45 Target: "v0.3.0", 46 Resolved: pkg.ID{ 47 Type: pkg.Go, 48 Name: "cat/fossa", 49 Revision: "v0.3.0", 50 Location: "", 51 }, 52 }, 53 }, 54 } 55 56 assert.Equal(t, err, nil) 57 assert.Equal(t, lock, expectedLockfile) 58 59 // Reading an invalid lockfile returns an expected error. 60 _, err = readLockfile("NotAFile") 61 assert.Error(t, err) 62 } 63 64 func TestReadManifest(t *testing.T) { 65 // Reading a valid manifest returns expected data. 66 man, err := readManifest("testdata/Gopkg.toml") 67 expectedManifest := manifest{ 68 Ignored: []string{ 69 "cat/puma", 70 "cat/big/*", 71 }, 72 } 73 74 assert.Equal(t, err, nil) 75 assert.Equal(t, man, expectedManifest) 76 77 // Reading an invalid manifest returns an expected error. 78 _, err = readManifest("NotAFile") 79 assert.Error(t, err) 80 }