github.com/joey-fossa/fossa-cli@v0.7.34-0.20190708193710-569f1e8679f0/analyzers/ruby/integration_test.go (about)

     1  package ruby_test
     2  
     3  import (
     4  	"path/filepath"
     5  	"testing"
     6  
     7  	"github.com/apex/log"
     8  	"github.com/stretchr/testify/assert"
     9  
    10  	"github.com/fossas/fossa-cli/analyzers"
    11  	"github.com/fossas/fossa-cli/exec"
    12  	"github.com/fossas/fossa-cli/files"
    13  	"github.com/fossas/fossa-cli/module"
    14  	"github.com/fossas/fossa-cli/pkg"
    15  	"github.com/fossas/fossa-cli/testing/fixtures"
    16  	"github.com/fossas/fossa-cli/testing/runfossa"
    17  )
    18  
    19  var rubyAnalyzerFixtureDir = filepath.Join(fixtures.Directory(), "ruby", "analyzer")
    20  
    21  func TestRubyIntegration(t *testing.T) {
    22  	if testing.Short() {
    23  		return
    24  	}
    25  
    26  	fixtures.Initialize(rubyAnalyzerFixtureDir, projects, projectInitializer)
    27  	for _, project := range projects {
    28  		proj := project
    29  		t.Run("Analysis:\t"+proj.Name, func(t *testing.T) {
    30  
    31  			module := module.Module{
    32  				Dir:         filepath.Join(rubyAnalyzerFixtureDir, proj.Name),
    33  				Type:        pkg.Ruby,
    34  				Name:        proj.Name,
    35  				Options:     proj.ModuleOptions,
    36  				BuildTarget: filepath.Join(rubyAnalyzerFixtureDir, proj.Name),
    37  			}
    38  
    39  			analyzer, err := analyzers.New(module)
    40  			assert.NoError(t, err)
    41  
    42  			deps, err := analyzer.Analyze()
    43  			assert.NoError(t, err)
    44  			assert.NotEmpty(t, deps.Direct)
    45  			assert.NotEmpty(t, deps.Transitive)
    46  		})
    47  	}
    48  }
    49  
    50  func projectInitializer(proj fixtures.Project, projectDir string) error {
    51  	ymlAlreadyExists, err := files.Exists(filepath.Join(projectDir, ".fossa.yml"))
    52  
    53  	if err != nil {
    54  		panic(err)
    55  	}
    56  	if ymlAlreadyExists {
    57  		return nil
    58  	}
    59  
    60  	args := []string{"install"}
    61  
    62  	// we could extend or refactor the fixtures.Project struct, but because this is a single case, this is simpler for the time being
    63  	if proj.Name == "rails" {
    64  		args = append(args, []string{"--deployment", "--without", "doc", "job", "cable", "storage", "ujs", "test", "db"}...)
    65  	}
    66  
    67  	_, stderr, err := exec.Run(exec.Cmd{
    68  		Command: "bundle",
    69  		Name:    "bundle",
    70  		Argv:    args,
    71  		Dir:     projectDir,
    72  	})
    73  	if err != nil {
    74  		log.Error("failed to run bundle on " + proj.Name)
    75  		log.Error(stderr)
    76  		return err
    77  	}
    78  
    79  	// any key will work to prevent the "NEED KEY" error message
    80  	_, stderr, err = runfossa.Init(projectDir)
    81  	if err != nil {
    82  		log.Error("failed to run fossa init on " + proj.Name)
    83  		log.Error(stderr)
    84  		return err
    85  	}
    86  
    87  	return nil
    88  }
    89  
    90  var projects = []fixtures.Project{
    91  	fixtures.Project{
    92  		Name:   "fluentd",
    93  		URL:    "https://github.com/fluent/fluentd.git",
    94  		Commit: "3566901ab4a00e0168b4a6078153dde85601fc53",
    95  	},
    96  	fixtures.Project{
    97  		Name:   "vagrant",
    98  		URL:    "https://github.com/hashicorp/vagrant",
    99  		Commit: "b4d87e6ce9926592bee6943b1feff2194590d62f",
   100  	},
   101  }