Skip to content

Commit

Permalink
setup example case for running with debuggability locally
Browse files Browse the repository at this point in the history
  • Loading branch information
microsoftly committed Sep 27, 2018
1 parent dff5f88 commit 0be551f
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 25 deletions.
14 changes: 11 additions & 3 deletions analyzers/nodejs/integration_test.go
Expand Up @@ -60,14 +60,17 @@ func TestTestSetup(t *testing.T) {
}

func TestAnalysisOutput(t *testing.T) {
t.Parallel()
// t.Parallel()
for _, proj := range projects {
t.Run(proj.Name, func(t *testing.T) {
// t.Parallel()
allowNpmErr := proj.Name == "standard"
projPath := filepath.Join(nodeAnalyzerFixtureDir, proj.Name)
module := module.Module{
Dir: filepath.Join(nodeAnalyzerFixtureDir, proj.Name),
Dir: projPath,
Type: pkg.NodeJS,
Name: proj.Name,
Options: map[string]interface{}{"allow-npm-err": proj.Name == "standard"},
Options: map[string]interface{}{"allow-npm-err": allowNpmErr},
BuildTarget: filepath.Join(nodeAnalyzerFixtureDir, proj.Name, "package.json"),
}

Expand All @@ -84,6 +87,11 @@ func TestAnalysisOutput(t *testing.T) {
assert.NotEmpty(t, deps.Direct)
assert.NotEmpty(t, deps.Transitive)
}

str, err := runfossa.ReportLicenses(projPath, "--option", "allow-npm-err:true")
assert.NoError(t, err)
assert.NotNil(t, str)
assert.NotEqual(t, "", str)
})
}
}
Expand Down
42 changes: 22 additions & 20 deletions cmd/fossa/app/app.go
Expand Up @@ -19,26 +19,28 @@ import (
"github.com/fossas/fossa-cli/config"
)

var App = cli.App{
Name: "fossa-cli",
Usage: "Fast, portable and reliable dependency analysis (https://github.com/fossas/fossa-cli/)",
Version: version.String(),
Action: Run,
EnableBashCompletion: true,
Flags: flags.Combine(
initc.Cmd.Flags,
analyze.Cmd.Flags,
flags.WithGlobalFlags(nil),
),
Commands: []cli.Command{
initc.Cmd,
build.Cmd,
analyze.Cmd,
upload.Cmd,
report.Cmd,
test.Cmd,
update.Cmd,
},
func New() *cli.App {
return &cli.App{
Name: "fossa-cli",
Usage: "Fast, portable and reliable dependency analysis (https://github.com/fossas/fossa-cli/)",
Version: version.String(),
Action: Run,
EnableBashCompletion: true,
Flags: flags.Combine(
initc.Cmd.Flags,
analyze.Cmd.Flags,
flags.WithGlobalFlags(nil),
),
Commands: []cli.Command{
initc.Cmd,
build.Cmd,
analyze.Cmd,
upload.Cmd,
report.Cmd,
test.Cmd,
update.Cmd,
},
}
}

func Run(ctx *cli.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/fossa/main.go
Expand Up @@ -10,7 +10,7 @@ import (
)

func main() {
err := app.App.Run(os.Args)
err := app.New().Run(os.Args)
if err != nil {
switch e := err.(type) {
case *cli.ExitError:
Expand Down
40 changes: 39 additions & 1 deletion testing/runfossa/runfossa.go
@@ -1,6 +1,13 @@
package runfossa

import "github.com/fossas/fossa-cli/exec"
import (
"bytes"
"io"
"os"

"github.com/fossas/fossa-cli/cmd/fossa/app"
"github.com/fossas/fossa-cli/exec"
)

// Init executes fossa init the provided directory
func Init(projectDir string) error {
Expand All @@ -18,3 +25,34 @@ func Init(projectDir string) error {

return err
}

func ReportLicenses(dir string, params ...string) (string, error) {
old := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w

outC := make(chan string)

origApiKey := os.Getenv("FOSSA_API_KEY")
// os.Setenv("FOSSA_API_KEY", "abc")
os.Chdir(dir)
cliCommand := []string{"fossa", "report", "licenses"}

cliCommand = append(cliCommand, params...)

go func() {
var buf bytes.Buffer
io.Copy(&buf, r)
outC <- buf.String()
}()

err := app.New().Run(cliCommand)
os.Setenv("FOSSA_API_KEY", origApiKey)

// back to normal state
w.Close()
os.Stdout = old // restoring the real stdout
out := <-outC

return out, err
}

0 comments on commit 0be551f

Please sign in to comment.