github.com/qri-io/qri@v0.10.1-0.20220104210721-c771715036cb/cmd/print_test.go (about) 1 package cmd 2 3 import ( 4 "bytes" 5 "context" 6 "fmt" 7 "runtime" 8 "testing" 9 10 "github.com/qri-io/dag" 11 "github.com/qri-io/qri/dsref" 12 "github.com/qri-io/qri/event" 13 ) 14 15 func TestDoesCommandExist(t *testing.T) { 16 if runtime.GOOS == "darwin" || runtime.GOOS == "linux" { 17 if doesCommandExist("ls") == false { 18 t.Error("ls command does not exist!") 19 } 20 if doesCommandExist("ls111") == true { 21 t.Error("ls111 command should not exist!") 22 } 23 } 24 } 25 26 func TestProgressBars(t *testing.T) { 27 ctx, cancel := context.WithCancel(context.Background()) 28 defer cancel() 29 30 bus := event.NewBus(ctx) 31 32 buf := &bytes.Buffer{} 33 PrintProgressBarsOnEvents(buf, bus) 34 35 ref := dsref.MustParse("c/d") 36 37 events := []struct { 38 t event.Type 39 p interface{} 40 }{ 41 {event.ETDatasetSaveStarted, event.DsSaveEvent{Username: "a", Name: "b", Completion: 0.1}}, 42 {event.ETDatasetSaveProgress, event.DsSaveEvent{Username: "a", Name: "b", Completion: 0.2}}, 43 {event.ETDatasetSaveProgress, event.DsSaveEvent{Username: "a", Name: "b", Completion: 0.3}}, 44 {event.ETDatasetSaveCompleted, event.DsSaveEvent{Username: "a", Name: "b", Completion: 0.3, Error: fmt.Errorf("oh noes")}}, 45 46 {event.ETRemoteClientPullVersionProgress, event.RemoteEvent{Ref: ref, Progress: dag.Completion{0, 1, 1}}}, 47 {event.ETRemoteClientPushVersionProgress, event.RemoteEvent{Ref: ref, Progress: dag.Completion{0, 1, 1}}}, 48 {event.ETRemoteClientPullVersionCompleted, event.RemoteEvent{Ref: ref, Progress: dag.Completion{0, 1, 1}, Error: fmt.Errorf("ooooh noes")}}, 49 {event.ETRemoteClientPushVersionCompleted, event.RemoteEvent{Ref: ref, Progress: dag.Completion{0, 1, 1}, Error: fmt.Errorf("ooooh noes")}}, 50 } 51 52 for _, e := range events { 53 bus.Publish(ctx, e.t, e.p) 54 } 55 }