github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/api/globaltagging/globaltaggingv3/tagging_test.go (about) 1 package globaltaggingv3 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 bluemixHttp "github.com/IBM-Cloud/bluemix-go/http" 10 "github.com/IBM-Cloud/bluemix-go/session" 11 12 "github.com/onsi/gomega/ghttp" 13 14 . "github.com/onsi/ginkgo" 15 . "github.com/onsi/gomega" 16 ) 17 18 var _ = Describe("Tasks", func() { 19 var server *ghttp.Server 20 AfterEach(func() { 21 server.Close() 22 }) 23 Describe("PostQuery", func() { 24 Context("When PostQuery is successful", func() { 25 BeforeEach(func() { 26 server = ghttp.NewServer() 27 server.AppendHandlers( 28 ghttp.CombineHandlers( 29 ghttp.VerifyRequest(http.MethodGet, "/v3/tags"), 30 ghttp.RespondWith(http.StatusOK, ` 31 { 32 "items": { 33 } 34 } 35 `), 36 ), 37 ) 38 }) 39 40 It("should return query results", func() { 41 resourceID := "crn:v1:bluemix:public:databases-for-postgresql:us-south:a/4ea1882a2d3401ed1e459979941966ea:2ede6105-d368-4f20-b2a3-2e27de37f0da::" 42 taggingResult, err := newTagging(server.URL()).GetTags(resourceID) 43 Expect(err).NotTo(HaveOccurred()) 44 Expect(taggingResult).ShouldNot(BeNil()) 45 //Expect(taggingResult.Items).Should(Equal("5abb6a7d11a1a5001479a0ac")) 46 47 }) 48 }) 49 Context("When PostQuery is unsuccessful", func() { 50 BeforeEach(func() { 51 server = ghttp.NewServer() 52 server.SetAllowUnhandledRequests(true) 53 server.AppendHandlers( 54 ghttp.CombineHandlers( 55 ghttp.VerifyRequest(http.MethodGet, "/v3/tags"), 56 ghttp.RespondWith(http.StatusInternalServerError, `Failed to get query results`), 57 ), 58 ) 59 }) 60 61 It("should return error during post query", func() { 62 resourceID := "crn:v1:bluemix:public:databases-for-postgresql:us-south:a/4ea1882a2d3401ed1e459979941966ea:2ede6105-d368-4f20-b2a3-2e27de37f0da::" 63 taggingResult, err := newTagging(server.URL()).GetTags(resourceID) 64 Expect(err).To(HaveOccurred()) 65 Expect(taggingResult.Items).Should(Equal("")) 66 }) 67 }) 68 }) 69 }) 70 71 func newTagging(url string) Tags { 72 73 sess, err := session.New() 74 if err != nil { 75 log.Fatal(err) 76 } 77 conf := sess.Config.Copy() 78 conf.HTTPClient = bluemixHttp.NewHTTPClient(conf) 79 conf.Endpoint = &url 80 81 client := client.Client{ 82 Config: conf, 83 ServiceName: bluemix.GlobalTaggingService, 84 } 85 return newTaggingAPI(&client) 86 }