gopkg.in/frapposelli/wwhrd.v0@v0.2.1/walker_test.go (about)

     1  package main
     2  
     3  import (
     4  	"path/filepath"
     5  	"testing"
     6  
     7  	"github.com/ryanuber/go-license"
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  //TestWalkImports test walking imports
    12  func TestWalkImports(t *testing.T) {
    13  
    14  	dir, rm := mockGoPackageDir(t, "TestWalkImports")
    15  	defer rm()
    16  
    17  	pkgs, err := WalkImports(dir)
    18  	assert.NoError(t, err)
    19  
    20  	res := make(map[string]bool)
    21  	res["github.com/fake/package"] = true
    22  	res["github.com/fake/nested/inside/a/package"] = true
    23  
    24  	assert.Equal(t, res, pkgs)
    25  
    26  }
    27  
    28  //TestWalkImports test walking imports
    29  func TestGetLicenses(t *testing.T) {
    30  
    31  	dir, rm := mockGoPackageDir(t, "TestGetLicenses")
    32  	defer rm()
    33  
    34  	pkgs, err := WalkImports(dir)
    35  	assert.NoError(t, err)
    36  	lics := GetLicenses(dir, pkgs)
    37  
    38  	res := make(map[string]*license.License)
    39  	var lic license.License
    40  	var lic2 license.License
    41  	lic.File = filepath.Join(dir, "vendor/github.com/fake/package", "LICENSE")
    42  	lic.Text = mockLicense
    43  	lic.Type = "FreeBSD"
    44  
    45  	lic2.File = filepath.Join(dir, "vendor/github.com/fake/nested", "LICENSE")
    46  	lic2.Text = mockLicense
    47  	lic2.Type = "FreeBSD"
    48  
    49  	res["github.com/fake/package"] = &lic
    50  	res["github.com/fake/nested/inside/a/package"] = &lic2
    51  
    52  	assert.Equal(t, res, lics)
    53  
    54  }