github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/api/cloudcontroller/ccv2/cloudcontrollerv2_suite_test.go (about)

     1  package ccv2_test
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  	"log"
     7  	"net/http"
     8  	"strings"
     9  
    10  	. "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
    11  
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/gomega"
    14  	. "github.com/onsi/gomega/ghttp"
    15  
    16  	"testing"
    17  )
    18  
    19  func TestCloudcontrollerv2(t *testing.T) {
    20  	RegisterFailHandler(Fail)
    21  	RunSpecs(t, "Cloud Controller V2 Suite")
    22  }
    23  
    24  var server *Server
    25  
    26  var _ = BeforeEach(func() {
    27  	server = NewTLSServer()
    28  
    29  	// Suppresses ginkgo server logs
    30  	server.HTTPTestServer.Config.ErrorLog = log.New(&bytes.Buffer{}, "", 0)
    31  })
    32  
    33  var _ = AfterEach(func() {
    34  	server.Close()
    35  })
    36  
    37  func NewTestClient(passed ...Config) *Client {
    38  	return NewClientWithCustomAPIVersion("2.23.0", passed...)
    39  }
    40  
    41  func NewClientWithCustomAPIVersion(apiVersion string, passed ...Config) *Client {
    42  	SetupV2InfoResponse(apiVersion)
    43  
    44  	var config Config
    45  	if len(passed) > 0 {
    46  		config = passed[0]
    47  	} else {
    48  		config = Config{}
    49  	}
    50  	config.AppName = "CF CLI API V2 Test"
    51  	config.AppVersion = "Unknown"
    52  
    53  	client := NewClient(config)
    54  	warnings, err := client.TargetCF(TargetSettings{
    55  		SkipSSLValidation: true,
    56  		URL:               server.URL() + "/",
    57  	})
    58  	Expect(err).ToNot(HaveOccurred())
    59  	Expect(warnings).To(BeEmpty())
    60  	return client
    61  }
    62  
    63  func SetupV2InfoResponse(apiVersion string) {
    64  	serverAPIURL := server.URL()[8:]
    65  	response := fmt.Sprintf(`{
    66  		"name":"",
    67  		"build":"",
    68  		"support":"http://support.cloudfoundry.com",
    69  		"version":0,
    70  		"description":"",
    71  		"authorization_endpoint":"https://login.APISERVER",
    72  		"min_cli_version":null,
    73  		"min_recommended_cli_version":null,
    74  		"api_version":"%s",
    75  		"app_ssh_endpoint":"ssh.APISERVER",
    76  		"app_ssh_host_key_fingerprint":"a6:d1:08:0b:b0:cb:9b:5f:c4:ba:44:2a:97:26:19:8a",
    77  		"routing_endpoint": "https://APISERVER/routing",
    78  		"app_ssh_oauth_client":"ssh-proxy",
    79  		"logging_endpoint":"wss://loggregator.APISERVER",
    80  		"doppler_logging_endpoint":"wss://doppler.APISERVER"
    81  	}`, apiVersion)
    82  	response = strings.Replace(response, "APISERVER", serverAPIURL, -1)
    83  	server.AppendHandlers(
    84  		CombineHandlers(
    85  			VerifyRequest(http.MethodGet, "/v2/info"),
    86  			RespondWith(http.StatusOK, response),
    87  		),
    88  	)
    89  }
    90  
    91  func validateV2InfoPlusNumberOfRequests(numberOfPostInfoRequests int) {
    92  	Expect(server.ReceivedRequests()).To(HaveLen(numberOfPostInfoRequests + 1))
    93  }