github.com/joey-fossa/fossa-cli@v0.7.34-0.20190708193710-569f1e8679f0/analyzers/nodejs/mocks_test.go (about) 1 package nodejs_test 2 3 import ( 4 "errors" 5 6 "github.com/fossas/fossa-cli/buildtools/npm" 7 "github.com/fossas/fossa-cli/files" 8 ) 9 10 type MockNPM struct { 11 JSONFilename string 12 } 13 14 func (n MockNPM) List(_ string) (npm.Output, error) { 15 var output npm.Output 16 err := files.ReadJSON(&output, n.JSONFilename) 17 if err != nil { 18 panic(err) 19 } 20 return output, nil 21 } 22 23 func (n MockNPM) Clean(dir string) error { 24 return nil 25 } 26 27 func (n MockNPM) Install(dir string) error { 28 return nil 29 } 30 31 // Keeping this true means that yarn will not be favored 32 func (n MockNPM) Exists() bool { 33 return true 34 } 35 36 type MockNPMFailure struct{} 37 38 func (n MockNPMFailure) List(_ string) (npm.Output, error) { 39 return npm.Output{}, errors.New("expected failure for npm list") 40 } 41 42 func (n MockNPMFailure) Clean(dir string) error { 43 return errors.New("expected failure for npm clean") 44 } 45 46 func (n MockNPMFailure) Install(dir string) error { 47 return errors.New("expected failure for npm i") 48 } 49 50 func (n MockNPMFailure) Exists() bool { 51 return true 52 }