github.com/joey-fossa/fossa-cli@v0.7.34-0.20190708193710-569f1e8679f0/buildtools/ant/ant_test.go (about)

     1  package ant_test
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  
     9  	"github.com/fossas/fossa-cli/buildtools/ant"
    10  	"github.com/fossas/fossa-cli/pkg"
    11  )
    12  
    13  func TestAntDeps(t *testing.T) {
    14  	graph, err := ant.Graph("testdata")
    15  	assert.NoError(t, err)
    16  	assert.Len(t, graph.Direct, 1)
    17  	assertImport(t, graph.Direct, "test")
    18  
    19  	assert.Len(t, graph.Transitive, 1)
    20  	packageOne, err := findPackage(graph.Transitive, "test")
    21  	assert.NoError(t, err)
    22  	assert.Len(t, packageOne.Imports, 0)
    23  }
    24  
    25  func findPackage(packages map[pkg.ID]pkg.Package, name string) (pkg.Package, error) {
    26  	for id := range packages {
    27  		if id.Name == name {
    28  			return packages[id], nil
    29  		}
    30  	}
    31  	return pkg.Package{}, fmt.Errorf("Package %s not found", name)
    32  }
    33  
    34  func assertImport(t *testing.T, imports pkg.Imports, name string) {
    35  	for _, importedProj := range imports {
    36  		if importedProj.Resolved.Name == name {
    37  			return
    38  		}
    39  	}
    40  	assert.Fail(t, "missing "+name)
    41  }