github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/api/router/router_suite_test.go (about)

     1  package router_test
     2  
     3  import (
     4  	"bytes"
     5  	"log"
     6  	"net/url"
     7  
     8  	"code.cloudfoundry.org/cli/api/router"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/ghttp"
    12  
    13  	"testing"
    14  )
    15  
    16  func TestRouter(t *testing.T) {
    17  	RegisterFailHandler(Fail)
    18  	RunSpecs(t, "Router Suite")
    19  }
    20  
    21  var server *Server
    22  
    23  var _ = SynchronizedBeforeSuite(func() []byte {
    24  	return []byte{}
    25  }, func(data []byte) {
    26  	server = NewTLSServer()
    27  
    28  	// Suppresses ginkgo server logs
    29  	server.HTTPTestServer.Config.ErrorLog = log.New(&bytes.Buffer{}, "", 0)
    30  })
    31  
    32  var _ = SynchronizedAfterSuite(func() {
    33  	server.Close()
    34  }, func() {})
    35  
    36  var _ = BeforeEach(func() {
    37  	server.Reset()
    38  })
    39  
    40  func NewTestConfig() router.Config {
    41  	return router.Config{
    42  		AppName:    "TestApp",
    43  		AppVersion: "1.2.3",
    44  	}
    45  }
    46  
    47  func NewTestRouterClient(config router.Config) *router.Client {
    48  	resource, err := url.Parse("/routing")
    49  	Expect(err).ToNot(HaveOccurred())
    50  	baseURL, err := url.Parse(server.URL())
    51  	Expect(err).ToNot(HaveOccurred())
    52  
    53  	config.RoutingEndpoint = baseURL.ResolveReference(resource).String()
    54  	config.SkipSSLValidation = true
    55  	client := router.NewClient(config)
    56  
    57  	return client
    58  }