github.com/jcarley/cli@v0.0.0-20180201210820-966d90434c30/commands/git/show_test.go (about) 1 package git 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/daticahealth/cli/commands/services" 9 "github.com/daticahealth/cli/test" 10 ) 11 12 var showTests = []struct { 13 svcLabel string 14 expectErr bool 15 }{ 16 {test.SvcLabel, false}, 17 {"invalid-svc", true}, 18 } 19 20 func TestShow(t *testing.T) { 21 mux, server, baseURL := test.Setup() 22 defer test.Teardown(server) 23 settings := test.GetSettings(baseURL.String()) 24 mux.HandleFunc("/environments/"+test.EnvID+"/services", 25 func(w http.ResponseWriter, r *http.Request) { 26 test.AssertEquals(t, r.Method, "GET") 27 fmt.Fprintf(w, `[{"id":"%s","label":"%s","source":"git@github.com/github/github.git"}]`, test.SvcID, test.SvcLabel) 28 }, 29 ) 30 31 for _, data := range showTests { 32 t.Logf("Data: %+v", data) 33 34 // test 35 err := CmdShow(data.svcLabel, services.New(settings)) 36 37 // assert 38 if err != nil != data.expectErr { 39 t.Errorf("Unexpected error: %s", err) 40 continue 41 } 42 } 43 }