github.com/MealCraft/glide@v0.13.4/action/list_test.go (about)

     1  package action
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/json"
     6  	"testing"
     7  
     8  	"github.com/Masterminds/glide/msg"
     9  )
    10  
    11  func TestList(t *testing.T) {
    12  	msg.Default.PanicOnDie = true
    13  	old := msg.Default.Stdout
    14  	defer func() {
    15  		msg.Default.Stdout = old
    16  	}()
    17  
    18  	var buf bytes.Buffer
    19  	msg.Default.Stdout = &buf
    20  	List("../", false, "text")
    21  	if buf.Len() < 5 {
    22  		t.Error("Expected some data to be found.")
    23  	}
    24  
    25  	var buf2 bytes.Buffer
    26  	msg.Default.Stdout = &buf2
    27  	List("../", false, "json")
    28  	j := buf2.Bytes()
    29  	var o PackageList
    30  	err := json.Unmarshal(j, &o)
    31  	if err != nil {
    32  		t.Errorf("Error unmarshaling json list: %s", err)
    33  	}
    34  	if len(o.Installed) == 0 {
    35  		t.Error("No packages found on json list")
    36  	}
    37  
    38  	var buf3 bytes.Buffer
    39  	msg.Default.Stdout = &buf3
    40  	List("../", false, "json-pretty")
    41  	j = buf3.Bytes()
    42  	var o2 PackageList
    43  	err = json.Unmarshal(j, &o2)
    44  	if err != nil {
    45  		t.Errorf("Error unmarshaling json-pretty list: %s", err)
    46  	}
    47  	if len(o2.Installed) == 0 {
    48  		t.Error("No packages found on json-pretty list")
    49  	}
    50  }