github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/api/hpcs/endpoint_test.go (about)

     1  package hpcs
     2  
     3  import (
     4  	"log"
     5  	"net/http"
     6  
     7  	bluemix "github.com/IBM-Cloud/bluemix-go"
     8  	"github.com/IBM-Cloud/bluemix-go/client"
     9  	"github.com/IBM-Cloud/bluemix-go/session"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  	"github.com/onsi/gomega/ghttp"
    13  )
    14  
    15  var _ = Describe("HpcsRepository", func() {
    16  	var (
    17  		server *ghttp.Server
    18  	)
    19  
    20  	Describe("Get()", func() {
    21  		Context("When generating endpoint", func() {
    22  			BeforeEach(func() {
    23  				server = ghttp.NewServer()
    24  				server.AppendHandlers(
    25  					ghttp.CombineHandlers(
    26  						ghttp.VerifyRequest(http.MethodGet, "/instances/abc"),
    27  						ghttp.RespondWith(http.StatusCreated, `{}`),
    28  					),
    29  				)
    30  			})
    31  
    32  			It("should return success", func() {
    33  				_, err := newTestHpcsRepo(server.URL()).GetAPIEndpoint("abc")
    34  
    35  				Expect(err).NotTo(HaveOccurred())
    36  			})
    37  		})
    38  	})
    39  
    40  })
    41  
    42  func newTestHpcsRepo(url string) EndpointRepository {
    43  	sess, err := session.New()
    44  	if err != nil {
    45  		log.Fatal(err)
    46  	}
    47  	conf := sess.Config.Copy()
    48  	conf.Endpoint = &url
    49  	client := client.Client{
    50  		Config:      conf,
    51  		ServiceName: bluemix.HPCService,
    52  	}
    53  	return NewHpcsEndpointRepository(&client)
    54  }