Skip to content

Commit

Permalink
fix(Global Search/Tagging): re-gen services with latest API definition (
Browse files Browse the repository at this point in the history
#305)

Signed-off-by: Fabrizio Leoni <fabrizio_leoni@it.ibm.com>
  • Loading branch information
fabrizio-leoni committed Mar 1, 2024
1 parent d043940 commit 004b634
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 17 deletions.
19 changes: 12 additions & 7 deletions globalsearchv2/global_search_v2.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2023.
* (C) Copyright IBM Corp. 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
*/

/*
* IBM OpenAPI SDK Code Generator Version: 3.82.1-2082d402-20231115-195014
* IBM OpenAPI SDK Code Generator Version: 3.86.0-bc6f14b3-20240221-193958
*/

// Package globalsearchv2 : Operations and models for the GlobalSearchV2 service
Expand Down Expand Up @@ -178,8 +178,11 @@ func (globalSearch *GlobalSearchV2) DisableRetries() {
//
// You must use `/v3/resources/search` when you need to fetch more than `10000` resource items. 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 that are returned for every resource are "crn",
// "name", "family", "type", and "account_id". You can specify the subset of the fields you want in your request.
// results until you get the empty result set.
//
// By default, the fields that are returned for every resource are `crn`, `name`,
// `family`, `type`, and `account_id`. You can specify the subset of the fields you want in your request using the
// `fields` request body attribute. Set `"fields": ["*"]` to discover the set of fields which are available to request.
func (globalSearch *GlobalSearchV2) Search(searchOptions *SearchOptions) (result *ScanResult, response *core.DetailedResponse, err error) {
return globalSearch.SearchWithContext(context.Background(), searchOptions)
}
Expand Down Expand Up @@ -367,8 +370,9 @@ type ScanResult struct {
// Value of the limit parameter specified by the user.
Limit *int64 `json:"limit" validate:"required"`

// The array of results. Each item represents a resource. An empty array signals the end of the result set, which means
// there are no more results to fetch.
// The array of results. Each item represents a resource. For each resource, the requested `fields` are returned. If
// you did not set the `fields` request body parameter, then the `account_id`, `name`, `type`, `family`, and `crn` are
// returned. An empty array signals the end of the result set, which means there are no more results to fetch.
Items []ResultItem `json:"items" validate:"required"`
}

Expand Down Expand Up @@ -397,7 +401,8 @@ type SearchOptions struct {
Query *string `json:"query,omitempty"`

// The list of the fields returned by the search. By default, the returned fields are the `account_id`, `name`, `type`,
// `family`, and `crn`. For all queries, `crn` is always returned.
// `family`, and `crn`. For all queries, `crn` is always returned. You may set `"fields": ["*"]` to discover the set of
// fields available to request.
Fields []string `json:"fields,omitempty"`

// An opaque cursor that is returned on each call and that must be set on the subsequent call to get the next batch of
Expand Down
2 changes: 1 addition & 1 deletion globalsearchv2/global_search_v2_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2023.
* (C) Copyright IBM Corp. 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
6 changes: 3 additions & 3 deletions globalsearchv2/global_search_v2_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2023.
* (C) Copyright IBM Corp. 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -557,6 +557,7 @@ var _ = Describe(`GlobalSearchV2`, func() {
})
})
})

Describe(`Utility function tests`, func() {
It(`Invoke CreateMockByteArray() successfully`, func() {
mockByteArray := CreateMockByteArray("This is a test")
Expand Down Expand Up @@ -586,8 +587,7 @@ var _ = Describe(`GlobalSearchV2`, func() {
//

func CreateMockByteArray(mockData string) *[]byte {
ba := make([]byte, 0)
ba = append(ba, mockData...)
ba := []byte(mockData)
return &ba
}

Expand Down
17 changes: 15 additions & 2 deletions globaltaggingv1/global_tagging_v1.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2023.
* (C) Copyright IBM Corp. 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
*/

/*
* IBM OpenAPI SDK Code Generator Version: 3.82.1-2082d402-20231115-195014
* IBM OpenAPI SDK Code Generator Version: 3.86.0-bc6f14b3-20240221-193958
*/

// Package globaltaggingv1 : Operations and models for the GlobalTaggingV1 service
Expand Down Expand Up @@ -544,6 +544,9 @@ func (globalTagging *GlobalTaggingV1) AttachTagWithContext(ctx context.Context,
if attachTagOptions.TagType != nil {
builder.AddQuery("tag_type", fmt.Sprint(*attachTagOptions.TagType))
}
if attachTagOptions.Replace != nil {
builder.AddQuery("replace", fmt.Sprint(*attachTagOptions.Replace))
}

body := make(map[string]interface{})
if attachTagOptions.Resources != nil {
Expand Down Expand Up @@ -708,6 +711,10 @@ type AttachTagOptions struct {
// for IMS resources.
TagType *string `json:"tag_type,omitempty"`

// Flag to request replacement of all attached tags. Set 'true' if you want to replace all the list of tags attached to
// the resource. Default value is false.
Replace *bool `json:"replace,omitempty"`

// Allows users to set headers on API requests
Headers map[string]string
}
Expand Down Expand Up @@ -777,6 +784,12 @@ func (_options *AttachTagOptions) SetTagType(tagType string) *AttachTagOptions {
return _options
}

// SetReplace : Allow user to set Replace
func (_options *AttachTagOptions) SetReplace(replace bool) *AttachTagOptions {
_options.Replace = core.BoolPtr(replace)
return _options
}

// SetHeaders : Allow user to set Headers
func (options *AttachTagOptions) SetHeaders(param map[string]string) *AttachTagOptions {
options.Headers = param
Expand Down
2 changes: 1 addition & 1 deletion globaltaggingv1/global_tagging_v1_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2023.
* (C) Copyright IBM Corp. 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
38 changes: 35 additions & 3 deletions globaltaggingv1/global_tagging_v1_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2023.
* (C) Copyright IBM Corp. 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@ package globaltaggingv1_test
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -1307,6 +1308,7 @@ var _ = Describe(`GlobalTaggingV1`, func() {
Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString")))
Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["tag_type"]).To(Equal([]string{"user"}))
// TODO: Add check for replace query parameter
res.Header().Set("Content-type", "application/json")
res.WriteHeader(200)
fmt.Fprint(res, `} this is not valid json {`)
Expand Down Expand Up @@ -1335,6 +1337,7 @@ var _ = Describe(`GlobalTaggingV1`, func() {
attachTagOptionsModel.TransactionID = core.StringPtr("testString")
attachTagOptionsModel.AccountID = core.StringPtr("testString")
attachTagOptionsModel.TagType = core.StringPtr("user")
attachTagOptionsModel.Replace = core.BoolPtr(false)
attachTagOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}
// Expect response parsing to fail since we are receiving a text/plain response
result, response, operationErr := globalTaggingService.AttachTag(attachTagOptionsModel)
Expand Down Expand Up @@ -1389,6 +1392,7 @@ var _ = Describe(`GlobalTaggingV1`, func() {
Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString")))
Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["tag_type"]).To(Equal([]string{"user"}))
// TODO: Add check for replace query parameter
// Sleep a short time to support a timeout test
time.Sleep(100 * time.Millisecond)

Expand Down Expand Up @@ -1422,6 +1426,7 @@ var _ = Describe(`GlobalTaggingV1`, func() {
attachTagOptionsModel.TransactionID = core.StringPtr("testString")
attachTagOptionsModel.AccountID = core.StringPtr("testString")
attachTagOptionsModel.TagType = core.StringPtr("user")
attachTagOptionsModel.Replace = core.BoolPtr(false)
attachTagOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}

// Invoke operation with a Context to test a timeout error
Expand Down Expand Up @@ -1482,6 +1487,7 @@ var _ = Describe(`GlobalTaggingV1`, func() {
Expect(req.Header["Transaction-Id"][0]).To(Equal(fmt.Sprintf("%v", "testString")))
Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["tag_type"]).To(Equal([]string{"user"}))
// TODO: Add check for replace query parameter
// Set mock response
res.Header().Set("Content-type", "application/json")
res.WriteHeader(200)
Expand Down Expand Up @@ -1517,6 +1523,7 @@ var _ = Describe(`GlobalTaggingV1`, func() {
attachTagOptionsModel.TransactionID = core.StringPtr("testString")
attachTagOptionsModel.AccountID = core.StringPtr("testString")
attachTagOptionsModel.TagType = core.StringPtr("user")
attachTagOptionsModel.Replace = core.BoolPtr(false)
attachTagOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}

// Invoke operation with valid options model (positive test)
Expand Down Expand Up @@ -1549,6 +1556,7 @@ var _ = Describe(`GlobalTaggingV1`, func() {
attachTagOptionsModel.TransactionID = core.StringPtr("testString")
attachTagOptionsModel.AccountID = core.StringPtr("testString")
attachTagOptionsModel.TagType = core.StringPtr("user")
attachTagOptionsModel.Replace = core.BoolPtr(false)
attachTagOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}
// Invoke operation with empty URL (negative test)
err := globalTaggingService.SetServiceURL("")
Expand Down Expand Up @@ -1602,6 +1610,7 @@ var _ = Describe(`GlobalTaggingV1`, func() {
attachTagOptionsModel.TransactionID = core.StringPtr("testString")
attachTagOptionsModel.AccountID = core.StringPtr("testString")
attachTagOptionsModel.TagType = core.StringPtr("user")
attachTagOptionsModel.Replace = core.BoolPtr(false)
attachTagOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}

// Invoke operation
Expand Down Expand Up @@ -1971,6 +1980,7 @@ var _ = Describe(`GlobalTaggingV1`, func() {
attachTagOptionsModel.SetTransactionID("testString")
attachTagOptionsModel.SetAccountID("testString")
attachTagOptionsModel.SetTagType("user")
attachTagOptionsModel.SetReplace(false)
attachTagOptionsModel.SetHeaders(map[string]string{"foo": "bar"})
Expect(attachTagOptionsModel).ToNot(BeNil())
Expect(attachTagOptionsModel.Resources).To(Equal([]globaltaggingv1.Resource{*resourceModel}))
Expand All @@ -1981,6 +1991,7 @@ var _ = Describe(`GlobalTaggingV1`, func() {
Expect(attachTagOptionsModel.TransactionID).To(Equal(core.StringPtr("testString")))
Expect(attachTagOptionsModel.AccountID).To(Equal(core.StringPtr("testString")))
Expect(attachTagOptionsModel.TagType).To(Equal(core.StringPtr("user")))
Expect(attachTagOptionsModel.Replace).To(Equal(core.BoolPtr(false)))
Expect(attachTagOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"}))
})
It(`Invoke NewCreateTagOptions successfully`, func() {
Expand Down Expand Up @@ -2117,6 +2128,28 @@ var _ = Describe(`GlobalTaggingV1`, func() {
})
})
})
Describe(`Model unmarshaling tests`, func() {
It(`Invoke UnmarshalResource successfully`, func() {
// Construct an instance of the model.
model := new(globaltaggingv1.Resource)
model.ResourceID = core.StringPtr("testString")
model.ResourceType = core.StringPtr("testString")

b, err := json.Marshal(model)
Expect(err).To(BeNil())

var raw map[string]json.RawMessage
err = json.Unmarshal(b, &raw)
Expect(err).To(BeNil())

var result *globaltaggingv1.Resource
err = globaltaggingv1.UnmarshalResource(raw, &result)
Expect(err).To(BeNil())
Expect(result).ToNot(BeNil())
Expect(result).To(Equal(model))
})
})

Describe(`Utility function tests`, func() {
It(`Invoke CreateMockByteArray() successfully`, func() {
mockByteArray := CreateMockByteArray("This is a test")
Expand Down Expand Up @@ -2146,8 +2179,7 @@ var _ = Describe(`GlobalTaggingV1`, func() {
//

func CreateMockByteArray(mockData string) *[]byte {
ba := make([]byte, 0)
ba = append(ba, mockData...)
ba := []byte(mockData)
return &ba
}

Expand Down

0 comments on commit 004b634

Please sign in to comment.