github.com/jcarley/cli@v0.0.0-20180201210820-966d90434c30/commands/certs/rm_test.go (about)

     1  package certs
     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 certRmTests = []struct {
    13  	name       string
    14  	downStream string
    15  	expectErr  bool
    16  }{
    17  	{certName, test.DownStream, false},
    18  	{"bad-cert-name", test.DownStream, true},
    19  }
    20  
    21  func TestCertsRm(t *testing.T) {
    22  	mux, server, baseURL := test.Setup()
    23  	defer test.Teardown(server)
    24  	settings := test.GetSettings(baseURL.String())
    25  	mux.HandleFunc("/environments/"+test.EnvID+"/services/"+test.SvcID+"/certs/"+certName,
    26  		func(w http.ResponseWriter, r *http.Request) {
    27  			test.AssertEquals(t, r.Method, "DELETE")
    28  			fmt.Fprint(w, "")
    29  		},
    30  	)
    31  	mux.HandleFunc("/environments/"+test.EnvID+"/services",
    32  		func(w http.ResponseWriter, r *http.Request) {
    33  			test.AssertEquals(t, r.Method, "GET")
    34  			fmt.Fprint(w, fmt.Sprintf(`[{"id":"%s","label":"%s"}]`, test.SvcID, test.DownStream))
    35  		},
    36  	)
    37  
    38  	for _, data := range certRmTests {
    39  		t.Logf("Data: %+v", data)
    40  
    41  		// test
    42  		err := CmdRm(data.name, New(settings), services.New(settings), data.downStream)
    43  
    44  		// assert
    45  		if err != nil != data.expectErr {
    46  			t.Errorf("Unexpected error: %s", err)
    47  			continue
    48  		}
    49  	}
    50  }