Fixed the list tests and fixed list to use msg for output
diff --git a/action/list.go b/action/list.go
index df8935d..8ff6c69 100644
--- a/action/list.go
+++ b/action/list.go
@@ -2,8 +2,6 @@
import (
"encoding/json"
- "fmt"
- "os"
"path/filepath"
"sort"
@@ -87,13 +85,13 @@
}
}
case jsonFormat:
- json.NewEncoder(os.Stdout).Encode(l)
+ json.NewEncoder(msg.Default.Stdout).Encode(l)
case jsonPrettyFormat:
b, err := json.MarshalIndent(l, "", " ")
if err != nil {
msg.Die("could not unmarshal package list: %s", err)
}
- fmt.Println(string(b))
+ msg.Puts(string(b))
default:
msg.Die("invalid output format: must be one of: json|json-pretty|text")
}
diff --git a/action/list_test.go b/action/list_test.go
index 1f2aed5..69e3eaf 100644
--- a/action/list_test.go
+++ b/action/list_test.go
@@ -1,9 +1,50 @@
package action
-import "testing"
+import (
+ "bytes"
+ "encoding/json"
+ "testing"
+
+ "github.com/Masterminds/glide/msg"
+)
func TestList(t *testing.T) {
- if len(List("../", false).Installed) < 1 {
- t.Error("Expected some packages to be found")
+ msg.Default.PanicOnDie = true
+ old := msg.Default.Stdout
+ defer func() {
+ msg.Default.Stdout = old
+ }()
+
+ var buf bytes.Buffer
+ msg.Default.Stdout = &buf
+ List("../", false, "text")
+ if buf.Len() < 5 {
+ t.Error("Expected some data to be found.")
+ }
+
+ var buf2 bytes.Buffer
+ msg.Default.Stdout = &buf2
+ List("../", false, "json")
+ j := buf2.Bytes()
+ var o PackageList
+ err := json.Unmarshal(j, &o)
+ if err != nil {
+ t.Errorf("Error unmarshaling json list: %s", err)
+ }
+ if len(o.Installed) == 0 {
+ t.Error("No packages found on json list")
+ }
+
+ var buf3 bytes.Buffer
+ msg.Default.Stdout = &buf3
+ List("../", false, "json-pretty")
+ j = buf3.Bytes()
+ var o2 PackageList
+ err = json.Unmarshal(j, &o2)
+ if err != nil {
+ t.Errorf("Error unmarshaling json-pretty list: %s", err)
+ }
+ if len(o2.Installed) == 0 {
+ t.Error("No packages found on json-pretty list")
}
}