github.com/dan-leo/glide@v0.13.4-0.20210218130343-57e8627e3947/action/get_test.go (about)

     1  package action
     2  
     3  import (
     4  	"io/ioutil"
     5  	"testing"
     6  
     7  	"github.com/Masterminds/glide/cfg"
     8  	"github.com/Masterminds/glide/msg"
     9  )
    10  
    11  func TestAddPkgsToConfig(t *testing.T) {
    12  	// Route output to discard so it's not displayed with the test output.
    13  	o := msg.Default.Stderr
    14  	msg.Default.Stderr = ioutil.Discard
    15  
    16  	conf := new(cfg.Config)
    17  	dep := new(cfg.Dependency)
    18  	dep.Name = "github.com/Masterminds/cookoo"
    19  	dep.Subpackages = append(dep.Subpackages, "convert")
    20  	conf.Imports = append(conf.Imports, dep)
    21  
    22  	names := []string{
    23  		"github.com/Masterminds/cookoo/fmt",
    24  		"github.com/Masterminds/semver",
    25  	}
    26  
    27  	addPkgsToConfig(conf, names, false, true, false)
    28  
    29  	if !conf.HasDependency("github.com/Masterminds/semver") {
    30  		t.Error("addPkgsToConfig failed to add github.com/Masterminds/semver")
    31  	}
    32  
    33  	d := conf.Imports.Get("github.com/Masterminds/cookoo")
    34  	found := false
    35  	for _, s := range d.Subpackages {
    36  		if s == "fmt" {
    37  			found = true
    38  		}
    39  	}
    40  	if !found {
    41  		t.Error("addPkgsToConfig failed to add subpackage to existing import")
    42  	}
    43  
    44  	// Restore messaging to original location
    45  	msg.Default.Stderr = o
    46  }