github.com/joey-fossa/fossa-cli@v0.7.34-0.20190708193710-569f1e8679f0/analyzers/buck/buck_test.go (about) 1 package buck_test 2 3 import ( 4 "testing" 5 6 "github.com/pkg/errors" 7 "github.com/stretchr/testify/assert" 8 9 "github.com/fossas/fossa-cli/analyzers/buck" 10 "github.com/fossas/fossa-cli/module" 11 "github.com/fossas/fossa-cli/pkg" 12 ) 13 14 func TestDiscoveryAliasConfig(t *testing.T) { 15 dir := "testdata/buckconfig/Alias" 16 modules, err := buck.DiscoverWithCommand(dir, make(map[string]interface{}), mockBuck) 17 assert.NoError(t, err) 18 assert.Equal(t, len(modules), 2) 19 assert.Contains(t, modules, testModule("one", "//test:one", dir)) 20 assert.Contains(t, modules, testModule("two", "//test:two", dir)) 21 } 22 23 func TestDiscoveryEmptyAliasConfig(t *testing.T) { 24 dir := "testdata/buckconfig/EmptyAlias" 25 modules, err := buck.DiscoverWithCommand(dir, make(map[string]interface{}), mockBuck) 26 assert.NoError(t, err) 27 assert.Equal(t, len(modules), 2) 28 assert.Contains(t, modules, testModule("//test:one", "//test:one", dir)) 29 assert.Contains(t, modules, testModule("//test:two", "//test:two", dir)) 30 } 31 32 func TestDiscoveryBlankConfig(t *testing.T) { 33 dir := "testdata/buckconfig/Blank" 34 modules, err := buck.DiscoverWithCommand(dir, make(map[string]interface{}), mockBuck) 35 assert.NoError(t, err) 36 assert.Equal(t, len(modules), 2) 37 assert.Contains(t, modules, testModule("//test:one", "//test:one", dir)) 38 assert.Contains(t, modules, testModule("//test:two", "//test:two", dir)) 39 } 40 41 func TestDiscoveryBUCKFile(t *testing.T) { 42 dir := "testdata/BUCK" 43 modules, err := buck.DiscoverWithCommand(dir, make(map[string]interface{}), mockBuck) 44 assert.NoError(t, err) 45 assert.Equal(t, len(modules), 2) 46 assert.Contains(t, modules, testModule("//test:one", "//test:one", dir)) 47 assert.Contains(t, modules, testModule("//test:two", "//test:two", dir)) 48 } 49 50 func testModule(name, target, dir string) module.Module { 51 return module.Module{ 52 Name: name, 53 Type: pkg.Buck, 54 BuildTarget: target, 55 Dir: dir, 56 } 57 } 58 59 func mockBuck(cmd string, args ...string) (string, error) { 60 switch cmd { 61 case "root": 62 return "", nil 63 case "targets": 64 return "//test:one\n//test:two", nil 65 default: 66 return "", errors.New("Cannot identify the test command") 67 } 68 }