Skip to content

Commit

Permalink
fix(Global Search): re-gen service and add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
padamstx committed Dec 10, 2020
1 parent e37563e commit 0aa0e9b
Show file tree
Hide file tree
Showing 4 changed files with 319 additions and 137 deletions.
31 changes: 23 additions & 8 deletions globalsearchv2/global_search_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

/*
* IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-8d569e8f-20201030-111043
* IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-d753183b-20201209-163011
*/


Expand Down Expand Up @@ -115,6 +115,21 @@ func NewGlobalSearchV2(options *GlobalSearchV2Options) (service *GlobalSearchV2,
return
}

// GetServiceURLForRegion returns the service URL to be used for the specified region
func GetServiceURLForRegion(region string) (string, error) {
return "", fmt.Errorf("service does not support regional URLs")
}

// Clone makes a copy of "globalSearch" suitable for processing requests.
func (globalSearch *GlobalSearchV2) Clone() *GlobalSearchV2 {
if core.IsNil(globalSearch) {
return nil
}
clone := *globalSearch
clone.Service = globalSearch.Service.Clone()
return &clone
}

// SetServiceURL sets the service URL
func (globalSearch *GlobalSearchV2) SetServiceURL(url string) error {
return globalSearch.Service.SetServiceURL(url)
Expand Down Expand Up @@ -152,7 +167,7 @@ func (globalSearch *GlobalSearchV2) DisableRetries() {
}

// Search : Find instances of resources
// 'Find cloud foundry resources, resource controlled enabled resources, or storage and network resources running on
// Find cloud foundry resources, resource controller-enabled resources, or storage and network resources running on
// classic infrastructure in a specific account ID. You can apply query strings if necessary. To filter results, you can
// insert a string using the Lucene syntax and the query string is parsed into a series of terms and operators. A term
// can be a single word or a phrase, in which case the search is performed for all the words, in the same order. To
Expand All @@ -162,7 +177,7 @@ func (globalSearch *GlobalSearchV2) DisableRetries() {
// through such a big number. On the first call, the operation returns a live cursor on the data that you must use on
// all the subsequent calls to get the next batch of results until you get the empty result set. By default, the fields
// returned for every resources are: "crn", "name", "family", "type", "account_id". You can specify the subset of the
// fields you want in your request.''.
// fields you want in your request.
func (globalSearch *GlobalSearchV2) Search(searchOptions *SearchOptions) (result *ScanResult, response *core.DetailedResponse, err error) {
return globalSearch.SearchWithContext(context.Background(), searchOptions)
}
Expand Down Expand Up @@ -318,7 +333,7 @@ func (options *GetSupportedTypesOptions) SetHeaders(param map[string]string) *Ge
// ResultItem : A resource returned in a search result.
type ResultItem struct {
// Resource identifier in CRN format.
Crn *string `json:"crn,omitempty"`
CRN *string `json:"crn,omitempty"`

// Allows users to set arbitrary properties
additionalProperties map[string]interface{}
Expand Down Expand Up @@ -351,8 +366,8 @@ func (o *ResultItem) MarshalJSON() (buffer []byte, err error) {
m[k] = v
}
}
if o.Crn != nil {
m["crn"] = o.Crn
if o.CRN != nil {
m["crn"] = o.CRN
}
buffer, err = json.Marshal(m)
return
Expand All @@ -361,7 +376,7 @@ func (o *ResultItem) MarshalJSON() (buffer []byte, err error) {
// UnmarshalResultItem unmarshals an instance of ResultItem from the specified map of raw messages.
func UnmarshalResultItem(m map[string]json.RawMessage, result interface{}) (err error) {
obj := new(ResultItem)
err = core.UnmarshalPrimitive(m, "crn", &obj.Crn)
err = core.UnmarshalPrimitive(m, "crn", &obj.CRN)
if err != nil {
return
}
Expand All @@ -385,7 +400,7 @@ type ScanResult struct {
SearchCursor *string `json:"search_cursor" validate:"required"`

// Value of the limit parameter specified by the user.
Limit *float64 `json:"limit,omitempty"`
Limit *int64 `json:"limit,omitempty"`

// The array of results. Each item represents a resource. An empty array signals the end of the result set, there are
// no more hits to fetch.
Expand Down
142 changes: 142 additions & 0 deletions globalsearchv2/global_search_v2_examples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// +build examples

/**
* (C) Copyright IBM Corp. 2020.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package globalsearchv2_test

import (
"encoding/json"
"fmt"
"os"

"github.com/IBM/go-sdk-core/v4/core"
"github.com/IBM/platform-services-go-sdk/globalsearchv2"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

// This file provides an example of how to use the Global Search service.
//
// The following configuration properties are assumed to be defined in the external configuration file:
// GLOBAL_SEARCH_URL=<service url>
// GLOBAL_SEARCH_AUTHTYPE=iam
// GLOBAL_SEARCH_APIKEY=<IAM api key>
// GLOBAL_SEARCH_AUTH_URL=<IAM token service URL - omit this if using the production environment>

const externalConfigFile = "../global_search.env"

var (
globalSearchService *globalsearchv2.GlobalSearchV2
config map[string]string
configLoaded bool = false
)

func shouldSkipTest() {
if !configLoaded {
Skip("External configuration is not available, skipping tests...")
}
}

var _ = Describe(`GlobalSearchV2 Examples Tests`, func() {
Describe(`External configuration`, func() {
It("Successfully load the configuration", func() {
var err error
_, err = os.Stat(externalConfigFile)
if err != nil {
Skip("External configuration file not found, skipping tests: " + err.Error())
}

os.Setenv("IBM_CREDENTIALS_FILE", externalConfigFile)
config, err = core.GetServiceProperties(globalsearchv2.DefaultServiceName)
if err != nil {
Skip("Error loading service properties, skipping tests: " + err.Error())
}

configLoaded = len(config) > 0
})
})

Describe(`Client initialization`, func() {
BeforeEach(func() {
shouldSkipTest()
})
It("Successfully construct the service client instance", func() {
var err error

// begin-common

globalSearchServiceOptions := &globalsearchv2.GlobalSearchV2Options{}

globalSearchService, err = globalsearchv2.NewGlobalSearchV2UsingExternalConfig(globalSearchServiceOptions)

if err != nil {
panic(err)
}

// end-common

Expect(globalSearchService).ToNot(BeNil())
})
})

Describe(`GlobalSearchV2 request examples`, func() {
BeforeEach(func() {
shouldSkipTest()
})
It(`Search request example`, func() {
// begin-search

searchOptions := globalSearchService.NewSearchOptions()
searchOptions.SetLimit(10)
searchOptions.SetQuery("GST-sdk-*")
searchOptions.SetFields([]string{"*"})

scanResult, response, err := globalSearchService.Search(searchOptions)
if err != nil {
panic(err)
}
b, _ := json.MarshalIndent(scanResult, "", " ")
fmt.Println(string(b))

// end-search

Expect(err).To(BeNil())
Expect(response.StatusCode).To(Equal(200))
Expect(scanResult).ToNot(BeNil())

})
It(`GetSupportedTypes request example`, func() {
// begin-get_supported_types

getSupportedTypesOptions := globalSearchService.NewGetSupportedTypesOptions()

supportedTypesList, response, err := globalSearchService.GetSupportedTypes(getSupportedTypesOptions)
if err != nil {
panic(err)
}
b, _ := json.MarshalIndent(supportedTypesList, "", " ")
fmt.Println(string(b))

// end-get_supported_types

Expect(err).To(BeNil())
Expect(response.StatusCode).To(Equal(200))
Expect(supportedTypesList).ToNot(BeNil())

})
})
})
Loading

0 comments on commit 0aa0e9b

Please sign in to comment.