From 1b7cff84720599ba5ed06380fb96b73cd0f23037 Mon Sep 17 00:00:00 2001 From: ADYA NAND JHA Date: Tue, 3 Oct 2023 19:56:05 +0530 Subject: [PATCH] feat(ATracker V1): remove deprecated atrackerv1 service from project (#282) Signed-off-by: ADYA NAND JHA --- README.md | 1 - atrackerv1/atracker_v1.go | 1870 ----------- atrackerv1/atracker_v1_examples_test.go | 427 --- atrackerv1/atracker_v1_integration_test.go | 785 ----- atrackerv1/atracker_v1_suite_test.go | 29 - atrackerv1/atracker_v1_test.go | 3447 -------------------- 6 files changed, 6559 deletions(-) delete mode 100644 atrackerv1/atracker_v1.go delete mode 100644 atrackerv1/atracker_v1_examples_test.go delete mode 100644 atrackerv1/atracker_v1_integration_test.go delete mode 100644 atrackerv1/atracker_v1_suite_test.go delete mode 100644 atrackerv1/atracker_v1_test.go diff --git a/README.md b/README.md index 2e15548c..4bebabbe 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,6 @@ The IBM Cloud Platform Services Go SDK allows developers to programmatically int Service Name | Package name --- | --- [Activity Tracker](https://cloud.ibm.com/apidocs/atracker/atracker-v2) | atrackerv2 -[Activity Tracker v1 [deprecated]](https://cloud.ibm.com/apidocs/atracker/atracker-v1) | atrackerv1 [Case Management](https://cloud.ibm.com/apidocs/case-management?code=go) | casemanagementv1 [Catalog Management](https://cloud.ibm.com/apidocs/resource-catalog/private-catalog?code=go) | catalogmanagementv1 [Context Based Restrictions](https://cloud.ibm.com/apidocs/context-based-restrictions?code=go) | contextbasedrestrictionsv1 diff --git a/atrackerv1/atracker_v1.go b/atrackerv1/atracker_v1.go deleted file mode 100644 index 398645d1..00000000 --- a/atrackerv1/atracker_v1.go +++ /dev/null @@ -1,1870 +0,0 @@ -/** - * (C) Copyright IBM Corp. 2021. - * - * 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. - */ - -/* - * IBM OpenAPI SDK Code Generator Version: 3.57.1-4c556507-20220928-143422 - */ - -// Package atrackerv1 : Operations and models for the AtrackerV1 service -package atrackerv1 - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "reflect" - "time" - - "github.com/IBM/go-sdk-core/v5/core" - common "github.com/IBM/platform-services-go-sdk/common" - "github.com/go-openapi/strfmt" -) - -// AtrackerV1 : IBM Cloud Activity Tracker Event Routing allows you to configure how auditing events are collected and -// stored in each region in your account. Events are stored in a Cloud Object Storage bucket that is also available in -// the account. -// -// API Version: 1.1.0 -type AtrackerV1 struct { - Service *core.BaseService -} - -// DefaultServiceURL is the default URL to make service requests to. -const DefaultServiceURL = "https://us-south.atracker.cloud.ibm.com" - -// DefaultServiceName is the default key used to find external configuration information. -const DefaultServiceName = "atracker" - -// AtrackerV1Options : Service options -type AtrackerV1Options struct { - ServiceName string - URL string - Authenticator core.Authenticator -} - -// NewAtrackerV1UsingExternalConfig : constructs an instance of AtrackerV1 with passed in options and external configuration. -func NewAtrackerV1UsingExternalConfig(options *AtrackerV1Options) (atracker *AtrackerV1, err error) { - if options.ServiceName == "" { - options.ServiceName = DefaultServiceName - } - - if options.Authenticator == nil { - options.Authenticator, err = core.GetAuthenticatorFromEnvironment(options.ServiceName) - if err != nil { - return - } - } - - atracker, err = NewAtrackerV1(options) - if err != nil { - return - } - - err = atracker.Service.ConfigureService(options.ServiceName) - if err != nil { - return - } - - if options.URL != "" { - err = atracker.Service.SetServiceURL(options.URL) - } - return -} - -// NewAtrackerV1 : constructs an instance of AtrackerV1 with passed in options. -func NewAtrackerV1(options *AtrackerV1Options) (service *AtrackerV1, err error) { - serviceOptions := &core.ServiceOptions{ - URL: DefaultServiceURL, - Authenticator: options.Authenticator, - } - - baseService, err := core.NewBaseService(serviceOptions) - if err != nil { - return - } - - if options.URL != "" { - err = baseService.SetServiceURL(options.URL) - if err != nil { - return - } - } - - service = &AtrackerV1{ - Service: baseService, - } - - return -} - -// GetServiceURLForRegion returns the service URL to be used for the specified region -func GetServiceURLForRegion(region string) (string, error) { - var endpoints = map[string]string{ - "us-south": "https://us-south.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the us-south region. - "private.us-south": "https://private.us-south.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the us-south region. - "us-east": "https://us-east.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the us-east region. - "private.us-east": "https://private.us-east.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the us-east region. - "eu-de": "https://eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the eu-de region. - "private.eu-de": "https://private.eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the eu-de region. - "eu-gb": "https://eu-gb.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the eu-gb region. - "private.eu-gb": "https://private.eu-gb.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the eu-gb region. - "au-syd": "https://au-syd.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the au-syd region. - "private.au-syd": "https://private.au-syd.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the au-syd region. - "ca-tor": "https://us-east.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for ca-tor points to the us-east region. - "private.ca-tor": "https://private.us-east.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for ca-tor points to the us-east region. - "br-sao": "https://us-south.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for br-sao points to the us-south region. - "private.br-sao": "https://private.us-south.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for br-sao points to the us-south region. - "eu-fr2": "https://eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for eu-fr2 points to the eu-de region. - "private.eu-fr2": "https://private.eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for eu-fr2 points to the eu-de region. - "jp-tok": "https://eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for jp-tok points to the eu-de region. - "private.jp-tok": "https://private.eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for jp-tok points to the eu-de region. - "jp-osa": "https://eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for jp-osa points to the eu-de region. - "private.jp-osa": "https://private.eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for jp-osa points to the eu-de region. - "in-che": "https://eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for in-che points to the eu-de region. - "private.in-che": "https://private.eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for in-che points to the eu-de region. - } - - if url, ok := endpoints[region]; ok { - return url, nil - } - return "", fmt.Errorf("service URL for region '%s' not found", region) -} - -// Clone makes a copy of "atracker" suitable for processing requests. -func (atracker *AtrackerV1) Clone() *AtrackerV1 { - if core.IsNil(atracker) { - return nil - } - clone := *atracker - clone.Service = atracker.Service.Clone() - return &clone -} - -// SetServiceURL sets the service URL -func (atracker *AtrackerV1) SetServiceURL(url string) error { - return atracker.Service.SetServiceURL(url) -} - -// GetServiceURL returns the service URL -func (atracker *AtrackerV1) GetServiceURL() string { - return atracker.Service.GetServiceURL() -} - -// SetDefaultHeaders sets HTTP headers to be sent in every request -func (atracker *AtrackerV1) SetDefaultHeaders(headers http.Header) { - atracker.Service.SetDefaultHeaders(headers) -} - -// SetEnableGzipCompression sets the service's EnableGzipCompression field -func (atracker *AtrackerV1) SetEnableGzipCompression(enableGzip bool) { - atracker.Service.SetEnableGzipCompression(enableGzip) -} - -// GetEnableGzipCompression returns the service's EnableGzipCompression field -func (atracker *AtrackerV1) GetEnableGzipCompression() bool { - return atracker.Service.GetEnableGzipCompression() -} - -// EnableRetries enables automatic retries for requests invoked for this service instance. -// If either parameter is specified as 0, then a default value is used instead. -func (atracker *AtrackerV1) EnableRetries(maxRetries int, maxRetryInterval time.Duration) { - atracker.Service.EnableRetries(maxRetries, maxRetryInterval) -} - -// DisableRetries disables automatic retries for requests invoked for this service instance. -func (atracker *AtrackerV1) DisableRetries() { - atracker.Service.DisableRetries() -} - -// CreateTarget : Create a target -// Creates a Cloud Object Storage (COS) target that includes information about the COS endpoint and the credentials to -// access the bucket. You must define a COS target per region. Notice that although you can use the same COS bucket for -// collecting auditing events in your account across multiple regions, you should consider defining a bucket in each -// region to reduce performance and network latency issues. You can define up to 16 targets per region. -func (atracker *AtrackerV1) CreateTarget(createTargetOptions *CreateTargetOptions) (result *Target, response *core.DetailedResponse, err error) { - return atracker.CreateTargetWithContext(context.Background(), createTargetOptions) -} - -// CreateTargetWithContext is an alternate form of the CreateTarget method which supports a Context parameter -func (atracker *AtrackerV1) CreateTargetWithContext(ctx context.Context, createTargetOptions *CreateTargetOptions) (result *Target, response *core.DetailedResponse, err error) { - err = core.ValidateNotNil(createTargetOptions, "createTargetOptions cannot be nil") - if err != nil { - return - } - err = core.ValidateStruct(createTargetOptions, "createTargetOptions") - if err != nil { - return - } - - builder := core.NewRequestBuilder(core.POST) - builder = builder.WithContext(ctx) - builder.EnableGzipCompression = atracker.GetEnableGzipCompression() - _, err = builder.ResolveRequestURL(atracker.Service.Options.URL, `/api/v1/targets`, nil) - if err != nil { - return - } - - for headerName, headerValue := range createTargetOptions.Headers { - builder.AddHeader(headerName, headerValue) - } - - sdkHeaders := common.GetSdkHeaders("atracker", "V1", "CreateTarget") - for headerName, headerValue := range sdkHeaders { - builder.AddHeader(headerName, headerValue) - } - builder.AddHeader("Accept", "application/json") - builder.AddHeader("Content-Type", "application/json") - - body := make(map[string]interface{}) - if createTargetOptions.Name != nil { - body["name"] = createTargetOptions.Name - } - if createTargetOptions.TargetType != nil { - body["target_type"] = createTargetOptions.TargetType - } - if createTargetOptions.CosEndpoint != nil { - body["cos_endpoint"] = createTargetOptions.CosEndpoint - } - _, err = builder.SetBodyContentJSON(body) - if err != nil { - return - } - - request, err := builder.Build() - if err != nil { - return - } - - var rawResponse map[string]json.RawMessage - response, err = atracker.Service.Request(request, &rawResponse) - if err != nil { - return - } - if rawResponse != nil { - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalTarget) - if err != nil { - return - } - response.Result = result - } - - return -} - -// ListTargets : List targets -// List all Cloud Object Storage (COS) targets that are defined in a region. -func (atracker *AtrackerV1) ListTargets(listTargetsOptions *ListTargetsOptions) (result *TargetList, response *core.DetailedResponse, err error) { - return atracker.ListTargetsWithContext(context.Background(), listTargetsOptions) -} - -// ListTargetsWithContext is an alternate form of the ListTargets method which supports a Context parameter -func (atracker *AtrackerV1) ListTargetsWithContext(ctx context.Context, listTargetsOptions *ListTargetsOptions) (result *TargetList, response *core.DetailedResponse, err error) { - err = core.ValidateStruct(listTargetsOptions, "listTargetsOptions") - if err != nil { - return - } - - builder := core.NewRequestBuilder(core.GET) - builder = builder.WithContext(ctx) - builder.EnableGzipCompression = atracker.GetEnableGzipCompression() - _, err = builder.ResolveRequestURL(atracker.Service.Options.URL, `/api/v1/targets`, nil) - if err != nil { - return - } - - for headerName, headerValue := range listTargetsOptions.Headers { - builder.AddHeader(headerName, headerValue) - } - - sdkHeaders := common.GetSdkHeaders("atracker", "V1", "ListTargets") - for headerName, headerValue := range sdkHeaders { - builder.AddHeader(headerName, headerValue) - } - builder.AddHeader("Accept", "application/json") - - request, err := builder.Build() - if err != nil { - return - } - - var rawResponse map[string]json.RawMessage - response, err = atracker.Service.Request(request, &rawResponse) - if err != nil { - return - } - if rawResponse != nil { - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalTargetList) - if err != nil { - return - } - response.Result = result - } - - return -} - -// GetTarget : Get details of a target -// Retrieve the configuration details of a target. -func (atracker *AtrackerV1) GetTarget(getTargetOptions *GetTargetOptions) (result *Target, response *core.DetailedResponse, err error) { - return atracker.GetTargetWithContext(context.Background(), getTargetOptions) -} - -// GetTargetWithContext is an alternate form of the GetTarget method which supports a Context parameter -func (atracker *AtrackerV1) GetTargetWithContext(ctx context.Context, getTargetOptions *GetTargetOptions) (result *Target, response *core.DetailedResponse, err error) { - err = core.ValidateNotNil(getTargetOptions, "getTargetOptions cannot be nil") - if err != nil { - return - } - err = core.ValidateStruct(getTargetOptions, "getTargetOptions") - if err != nil { - return - } - - pathParamsMap := map[string]string{ - "id": *getTargetOptions.ID, - } - - builder := core.NewRequestBuilder(core.GET) - builder = builder.WithContext(ctx) - builder.EnableGzipCompression = atracker.GetEnableGzipCompression() - _, err = builder.ResolveRequestURL(atracker.Service.Options.URL, `/api/v1/targets/{id}`, pathParamsMap) - if err != nil { - return - } - - for headerName, headerValue := range getTargetOptions.Headers { - builder.AddHeader(headerName, headerValue) - } - - sdkHeaders := common.GetSdkHeaders("atracker", "V1", "GetTarget") - for headerName, headerValue := range sdkHeaders { - builder.AddHeader(headerName, headerValue) - } - builder.AddHeader("Accept", "application/json") - - request, err := builder.Build() - if err != nil { - return - } - - var rawResponse map[string]json.RawMessage - response, err = atracker.Service.Request(request, &rawResponse) - if err != nil { - return - } - if rawResponse != nil { - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalTarget) - if err != nil { - return - } - response.Result = result - } - - return -} - -// ReplaceTarget : Update a target -// Update the configuration details of a target. -func (atracker *AtrackerV1) ReplaceTarget(replaceTargetOptions *ReplaceTargetOptions) (result *Target, response *core.DetailedResponse, err error) { - return atracker.ReplaceTargetWithContext(context.Background(), replaceTargetOptions) -} - -// ReplaceTargetWithContext is an alternate form of the ReplaceTarget method which supports a Context parameter -func (atracker *AtrackerV1) ReplaceTargetWithContext(ctx context.Context, replaceTargetOptions *ReplaceTargetOptions) (result *Target, response *core.DetailedResponse, err error) { - err = core.ValidateNotNil(replaceTargetOptions, "replaceTargetOptions cannot be nil") - if err != nil { - return - } - err = core.ValidateStruct(replaceTargetOptions, "replaceTargetOptions") - if err != nil { - return - } - - pathParamsMap := map[string]string{ - "id": *replaceTargetOptions.ID, - } - - builder := core.NewRequestBuilder(core.PUT) - builder = builder.WithContext(ctx) - builder.EnableGzipCompression = atracker.GetEnableGzipCompression() - _, err = builder.ResolveRequestURL(atracker.Service.Options.URL, `/api/v1/targets/{id}`, pathParamsMap) - if err != nil { - return - } - - for headerName, headerValue := range replaceTargetOptions.Headers { - builder.AddHeader(headerName, headerValue) - } - - sdkHeaders := common.GetSdkHeaders("atracker", "V1", "ReplaceTarget") - for headerName, headerValue := range sdkHeaders { - builder.AddHeader(headerName, headerValue) - } - builder.AddHeader("Accept", "application/json") - builder.AddHeader("Content-Type", "application/json") - - body := make(map[string]interface{}) - if replaceTargetOptions.Name != nil { - body["name"] = replaceTargetOptions.Name - } - if replaceTargetOptions.TargetType != nil { - body["target_type"] = replaceTargetOptions.TargetType - } - if replaceTargetOptions.CosEndpoint != nil { - body["cos_endpoint"] = replaceTargetOptions.CosEndpoint - } - _, err = builder.SetBodyContentJSON(body) - if err != nil { - return - } - - request, err := builder.Build() - if err != nil { - return - } - - var rawResponse map[string]json.RawMessage - response, err = atracker.Service.Request(request, &rawResponse) - if err != nil { - return - } - if rawResponse != nil { - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalTarget) - if err != nil { - return - } - response.Result = result - } - - return -} - -// DeleteTarget : Delete a target -// Delete a target. -func (atracker *AtrackerV1) DeleteTarget(deleteTargetOptions *DeleteTargetOptions) (result *WarningReport, response *core.DetailedResponse, err error) { - return atracker.DeleteTargetWithContext(context.Background(), deleteTargetOptions) -} - -// DeleteTargetWithContext is an alternate form of the DeleteTarget method which supports a Context parameter -func (atracker *AtrackerV1) DeleteTargetWithContext(ctx context.Context, deleteTargetOptions *DeleteTargetOptions) (result *WarningReport, response *core.DetailedResponse, err error) { - err = core.ValidateNotNil(deleteTargetOptions, "deleteTargetOptions cannot be nil") - if err != nil { - return - } - err = core.ValidateStruct(deleteTargetOptions, "deleteTargetOptions") - if err != nil { - return - } - - pathParamsMap := map[string]string{ - "id": *deleteTargetOptions.ID, - } - - builder := core.NewRequestBuilder(core.DELETE) - builder = builder.WithContext(ctx) - builder.EnableGzipCompression = atracker.GetEnableGzipCompression() - _, err = builder.ResolveRequestURL(atracker.Service.Options.URL, `/api/v1/targets/{id}`, pathParamsMap) - if err != nil { - return - } - - for headerName, headerValue := range deleteTargetOptions.Headers { - builder.AddHeader(headerName, headerValue) - } - - sdkHeaders := common.GetSdkHeaders("atracker", "V1", "DeleteTarget") - for headerName, headerValue := range sdkHeaders { - builder.AddHeader(headerName, headerValue) - } - builder.AddHeader("Accept", "application/json") - - request, err := builder.Build() - if err != nil { - return - } - - var rawResponse map[string]json.RawMessage - response, err = atracker.Service.Request(request, &rawResponse) - if err != nil { - return - } - if rawResponse != nil { - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalWarningReport) - if err != nil { - return - } - response.Result = result - } - - return -} - -// ValidateTarget : Validate a target -// Validate a target by checking the credentials to write to the bucket. The result is included as additional data of -// the target in the section "cos_write_status". -func (atracker *AtrackerV1) ValidateTarget(validateTargetOptions *ValidateTargetOptions) (result *Target, response *core.DetailedResponse, err error) { - return atracker.ValidateTargetWithContext(context.Background(), validateTargetOptions) -} - -// ValidateTargetWithContext is an alternate form of the ValidateTarget method which supports a Context parameter -func (atracker *AtrackerV1) ValidateTargetWithContext(ctx context.Context, validateTargetOptions *ValidateTargetOptions) (result *Target, response *core.DetailedResponse, err error) { - err = core.ValidateNotNil(validateTargetOptions, "validateTargetOptions cannot be nil") - if err != nil { - return - } - err = core.ValidateStruct(validateTargetOptions, "validateTargetOptions") - if err != nil { - return - } - - pathParamsMap := map[string]string{ - "id": *validateTargetOptions.ID, - } - - builder := core.NewRequestBuilder(core.POST) - builder = builder.WithContext(ctx) - builder.EnableGzipCompression = atracker.GetEnableGzipCompression() - _, err = builder.ResolveRequestURL(atracker.Service.Options.URL, `/api/v1/targets/{id}/validate`, pathParamsMap) - if err != nil { - return - } - - for headerName, headerValue := range validateTargetOptions.Headers { - builder.AddHeader(headerName, headerValue) - } - - sdkHeaders := common.GetSdkHeaders("atracker", "V1", "ValidateTarget") - for headerName, headerValue := range sdkHeaders { - builder.AddHeader(headerName, headerValue) - } - builder.AddHeader("Accept", "application/json") - - request, err := builder.Build() - if err != nil { - return - } - - var rawResponse map[string]json.RawMessage - response, err = atracker.Service.Request(request, &rawResponse) - if err != nil { - return - } - if rawResponse != nil { - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalTarget) - if err != nil { - return - } - response.Result = result - } - - return -} - -// CreateRoute : Create a route -// Create a route to define the rule that specifies how to manage auditing events in a region. You can define 1 route -// only per region. You can configure 1 target only per route. To define how to manage global events, that is, auditing -// events in your account that are not region specific, you must configure 1 route in your account to collect and route -// global events. You must set the receive_global_events field to true. -func (atracker *AtrackerV1) CreateRoute(createRouteOptions *CreateRouteOptions) (result *Route, response *core.DetailedResponse, err error) { - return atracker.CreateRouteWithContext(context.Background(), createRouteOptions) -} - -// CreateRouteWithContext is an alternate form of the CreateRoute method which supports a Context parameter -func (atracker *AtrackerV1) CreateRouteWithContext(ctx context.Context, createRouteOptions *CreateRouteOptions) (result *Route, response *core.DetailedResponse, err error) { - err = core.ValidateNotNil(createRouteOptions, "createRouteOptions cannot be nil") - if err != nil { - return - } - err = core.ValidateStruct(createRouteOptions, "createRouteOptions") - if err != nil { - return - } - - builder := core.NewRequestBuilder(core.POST) - builder = builder.WithContext(ctx) - builder.EnableGzipCompression = atracker.GetEnableGzipCompression() - _, err = builder.ResolveRequestURL(atracker.Service.Options.URL, `/api/v1/routes`, nil) - if err != nil { - return - } - - for headerName, headerValue := range createRouteOptions.Headers { - builder.AddHeader(headerName, headerValue) - } - - sdkHeaders := common.GetSdkHeaders("atracker", "V1", "CreateRoute") - for headerName, headerValue := range sdkHeaders { - builder.AddHeader(headerName, headerValue) - } - builder.AddHeader("Accept", "application/json") - builder.AddHeader("Content-Type", "application/json") - - body := make(map[string]interface{}) - if createRouteOptions.Name != nil { - body["name"] = createRouteOptions.Name - } - if createRouteOptions.ReceiveGlobalEvents != nil { - body["receive_global_events"] = createRouteOptions.ReceiveGlobalEvents - } - if createRouteOptions.Rules != nil { - body["rules"] = createRouteOptions.Rules - } - _, err = builder.SetBodyContentJSON(body) - if err != nil { - return - } - - request, err := builder.Build() - if err != nil { - return - } - - var rawResponse map[string]json.RawMessage - response, err = atracker.Service.Request(request, &rawResponse) - if err != nil { - return - } - if rawResponse != nil { - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalRoute) - if err != nil { - return - } - response.Result = result - } - - return -} - -// ListRoutes : List routes -// List the route that is configured in a region. -func (atracker *AtrackerV1) ListRoutes(listRoutesOptions *ListRoutesOptions) (result *RouteList, response *core.DetailedResponse, err error) { - return atracker.ListRoutesWithContext(context.Background(), listRoutesOptions) -} - -// ListRoutesWithContext is an alternate form of the ListRoutes method which supports a Context parameter -func (atracker *AtrackerV1) ListRoutesWithContext(ctx context.Context, listRoutesOptions *ListRoutesOptions) (result *RouteList, response *core.DetailedResponse, err error) { - err = core.ValidateStruct(listRoutesOptions, "listRoutesOptions") - if err != nil { - return - } - - builder := core.NewRequestBuilder(core.GET) - builder = builder.WithContext(ctx) - builder.EnableGzipCompression = atracker.GetEnableGzipCompression() - _, err = builder.ResolveRequestURL(atracker.Service.Options.URL, `/api/v1/routes`, nil) - if err != nil { - return - } - - for headerName, headerValue := range listRoutesOptions.Headers { - builder.AddHeader(headerName, headerValue) - } - - sdkHeaders := common.GetSdkHeaders("atracker", "V1", "ListRoutes") - for headerName, headerValue := range sdkHeaders { - builder.AddHeader(headerName, headerValue) - } - builder.AddHeader("Accept", "application/json") - - request, err := builder.Build() - if err != nil { - return - } - - var rawResponse map[string]json.RawMessage - response, err = atracker.Service.Request(request, &rawResponse) - if err != nil { - return - } - if rawResponse != nil { - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalRouteList) - if err != nil { - return - } - response.Result = result - } - - return -} - -// GetRoute : Get details of a route -// Get the configuration details of a route. -func (atracker *AtrackerV1) GetRoute(getRouteOptions *GetRouteOptions) (result *Route, response *core.DetailedResponse, err error) { - return atracker.GetRouteWithContext(context.Background(), getRouteOptions) -} - -// GetRouteWithContext is an alternate form of the GetRoute method which supports a Context parameter -func (atracker *AtrackerV1) GetRouteWithContext(ctx context.Context, getRouteOptions *GetRouteOptions) (result *Route, response *core.DetailedResponse, err error) { - err = core.ValidateNotNil(getRouteOptions, "getRouteOptions cannot be nil") - if err != nil { - return - } - err = core.ValidateStruct(getRouteOptions, "getRouteOptions") - if err != nil { - return - } - - pathParamsMap := map[string]string{ - "id": *getRouteOptions.ID, - } - - builder := core.NewRequestBuilder(core.GET) - builder = builder.WithContext(ctx) - builder.EnableGzipCompression = atracker.GetEnableGzipCompression() - _, err = builder.ResolveRequestURL(atracker.Service.Options.URL, `/api/v1/routes/{id}`, pathParamsMap) - if err != nil { - return - } - - for headerName, headerValue := range getRouteOptions.Headers { - builder.AddHeader(headerName, headerValue) - } - - sdkHeaders := common.GetSdkHeaders("atracker", "V1", "GetRoute") - for headerName, headerValue := range sdkHeaders { - builder.AddHeader(headerName, headerValue) - } - builder.AddHeader("Accept", "application/json") - - request, err := builder.Build() - if err != nil { - return - } - - var rawResponse map[string]json.RawMessage - response, err = atracker.Service.Request(request, &rawResponse) - if err != nil { - return - } - if rawResponse != nil { - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalRoute) - if err != nil { - return - } - response.Result = result - } - - return -} - -// ReplaceRoute : Update a route -// Update the configuration details of a route. -func (atracker *AtrackerV1) ReplaceRoute(replaceRouteOptions *ReplaceRouteOptions) (result *Route, response *core.DetailedResponse, err error) { - return atracker.ReplaceRouteWithContext(context.Background(), replaceRouteOptions) -} - -// ReplaceRouteWithContext is an alternate form of the ReplaceRoute method which supports a Context parameter -func (atracker *AtrackerV1) ReplaceRouteWithContext(ctx context.Context, replaceRouteOptions *ReplaceRouteOptions) (result *Route, response *core.DetailedResponse, err error) { - err = core.ValidateNotNil(replaceRouteOptions, "replaceRouteOptions cannot be nil") - if err != nil { - return - } - err = core.ValidateStruct(replaceRouteOptions, "replaceRouteOptions") - if err != nil { - return - } - - pathParamsMap := map[string]string{ - "id": *replaceRouteOptions.ID, - } - - builder := core.NewRequestBuilder(core.PUT) - builder = builder.WithContext(ctx) - builder.EnableGzipCompression = atracker.GetEnableGzipCompression() - _, err = builder.ResolveRequestURL(atracker.Service.Options.URL, `/api/v1/routes/{id}`, pathParamsMap) - if err != nil { - return - } - - for headerName, headerValue := range replaceRouteOptions.Headers { - builder.AddHeader(headerName, headerValue) - } - - sdkHeaders := common.GetSdkHeaders("atracker", "V1", "ReplaceRoute") - for headerName, headerValue := range sdkHeaders { - builder.AddHeader(headerName, headerValue) - } - builder.AddHeader("Accept", "application/json") - builder.AddHeader("Content-Type", "application/json") - - body := make(map[string]interface{}) - if replaceRouteOptions.Name != nil { - body["name"] = replaceRouteOptions.Name - } - if replaceRouteOptions.ReceiveGlobalEvents != nil { - body["receive_global_events"] = replaceRouteOptions.ReceiveGlobalEvents - } - if replaceRouteOptions.Rules != nil { - body["rules"] = replaceRouteOptions.Rules - } - _, err = builder.SetBodyContentJSON(body) - if err != nil { - return - } - - request, err := builder.Build() - if err != nil { - return - } - - var rawResponse map[string]json.RawMessage - response, err = atracker.Service.Request(request, &rawResponse) - if err != nil { - return - } - if rawResponse != nil { - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalRoute) - if err != nil { - return - } - response.Result = result - } - - return -} - -// DeleteRoute : Delete a route -// Deletes a route. -func (atracker *AtrackerV1) DeleteRoute(deleteRouteOptions *DeleteRouteOptions) (response *core.DetailedResponse, err error) { - return atracker.DeleteRouteWithContext(context.Background(), deleteRouteOptions) -} - -// DeleteRouteWithContext is an alternate form of the DeleteRoute method which supports a Context parameter -func (atracker *AtrackerV1) DeleteRouteWithContext(ctx context.Context, deleteRouteOptions *DeleteRouteOptions) (response *core.DetailedResponse, err error) { - err = core.ValidateNotNil(deleteRouteOptions, "deleteRouteOptions cannot be nil") - if err != nil { - return - } - err = core.ValidateStruct(deleteRouteOptions, "deleteRouteOptions") - if err != nil { - return - } - - pathParamsMap := map[string]string{ - "id": *deleteRouteOptions.ID, - } - - builder := core.NewRequestBuilder(core.DELETE) - builder = builder.WithContext(ctx) - builder.EnableGzipCompression = atracker.GetEnableGzipCompression() - _, err = builder.ResolveRequestURL(atracker.Service.Options.URL, `/api/v1/routes/{id}`, pathParamsMap) - if err != nil { - return - } - - for headerName, headerValue := range deleteRouteOptions.Headers { - builder.AddHeader(headerName, headerValue) - } - - sdkHeaders := common.GetSdkHeaders("atracker", "V1", "DeleteRoute") - for headerName, headerValue := range sdkHeaders { - builder.AddHeader(headerName, headerValue) - } - - request, err := builder.Build() - if err != nil { - return - } - - response, err = atracker.Service.Request(request, nil) - - return -} - -// GetEndpoints : Get endpoints -// Get information about the public and private endpoints that are enabled in a region when you use the Activity Tracker -// API. -func (atracker *AtrackerV1) GetEndpoints(getEndpointsOptions *GetEndpointsOptions) (result *Endpoints, response *core.DetailedResponse, err error) { - return atracker.GetEndpointsWithContext(context.Background(), getEndpointsOptions) -} - -// GetEndpointsWithContext is an alternate form of the GetEndpoints method which supports a Context parameter -func (atracker *AtrackerV1) GetEndpointsWithContext(ctx context.Context, getEndpointsOptions *GetEndpointsOptions) (result *Endpoints, response *core.DetailedResponse, err error) { - err = core.ValidateStruct(getEndpointsOptions, "getEndpointsOptions") - if err != nil { - return - } - - builder := core.NewRequestBuilder(core.GET) - builder = builder.WithContext(ctx) - builder.EnableGzipCompression = atracker.GetEnableGzipCompression() - _, err = builder.ResolveRequestURL(atracker.Service.Options.URL, `/api/v1/endpoints`, nil) - if err != nil { - return - } - - for headerName, headerValue := range getEndpointsOptions.Headers { - builder.AddHeader(headerName, headerValue) - } - - sdkHeaders := common.GetSdkHeaders("atracker", "V1", "GetEndpoints") - for headerName, headerValue := range sdkHeaders { - builder.AddHeader(headerName, headerValue) - } - builder.AddHeader("Accept", "application/json") - - request, err := builder.Build() - if err != nil { - return - } - - var rawResponse map[string]json.RawMessage - response, err = atracker.Service.Request(request, &rawResponse) - if err != nil { - return - } - if rawResponse != nil { - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalEndpoints) - if err != nil { - return - } - response.Result = result - } - - return -} - -// PatchEndpoints : Modify endpoints -// Configure the public endpoint availability in a region to use the Activity Tracker API. By default, the private -// endpoint is enabled and cannot be disabled. -func (atracker *AtrackerV1) PatchEndpoints(patchEndpointsOptions *PatchEndpointsOptions) (result *Endpoints, response *core.DetailedResponse, err error) { - return atracker.PatchEndpointsWithContext(context.Background(), patchEndpointsOptions) -} - -// PatchEndpointsWithContext is an alternate form of the PatchEndpoints method which supports a Context parameter -func (atracker *AtrackerV1) PatchEndpointsWithContext(ctx context.Context, patchEndpointsOptions *PatchEndpointsOptions) (result *Endpoints, response *core.DetailedResponse, err error) { - err = core.ValidateNotNil(patchEndpointsOptions, "patchEndpointsOptions cannot be nil") - if err != nil { - return - } - err = core.ValidateStruct(patchEndpointsOptions, "patchEndpointsOptions") - if err != nil { - return - } - - builder := core.NewRequestBuilder(core.PATCH) - builder = builder.WithContext(ctx) - builder.EnableGzipCompression = atracker.GetEnableGzipCompression() - _, err = builder.ResolveRequestURL(atracker.Service.Options.URL, `/api/v1/endpoints`, nil) - if err != nil { - return - } - - for headerName, headerValue := range patchEndpointsOptions.Headers { - builder.AddHeader(headerName, headerValue) - } - - sdkHeaders := common.GetSdkHeaders("atracker", "V1", "PatchEndpoints") - for headerName, headerValue := range sdkHeaders { - builder.AddHeader(headerName, headerValue) - } - builder.AddHeader("Accept", "application/json") - builder.AddHeader("Content-Type", "application/json") - - body := make(map[string]interface{}) - if patchEndpointsOptions.APIEndpoint != nil { - body["api_endpoint"] = patchEndpointsOptions.APIEndpoint - } - _, err = builder.SetBodyContentJSON(body) - if err != nil { - return - } - - request, err := builder.Build() - if err != nil { - return - } - - var rawResponse map[string]json.RawMessage - response, err = atracker.Service.Request(request, &rawResponse) - if err != nil { - return - } - if rawResponse != nil { - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalEndpoints) - if err != nil { - return - } - response.Result = result - } - - return -} - -// APIEndpoint : Activity Tracker API endpoint. -type APIEndpoint struct { - // The public URL of Activity Tracker in a region. - PublicURL *string `json:"public_url" validate:"required"` - - // Indicates whether or not the public endpoint is enabled in the account. - PublicEnabled *bool `json:"public_enabled" validate:"required"` - - // The private URL of Activity Tracker. This URL cannot be disabled. - PrivateURL *string `json:"private_url" validate:"required"` - - // The private endpoint is always enabled. - PrivateEnabled *bool `json:"private_enabled,omitempty"` -} - -// UnmarshalAPIEndpoint unmarshals an instance of APIEndpoint from the specified map of raw messages. -func UnmarshalAPIEndpoint(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(APIEndpoint) - err = core.UnmarshalPrimitive(m, "public_url", &obj.PublicURL) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "public_enabled", &obj.PublicEnabled) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "private_url", &obj.PrivateURL) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "private_enabled", &obj.PrivateEnabled) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// CreateRouteOptions : The CreateRoute options. -type CreateRouteOptions struct { - // The name of the route. The name must be 1000 characters or less and cannot include any special characters other than - // `(space) - . _ :`. Do not include any personal identifying information (PII) in any resource names. - Name *string `json:"name" validate:"required"` - - // Indicates whether or not all global events should be forwarded to this region. - ReceiveGlobalEvents *bool `json:"receive_global_events" validate:"required"` - - // Routing rules that will be evaluated in their order of the array. - Rules []Rule `json:"rules" validate:"required"` - - // Allows users to set headers on API requests - Headers map[string]string -} - -// NewCreateRouteOptions : Instantiate CreateRouteOptions -func (*AtrackerV1) NewCreateRouteOptions(name string, receiveGlobalEvents bool, rules []Rule) *CreateRouteOptions { - return &CreateRouteOptions{ - Name: core.StringPtr(name), - ReceiveGlobalEvents: core.BoolPtr(receiveGlobalEvents), - Rules: rules, - } -} - -// SetName : Allow user to set Name -func (_options *CreateRouteOptions) SetName(name string) *CreateRouteOptions { - _options.Name = core.StringPtr(name) - return _options -} - -// SetReceiveGlobalEvents : Allow user to set ReceiveGlobalEvents -func (_options *CreateRouteOptions) SetReceiveGlobalEvents(receiveGlobalEvents bool) *CreateRouteOptions { - _options.ReceiveGlobalEvents = core.BoolPtr(receiveGlobalEvents) - return _options -} - -// SetRules : Allow user to set Rules -func (_options *CreateRouteOptions) SetRules(rules []Rule) *CreateRouteOptions { - _options.Rules = rules - return _options -} - -// SetHeaders : Allow user to set Headers -func (options *CreateRouteOptions) SetHeaders(param map[string]string) *CreateRouteOptions { - options.Headers = param - return options -} - -// CreateTargetOptions : The CreateTarget options. -type CreateTargetOptions struct { - // The name of the target. The name must be 1000 characters or less, and cannot include any special characters other - // than `(space) - . _ :`. Do not include any personal identifying information (PII) in any resource names. - Name *string `json:"name" validate:"required"` - - // The type of the target. - TargetType *string `json:"target_type" validate:"required"` - - // Property values for a Cloud Object Storage Endpoint. - CosEndpoint *CosEndpoint `json:"cos_endpoint" validate:"required"` - - // Allows users to set headers on API requests - Headers map[string]string -} - -// Constants associated with the CreateTargetOptions.TargetType property. -// The type of the target. -const ( - CreateTargetOptionsTargetTypeCloudObjectStorageConst = "cloud_object_storage" -) - -// NewCreateTargetOptions : Instantiate CreateTargetOptions -func (*AtrackerV1) NewCreateTargetOptions(name string, targetType string, cosEndpoint *CosEndpoint) *CreateTargetOptions { - return &CreateTargetOptions{ - Name: core.StringPtr(name), - TargetType: core.StringPtr(targetType), - CosEndpoint: cosEndpoint, - } -} - -// SetName : Allow user to set Name -func (_options *CreateTargetOptions) SetName(name string) *CreateTargetOptions { - _options.Name = core.StringPtr(name) - return _options -} - -// SetTargetType : Allow user to set TargetType -func (_options *CreateTargetOptions) SetTargetType(targetType string) *CreateTargetOptions { - _options.TargetType = core.StringPtr(targetType) - return _options -} - -// SetCosEndpoint : Allow user to set CosEndpoint -func (_options *CreateTargetOptions) SetCosEndpoint(cosEndpoint *CosEndpoint) *CreateTargetOptions { - _options.CosEndpoint = cosEndpoint - return _options -} - -// SetHeaders : Allow user to set Headers -func (options *CreateTargetOptions) SetHeaders(param map[string]string) *CreateTargetOptions { - options.Headers = param - return options -} - -// DeleteRouteOptions : The DeleteRoute options. -type DeleteRouteOptions struct { - // The v4 UUID that uniquely identifies the route. - ID *string `json:"id" validate:"required,ne="` - - // Allows users to set headers on API requests - Headers map[string]string -} - -// NewDeleteRouteOptions : Instantiate DeleteRouteOptions -func (*AtrackerV1) NewDeleteRouteOptions(id string) *DeleteRouteOptions { - return &DeleteRouteOptions{ - ID: core.StringPtr(id), - } -} - -// SetID : Allow user to set ID -func (_options *DeleteRouteOptions) SetID(id string) *DeleteRouteOptions { - _options.ID = core.StringPtr(id) - return _options -} - -// SetHeaders : Allow user to set Headers -func (options *DeleteRouteOptions) SetHeaders(param map[string]string) *DeleteRouteOptions { - options.Headers = param - return options -} - -// DeleteTargetOptions : The DeleteTarget options. -type DeleteTargetOptions struct { - // The v4 UUID that uniquely identifies the target. - ID *string `json:"id" validate:"required,ne="` - - // Allows users to set headers on API requests - Headers map[string]string -} - -// NewDeleteTargetOptions : Instantiate DeleteTargetOptions -func (*AtrackerV1) NewDeleteTargetOptions(id string) *DeleteTargetOptions { - return &DeleteTargetOptions{ - ID: core.StringPtr(id), - } -} - -// SetID : Allow user to set ID -func (_options *DeleteTargetOptions) SetID(id string) *DeleteTargetOptions { - _options.ID = core.StringPtr(id) - return _options -} - -// SetHeaders : Allow user to set Headers -func (options *DeleteTargetOptions) SetHeaders(param map[string]string) *DeleteTargetOptions { - options.Headers = param - return options -} - -// Endpoints : Activity Tracker endpoints. -type Endpoints struct { - // Activity Tracker API endpoint. - APIEndpoint *APIEndpoint `json:"api_endpoint" validate:"required"` -} - -// UnmarshalEndpoints unmarshals an instance of Endpoints from the specified map of raw messages. -func UnmarshalEndpoints(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(Endpoints) - err = core.UnmarshalModel(m, "api_endpoint", &obj.APIEndpoint, UnmarshalAPIEndpoint) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// EndpointsRequestAPIEndpoint : Activity Tracker service API endpoint. -type EndpointsRequestAPIEndpoint struct { - // Indicate whether or not the public endpoint is enabled in an account. - PublicEnabled *bool `json:"public_enabled,omitempty"` -} - -// UnmarshalEndpointsRequestAPIEndpoint unmarshals an instance of EndpointsRequestAPIEndpoint from the specified map of raw messages. -func UnmarshalEndpointsRequestAPIEndpoint(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(EndpointsRequestAPIEndpoint) - err = core.UnmarshalPrimitive(m, "public_enabled", &obj.PublicEnabled) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// GetEndpointsOptions : The GetEndpoints options. -type GetEndpointsOptions struct { - - // Allows users to set headers on API requests - Headers map[string]string -} - -// NewGetEndpointsOptions : Instantiate GetEndpointsOptions -func (*AtrackerV1) NewGetEndpointsOptions() *GetEndpointsOptions { - return &GetEndpointsOptions{} -} - -// SetHeaders : Allow user to set Headers -func (options *GetEndpointsOptions) SetHeaders(param map[string]string) *GetEndpointsOptions { - options.Headers = param - return options -} - -// GetRouteOptions : The GetRoute options. -type GetRouteOptions struct { - // The v4 UUID that uniquely identifies the route. - ID *string `json:"id" validate:"required,ne="` - - // Allows users to set headers on API requests - Headers map[string]string -} - -// NewGetRouteOptions : Instantiate GetRouteOptions -func (*AtrackerV1) NewGetRouteOptions(id string) *GetRouteOptions { - return &GetRouteOptions{ - ID: core.StringPtr(id), - } -} - -// SetID : Allow user to set ID -func (_options *GetRouteOptions) SetID(id string) *GetRouteOptions { - _options.ID = core.StringPtr(id) - return _options -} - -// SetHeaders : Allow user to set Headers -func (options *GetRouteOptions) SetHeaders(param map[string]string) *GetRouteOptions { - options.Headers = param - return options -} - -// GetTargetOptions : The GetTarget options. -type GetTargetOptions struct { - // The v4 UUID that uniquely identifies the target. - ID *string `json:"id" validate:"required,ne="` - - // Allows users to set headers on API requests - Headers map[string]string -} - -// NewGetTargetOptions : Instantiate GetTargetOptions -func (*AtrackerV1) NewGetTargetOptions(id string) *GetTargetOptions { - return &GetTargetOptions{ - ID: core.StringPtr(id), - } -} - -// SetID : Allow user to set ID -func (_options *GetTargetOptions) SetID(id string) *GetTargetOptions { - _options.ID = core.StringPtr(id) - return _options -} - -// SetHeaders : Allow user to set Headers -func (options *GetTargetOptions) SetHeaders(param map[string]string) *GetTargetOptions { - options.Headers = param - return options -} - -// ListRoutesOptions : The ListRoutes options. -type ListRoutesOptions struct { - - // Allows users to set headers on API requests - Headers map[string]string -} - -// NewListRoutesOptions : Instantiate ListRoutesOptions -func (*AtrackerV1) NewListRoutesOptions() *ListRoutesOptions { - return &ListRoutesOptions{} -} - -// SetHeaders : Allow user to set Headers -func (options *ListRoutesOptions) SetHeaders(param map[string]string) *ListRoutesOptions { - options.Headers = param - return options -} - -// ListTargetsOptions : The ListTargets options. -type ListTargetsOptions struct { - - // Allows users to set headers on API requests - Headers map[string]string -} - -// NewListTargetsOptions : Instantiate ListTargetsOptions -func (*AtrackerV1) NewListTargetsOptions() *ListTargetsOptions { - return &ListTargetsOptions{} -} - -// SetHeaders : Allow user to set Headers -func (options *ListTargetsOptions) SetHeaders(param map[string]string) *ListTargetsOptions { - options.Headers = param - return options -} - -// PatchEndpointsOptions : The PatchEndpoints options. -type PatchEndpointsOptions struct { - // Activity Tracker service API endpoint. - APIEndpoint *EndpointsRequestAPIEndpoint `json:"api_endpoint,omitempty"` - - // Allows users to set headers on API requests - Headers map[string]string -} - -// NewPatchEndpointsOptions : Instantiate PatchEndpointsOptions -func (*AtrackerV1) NewPatchEndpointsOptions() *PatchEndpointsOptions { - return &PatchEndpointsOptions{} -} - -// SetAPIEndpoint : Allow user to set APIEndpoint -func (_options *PatchEndpointsOptions) SetAPIEndpoint(apiEndpoint *EndpointsRequestAPIEndpoint) *PatchEndpointsOptions { - _options.APIEndpoint = apiEndpoint - return _options -} - -// SetHeaders : Allow user to set Headers -func (options *PatchEndpointsOptions) SetHeaders(param map[string]string) *PatchEndpointsOptions { - options.Headers = param - return options -} - -// ReplaceRouteOptions : The ReplaceRoute options. -type ReplaceRouteOptions struct { - // The v4 UUID that uniquely identifies the route. - ID *string `json:"id" validate:"required,ne="` - - // The name of the route. The name must be 1000 characters or less and cannot include any special characters other than - // `(space) - . _ :`. Do not include any personal identifying information (PII) in any resource names. - Name *string `json:"name" validate:"required"` - - // Indicates whether or not all global events should be forwarded to this region. - ReceiveGlobalEvents *bool `json:"receive_global_events" validate:"required"` - - // Routing rules that will be evaluated in their order of the array. - Rules []Rule `json:"rules" validate:"required"` - - // Allows users to set headers on API requests - Headers map[string]string -} - -// NewReplaceRouteOptions : Instantiate ReplaceRouteOptions -func (*AtrackerV1) NewReplaceRouteOptions(id string, name string, receiveGlobalEvents bool, rules []Rule) *ReplaceRouteOptions { - return &ReplaceRouteOptions{ - ID: core.StringPtr(id), - Name: core.StringPtr(name), - ReceiveGlobalEvents: core.BoolPtr(receiveGlobalEvents), - Rules: rules, - } -} - -// SetID : Allow user to set ID -func (_options *ReplaceRouteOptions) SetID(id string) *ReplaceRouteOptions { - _options.ID = core.StringPtr(id) - return _options -} - -// SetName : Allow user to set Name -func (_options *ReplaceRouteOptions) SetName(name string) *ReplaceRouteOptions { - _options.Name = core.StringPtr(name) - return _options -} - -// SetReceiveGlobalEvents : Allow user to set ReceiveGlobalEvents -func (_options *ReplaceRouteOptions) SetReceiveGlobalEvents(receiveGlobalEvents bool) *ReplaceRouteOptions { - _options.ReceiveGlobalEvents = core.BoolPtr(receiveGlobalEvents) - return _options -} - -// SetRules : Allow user to set Rules -func (_options *ReplaceRouteOptions) SetRules(rules []Rule) *ReplaceRouteOptions { - _options.Rules = rules - return _options -} - -// SetHeaders : Allow user to set Headers -func (options *ReplaceRouteOptions) SetHeaders(param map[string]string) *ReplaceRouteOptions { - options.Headers = param - return options -} - -// ReplaceTargetOptions : The ReplaceTarget options. -type ReplaceTargetOptions struct { - // The v4 UUID that uniquely identifies the target. - ID *string `json:"id" validate:"required,ne="` - - // The name of the target. The name must be 1000 characters or less, and cannot include any special characters other - // than `(space) - . _ :`. Do not include any personal identifying information (PII) in any resource names. - Name *string `json:"name" validate:"required"` - - // The type of the target. - TargetType *string `json:"target_type" validate:"required"` - - // Property values for a Cloud Object Storage Endpoint. - CosEndpoint *CosEndpoint `json:"cos_endpoint" validate:"required"` - - // Allows users to set headers on API requests - Headers map[string]string -} - -// Constants associated with the ReplaceTargetOptions.TargetType property. -// The type of the target. -const ( - ReplaceTargetOptionsTargetTypeCloudObjectStorageConst = "cloud_object_storage" -) - -// NewReplaceTargetOptions : Instantiate ReplaceTargetOptions -func (*AtrackerV1) NewReplaceTargetOptions(id string, name string, targetType string, cosEndpoint *CosEndpoint) *ReplaceTargetOptions { - return &ReplaceTargetOptions{ - ID: core.StringPtr(id), - Name: core.StringPtr(name), - TargetType: core.StringPtr(targetType), - CosEndpoint: cosEndpoint, - } -} - -// SetID : Allow user to set ID -func (_options *ReplaceTargetOptions) SetID(id string) *ReplaceTargetOptions { - _options.ID = core.StringPtr(id) - return _options -} - -// SetName : Allow user to set Name -func (_options *ReplaceTargetOptions) SetName(name string) *ReplaceTargetOptions { - _options.Name = core.StringPtr(name) - return _options -} - -// SetTargetType : Allow user to set TargetType -func (_options *ReplaceTargetOptions) SetTargetType(targetType string) *ReplaceTargetOptions { - _options.TargetType = core.StringPtr(targetType) - return _options -} - -// SetCosEndpoint : Allow user to set CosEndpoint -func (_options *ReplaceTargetOptions) SetCosEndpoint(cosEndpoint *CosEndpoint) *ReplaceTargetOptions { - _options.CosEndpoint = cosEndpoint - return _options -} - -// SetHeaders : Allow user to set Headers -func (options *ReplaceTargetOptions) SetHeaders(param map[string]string) *ReplaceTargetOptions { - options.Headers = param - return options -} - -// Route : The route resource. -type Route struct { - // The uuid of the route resource. - ID *string `json:"id" validate:"required"` - - // The name of the route. - Name *string `json:"name" validate:"required"` - - // The crn of the route resource. - CRN *string `json:"crn" validate:"required"` - - // The version of the route. - Version *int64 `json:"version,omitempty"` - - // Indicates whether or not all global events should be forwarded to this region. - ReceiveGlobalEvents *bool `json:"receive_global_events" validate:"required"` - - // The routing rules that will be evaluated in their order of the array. - Rules []Rule `json:"rules" validate:"required"` - - // The timestamp of the route creation time. - Created *strfmt.DateTime `json:"created,omitempty"` - - // The timestamp of the route last updated time. - Updated *strfmt.DateTime `json:"updated,omitempty"` -} - -// UnmarshalRoute unmarshals an instance of Route from the specified map of raw messages. -func UnmarshalRoute(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(Route) - err = core.UnmarshalPrimitive(m, "id", &obj.ID) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "name", &obj.Name) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "crn", &obj.CRN) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "version", &obj.Version) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "receive_global_events", &obj.ReceiveGlobalEvents) - if err != nil { - return - } - err = core.UnmarshalModel(m, "rules", &obj.Rules, UnmarshalRule) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "created", &obj.Created) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "updated", &obj.Updated) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// RouteList : A list of route resources. -type RouteList struct { - // A list of route resources. - Routes []Route `json:"routes" validate:"required"` -} - -// UnmarshalRouteList unmarshals an instance of RouteList from the specified map of raw messages. -func UnmarshalRouteList(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(RouteList) - err = core.UnmarshalModel(m, "routes", &obj.Routes, UnmarshalRoute) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// Rule : The request payload to create a regional route. -type Rule struct { - // The target ID List. Only 1 target id is supported. - TargetIds []string `json:"target_ids" validate:"required"` -} - -// NewRule : Instantiate Rule (Generic Model Constructor) -func (*AtrackerV1) NewRule(targetIds []string) (_model *Rule, err error) { - _model = &Rule{ - TargetIds: targetIds, - } - err = core.ValidateStruct(_model, "required parameters") - return -} - -// UnmarshalRule unmarshals an instance of Rule from the specified map of raw messages. -func UnmarshalRule(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(Rule) - err = core.UnmarshalPrimitive(m, "target_ids", &obj.TargetIds) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// Target : Property values for a target in the response. Credentials associated with the target are encrypted and masked as -// REDACTED in the response. -type Target struct { - // The uuid of the target resource. - ID *string `json:"id" validate:"required"` - - // The name of the target resource. - Name *string `json:"name" validate:"required"` - - // The crn of the target resource. - CRN *string `json:"crn" validate:"required"` - - // The type of the target. - TargetType *string `json:"target_type" validate:"required"` - - // The encryption key that is used to encrypt events before Activity Tracker services buffer them on storage. This - // credential is masked in the response. - EncryptKey *string `json:"encrypt_key,omitempty"` - - // Property values for a Cloud Object Storage Endpoint. - CosEndpoint *CosEndpoint `json:"cos_endpoint,omitempty"` - - // The status of the write attempt with the provided cos_endpoint parameters. - CosWriteStatus *CosWriteStatus `json:"cos_write_status,omitempty"` - - // The timestamp of the target creation time. - Created *strfmt.DateTime `json:"created,omitempty"` - - // The timestamp of the target last updated time. - Updated *strfmt.DateTime `json:"updated,omitempty"` -} - -// Constants associated with the Target.TargetType property. -// The type of the target. -const ( - TargetTargetTypeCloudObjectStorageConst = "cloud_object_storage" -) - -// UnmarshalTarget unmarshals an instance of Target from the specified map of raw messages. -func UnmarshalTarget(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(Target) - err = core.UnmarshalPrimitive(m, "id", &obj.ID) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "name", &obj.Name) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "crn", &obj.CRN) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "target_type", &obj.TargetType) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "encrypt_key", &obj.EncryptKey) - if err != nil { - return - } - err = core.UnmarshalModel(m, "cos_endpoint", &obj.CosEndpoint, UnmarshalCosEndpoint) - if err != nil { - return - } - err = core.UnmarshalModel(m, "cos_write_status", &obj.CosWriteStatus, UnmarshalCosWriteStatus) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "created", &obj.Created) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "updated", &obj.Updated) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// TargetList : A list of target resources. -type TargetList struct { - // A list of target resources. - Targets []Target `json:"targets" validate:"required"` -} - -// UnmarshalTargetList unmarshals an instance of TargetList from the specified map of raw messages. -func UnmarshalTargetList(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(TargetList) - err = core.UnmarshalModel(m, "targets", &obj.Targets, UnmarshalTarget) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// ValidateTargetOptions : The ValidateTarget options. -type ValidateTargetOptions struct { - // The v4 UUID that uniquely identifies the target. - ID *string `json:"id" validate:"required,ne="` - - // Allows users to set headers on API requests - Headers map[string]string -} - -// NewValidateTargetOptions : Instantiate ValidateTargetOptions -func (*AtrackerV1) NewValidateTargetOptions(id string) *ValidateTargetOptions { - return &ValidateTargetOptions{ - ID: core.StringPtr(id), - } -} - -// SetID : Allow user to set ID -func (_options *ValidateTargetOptions) SetID(id string) *ValidateTargetOptions { - _options.ID = core.StringPtr(id) - return _options -} - -// SetHeaders : Allow user to set Headers -func (options *ValidateTargetOptions) SetHeaders(param map[string]string) *ValidateTargetOptions { - options.Headers = param - return options -} - -// Warning : The warning object. -type Warning struct { - // The warning code. - Code *string `json:"code,omitempty"` - - // The warning message. - Message *string `json:"message,omitempty"` -} - -// UnmarshalWarning unmarshals an instance of Warning from the specified map of raw messages. -func UnmarshalWarning(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(Warning) - err = core.UnmarshalPrimitive(m, "code", &obj.Code) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "message", &obj.Message) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// WarningReport : Description of a warning that occurred in a service request. -type WarningReport struct { - // The status code. - StatusCode *int64 `json:"status_code,omitempty"` - - // The transaction-id of the API request. - Trace *string `json:"trace,omitempty"` - - // The warning array triggered by the API request. - Warnings []Warning `json:"warnings,omitempty"` -} - -// UnmarshalWarningReport unmarshals an instance of WarningReport from the specified map of raw messages. -func UnmarshalWarningReport(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(WarningReport) - err = core.UnmarshalPrimitive(m, "status_code", &obj.StatusCode) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "trace", &obj.Trace) - if err != nil { - return - } - err = core.UnmarshalModel(m, "warnings", &obj.Warnings, UnmarshalWarning) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// CosEndpoint : Property values for a Cloud Object Storage Endpoint. -type CosEndpoint struct { - // The host name of the Cloud Object Storage endpoint. - Endpoint *string `json:"endpoint" validate:"required"` - - // The CRN of the Cloud Object Storage instance. - TargetCRN *string `json:"target_crn" validate:"required"` - - // The bucket name under the Cloud Object Storage instance. - Bucket *string `json:"bucket" validate:"required"` - - // The IAM API key that has writer access to the Cloud Object Storage instance. This credential is masked in the - // response. - APIKey *string `json:"api_key" validate:"required"` -} - -// NewCosEndpoint : Instantiate CosEndpoint (Generic Model Constructor) -func (*AtrackerV1) NewCosEndpoint(endpoint string, targetCRN string, bucket string, apiKey string) (_model *CosEndpoint, err error) { - _model = &CosEndpoint{ - Endpoint: core.StringPtr(endpoint), - TargetCRN: core.StringPtr(targetCRN), - Bucket: core.StringPtr(bucket), - APIKey: core.StringPtr(apiKey), - } - err = core.ValidateStruct(_model, "required parameters") - return -} - -// UnmarshalCosEndpoint unmarshals an instance of CosEndpoint from the specified map of raw messages. -func UnmarshalCosEndpoint(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(CosEndpoint) - err = core.UnmarshalPrimitive(m, "endpoint", &obj.Endpoint) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "target_crn", &obj.TargetCRN) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "bucket", &obj.Bucket) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "api_key", &obj.APIKey) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// CosWriteStatus : The status of the write attempt with the provided cos_endpoint parameters. -type CosWriteStatus struct { - // The status such as failed or success. - Status *string `json:"status,omitempty"` - - // The timestamp of the failure. - LastFailure *strfmt.DateTime `json:"last_failure,omitempty"` - - // Detailed description of the cause of the failure. - ReasonForLastFailure *string `json:"reason_for_last_failure,omitempty"` -} - -// UnmarshalCosWriteStatus unmarshals an instance of CosWriteStatus from the specified map of raw messages. -func UnmarshalCosWriteStatus(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(CosWriteStatus) - err = core.UnmarshalPrimitive(m, "status", &obj.Status) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "last_failure", &obj.LastFailure) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "reason_for_last_failure", &obj.ReasonForLastFailure) - if err != nil { - return - } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} diff --git a/atrackerv1/atracker_v1_examples_test.go b/atrackerv1/atracker_v1_examples_test.go deleted file mode 100644 index a675a0e8..00000000 --- a/atrackerv1/atracker_v1_examples_test.go +++ /dev/null @@ -1,427 +0,0 @@ -// +build examples - -/** - * (C) Copyright IBM Corp. 2021. - * - * 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 atrackerv1_test - -import ( - "encoding/json" - "fmt" - "os" - - "github.com/IBM/go-sdk-core/v5/core" - "github.com/IBM/platform-services-go-sdk/atrackerv1" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -// -// This file provides an example of how to use the atracker service. -// -// The following configuration properties are assumed to be defined: -// ATRACKER_URL= -// ATRACKER_AUTH_TYPE=iam -// ATRACKER_APIKEY= -// ATRACKER_AUTH_URL= -// -// These configuration properties can be exported as environment variables, or stored -// in a configuration file and then: -// export IBM_CREDENTIALS_FILE= -// -const externalConfigFile = "../atracker_v1.env" - -var ( - atrackerService *atrackerv1.AtrackerV1 - config map[string]string - configLoaded bool = false -) - -// Globlal variables to hold link values -var ( - routeIDLink string - targetIDLink string -) - -func shouldSkipTest() { - if !configLoaded { - Skip("External configuration is not available, skipping tests...") - } -} - -var _ = Describe(`AtrackerV1 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(atrackerv1.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 - - atrackerServiceOptions := &atrackerv1.AtrackerV1Options{} - - atrackerService, err = atrackerv1.NewAtrackerV1UsingExternalConfig(atrackerServiceOptions) - - if err != nil { - panic(err) - } - - // end-common - - Expect(atrackerService).ToNot(BeNil()) - }) - }) - - Describe(`AtrackerV1 request examples`, func() { - BeforeEach(func() { - shouldSkipTest() - }) - It(`CreateTarget request example`, func() { - fmt.Println("\nCreateTarget() result:") - // begin-create_target - - cosEndpointModel := &atrackerv1.CosEndpoint{ - Endpoint: core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud"), - TargetCRN: core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::"), - Bucket: core.StringPtr("my-atracker-bucket"), - APIKey: core.StringPtr("xxxxxxxxxxxxxx"), - } - - createTargetOptions := atrackerService.NewCreateTargetOptions( - "my-cos-target", - "cloud_object_storage", - cosEndpointModel, - ) - - target, response, err := atrackerService.CreateTarget(createTargetOptions) - if err != nil { - panic(err) - } - b, _ := json.MarshalIndent(target, "", " ") - fmt.Println(string(b)) - - // end-create_target - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(201)) - Expect(target).ToNot(BeNil()) - - targetIDLink = *target.ID - - }) - It(`ListTargets request example`, func() { - fmt.Println("\nListTargets() result:") - // begin-list_targets - - listTargetsOptions := atrackerService.NewListTargetsOptions() - - targetList, response, err := atrackerService.ListTargets(listTargetsOptions) - if err != nil { - panic(err) - } - b, _ := json.MarshalIndent(targetList, "", " ") - fmt.Println(string(b)) - - // end-list_targets - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(targetList).ToNot(BeNil()) - - }) - It(`GetTarget request example`, func() { - fmt.Println("\nGetTarget() result:") - // begin-get_target - - getTargetOptions := atrackerService.NewGetTargetOptions( - targetIDLink, - ) - - target, response, err := atrackerService.GetTarget(getTargetOptions) - if err != nil { - panic(err) - } - b, _ := json.MarshalIndent(target, "", " ") - fmt.Println(string(b)) - - // end-get_target - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(target).ToNot(BeNil()) - - }) - It(`ReplaceTarget request example`, func() { - fmt.Println("\nReplaceTarget() result:") - // begin-replace_target - - cosEndpointModel := &atrackerv1.CosEndpoint{ - Endpoint: core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud"), - TargetCRN: core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::"), - Bucket: core.StringPtr("my-atracker-bucket"), - APIKey: core.StringPtr("xxxxxxxxxxxxxx"), - } - - replaceTargetOptions := atrackerService.NewReplaceTargetOptions( - targetIDLink, - "my-cos-target-modified", - "cloud_object_storage", - cosEndpointModel, - ) - - target, response, err := atrackerService.ReplaceTarget(replaceTargetOptions) - if err != nil { - panic(err) - } - b, _ := json.MarshalIndent(target, "", " ") - fmt.Println(string(b)) - - // end-replace_target - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(target).ToNot(BeNil()) - - }) - It(`ValidateTarget request example`, func() { - fmt.Println("\nValidateTarget() result:") - // begin-validate_target - - validateTargetOptions := atrackerService.NewValidateTargetOptions( - targetIDLink, - ) - - target, response, err := atrackerService.ValidateTarget(validateTargetOptions) - if err != nil { - panic(err) - } - b, _ := json.MarshalIndent(target, "", " ") - fmt.Println(string(b)) - - // end-validate_target - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(target).ToNot(BeNil()) - - }) - It(`CreateRoute request example`, func() { - fmt.Println("\nCreateRoute() result:") - // begin-create_route - - ruleModel := &atrackerv1.Rule{ - TargetIds: []string{targetIDLink}, - } - - createRouteOptions := atrackerService.NewCreateRouteOptions( - "my-route", - false, - []atrackerv1.Rule{*ruleModel}, - ) - - route, response, err := atrackerService.CreateRoute(createRouteOptions) - if err != nil { - panic(err) - } - b, _ := json.MarshalIndent(route, "", " ") - fmt.Println(string(b)) - - // end-create_route - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(201)) - Expect(route).ToNot(BeNil()) - - routeIDLink = *route.ID - - }) - It(`ListRoutes request example`, func() { - fmt.Println("\nListRoutes() result:") - // begin-list_routes - - listRoutesOptions := atrackerService.NewListRoutesOptions() - - routeList, response, err := atrackerService.ListRoutes(listRoutesOptions) - if err != nil { - panic(err) - } - b, _ := json.MarshalIndent(routeList, "", " ") - fmt.Println(string(b)) - - // end-list_routes - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(routeList).ToNot(BeNil()) - - }) - It(`GetRoute request example`, func() { - fmt.Println("\nGetRoute() result:") - // begin-get_route - - getRouteOptions := atrackerService.NewGetRouteOptions( - routeIDLink, - ) - - route, response, err := atrackerService.GetRoute(getRouteOptions) - if err != nil { - panic(err) - } - b, _ := json.MarshalIndent(route, "", " ") - fmt.Println(string(b)) - - // end-get_route - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(route).ToNot(BeNil()) - - }) - It(`ReplaceRoute request example`, func() { - fmt.Println("\nReplaceRoute() result:") - // begin-replace_route - - ruleModel := &atrackerv1.Rule{ - TargetIds: []string{targetIDLink}, - } - - replaceRouteOptions := atrackerService.NewReplaceRouteOptions( - routeIDLink, - "my-route-modified", - false, - []atrackerv1.Rule{*ruleModel}, - ) - - route, response, err := atrackerService.ReplaceRoute(replaceRouteOptions) - if err != nil { - panic(err) - } - b, _ := json.MarshalIndent(route, "", " ") - fmt.Println(string(b)) - - // end-replace_route - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(route).ToNot(BeNil()) - - }) - It(`DeleteRoute request example`, func() { - // begin-delete_route - - deleteRouteOptions := atrackerService.NewDeleteRouteOptions( - routeIDLink, - ) - - response, err := atrackerService.DeleteRoute(deleteRouteOptions) - if err != nil { - panic(err) - } - // end-delete_route - fmt.Printf("\nDeleteRoute() response status code: %d\n", response.StatusCode) - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(204)) - - }) - It(`DeleteTarget request example`, func() { - fmt.Println("\nDeleteTarget() result:") - // begin-delete_target - - deleteTargetOptions := atrackerService.NewDeleteTargetOptions( - targetIDLink, - ) - - warningReport, response, err := atrackerService.DeleteTarget(deleteTargetOptions) - if err != nil { - panic(err) - } - b, _ := json.MarshalIndent(warningReport, "", " ") - fmt.Println(string(b)) - - // end-delete_target - fmt.Printf("\nDeleteTarget() response status code: %d\n", response.StatusCode) - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(warningReport).ToNot(BeNil()) - - }) - It(`GetEndpoints request example`, func() { - fmt.Println("\nGetEndpoints() result:") - // begin-get_endpoints - - getEndpointsOptions := atrackerService.NewGetEndpointsOptions() - - endpoints, response, err := atrackerService.GetEndpoints(getEndpointsOptions) - if err != nil { - panic(err) - } - b, _ := json.MarshalIndent(endpoints, "", " ") - fmt.Println(string(b)) - - // end-get_endpoints - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(endpoints).ToNot(BeNil()) - - }) - It(`PatchEndpoints request example`, func() { - fmt.Println("\nPatchEndpoints() result:") - // begin-patch_endpoints - - patchEndpointsOptions := atrackerService.NewPatchEndpointsOptions() - - // set public enabled flag - publicEnabled := true - patchEndpointsOptions.SetAPIEndpoint(&atrackerv1.EndpointsRequestAPIEndpoint{PublicEnabled: &publicEnabled}) - - endpoints, response, err := atrackerService.PatchEndpoints(patchEndpointsOptions) - if err != nil { - panic(err) - } - b, _ := json.MarshalIndent(endpoints, "", " ") - fmt.Println(string(b)) - - // end-patch_endpoints - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(endpoints).ToNot(BeNil()) - - }) - }) -}) diff --git a/atrackerv1/atracker_v1_integration_test.go b/atrackerv1/atracker_v1_integration_test.go deleted file mode 100644 index 739dde52..00000000 --- a/atrackerv1/atracker_v1_integration_test.go +++ /dev/null @@ -1,785 +0,0 @@ -// +build integration - -/** - * (C) Copyright IBM Corp. 2021. - * - * 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 atrackerv1_test - -import ( - "fmt" - "os" - - "github.com/IBM/go-sdk-core/v5/core" - "github.com/IBM/platform-services-go-sdk/atrackerv1" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -/** - * This file contains an integration test for the atrackerv1 package. - * - * Notes: - * - * The integration test will automatically skip tests if the required config file is not available. - */ - -var _ = Describe(`AtrackerV1 Integration Tests`, func() { - - const externalConfigFile = "../atracker_v1.env" - - const notFoundTargetID = "deadbeef-2222-2222-2222-222222222222" - - const notFoundRouteID = "deadbeef-2222-2222-2222-222222222222" - - const badTargetType = "bad_target_type" - - var ( - err error - atrackerService *atrackerv1.AtrackerV1 - atrackerServiceNotAuthorized *atrackerv1.AtrackerV1 - serviceURL string - config map[string]string - - refreshTokenNotAuthorized string - ) - - // Globlal variables to hold link values - var ( - routeIDLink string - targetIDLink string - ) - - var shouldSkipTest = func() { - Skip("External configuration is not available, skipping tests...") - } - - Describe(`External configuration`, func() { - It("Successfully load the configuration", func() { - _, 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(atrackerv1.DefaultServiceName) - if err != nil { - Skip("Error loading service properties, skipping tests: " + err.Error()) - } - serviceURL = config["URL"] - if serviceURL == "" { - Skip("Unable to load service URL configuration property, skipping tests") - } - - fmt.Printf("Service URL: %s\n", serviceURL) - shouldSkipTest = func() {} - }) - }) - - Describe(`Client initialization`, func() { - BeforeEach(func() { - shouldSkipTest() - }) - It("Successfully construct the service client instance", func() { - - atrackerServiceOptions := &atrackerv1.AtrackerV1Options{} - - atrackerService, err = atrackerv1.NewAtrackerV1UsingExternalConfig(atrackerServiceOptions) - - Expect(err).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - Expect(atrackerService.Service.Options.URL).To(Equal(serviceURL)) - - atrackerUnauthorizedServiceOptions := &atrackerv1.AtrackerV1Options{ - ServiceName: "NOT_AUTHORIZED", - } - atrackerServiceNotAuthorized, err = atrackerv1.NewAtrackerV1UsingExternalConfig(atrackerUnauthorizedServiceOptions) - Expect(err).To(BeNil()) - Expect(atrackerServiceNotAuthorized).ToNot(BeNil()) - Expect(atrackerServiceNotAuthorized.Service.Options.URL).To(Equal(serviceURL)) - - tokenNotAuthorized, err := atrackerServiceNotAuthorized.Service.Options.Authenticator.(*core.IamAuthenticator).RequestToken() - Expect(err).To(BeNil()) - refreshTokenNotAuthorized = tokenNotAuthorized.RefreshToken - Expect(refreshTokenNotAuthorized).ToNot(BeNil()) - }) - }) - - Describe(`CreateTarget - Create a Cloud Object Storage target for a region`, func() { - BeforeEach(func() { - shouldSkipTest() - }) - - It(`Returns 400 when backend input validation fails`, func() { - cosEndpointModel := &atrackerv1.CosEndpoint{ - Endpoint: core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud"), - TargetCRN: core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::"), - Bucket: core.StringPtr("my-atracker-bucket"), - APIKey: core.StringPtr("xxxxxxxxxxxxxx"), - } - - createTargetOptions := &atrackerv1.CreateTargetOptions{ - Name: core.StringPtr("my-cos-target"), - TargetType: core.StringPtr(badTargetType), - CosEndpoint: cosEndpointModel, - } - - _, response, err := atrackerService.CreateTarget(createTargetOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(400)) - }) - - It(`Returns 403 when user is not authorized`, func() { - - cosEndpointModel := &atrackerv1.CosEndpoint{ - Endpoint: core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud"), - TargetCRN: core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::"), - Bucket: core.StringPtr("my-atracker-bucket"), - APIKey: core.StringPtr("xxxxxxxxxxxxxx"), - } - - createTargetOptions := &atrackerv1.CreateTargetOptions{ - Name: core.StringPtr("my-cos-target"), - TargetType: core.StringPtr("cloud_object_storage"), - CosEndpoint: cosEndpointModel, - } - - _, response, err := atrackerServiceNotAuthorized.CreateTarget(createTargetOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(403)) - }) - - It(`CreateTarget(createTargetOptions *CreateTargetOptions)`, func() { - - cosEndpointModel := &atrackerv1.CosEndpoint{ - Endpoint: core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud"), - TargetCRN: core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::"), - Bucket: core.StringPtr("my-atracker-bucket"), - APIKey: core.StringPtr("xxxxxxxxxxxxxx"), - } - - createTargetOptions := &atrackerv1.CreateTargetOptions{ - Name: core.StringPtr("my-cos-target"), - TargetType: core.StringPtr("cloud_object_storage"), - CosEndpoint: cosEndpointModel, - } - - target, response, err := atrackerService.CreateTarget(createTargetOptions) - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(201)) - Expect(target).ToNot(BeNil()) - - targetIDLink = *target.ID - - }) - }) - - Describe(`ListTargets - List Cloud Object Storage targets for the region`, func() { - BeforeEach(func() { - shouldSkipTest() - }) - - It(`Returns 403 when user is not authorized`, func() { - - listTargetsOptions := &atrackerv1.ListTargetsOptions{} - - _, response, err := atrackerServiceNotAuthorized.ListTargets(listTargetsOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(403)) - }) - - It(`ListTargets(listTargetsOptions *ListTargetsOptions)`, func() { - - listTargetsOptions := &atrackerv1.ListTargetsOptions{} - - targetList, response, err := atrackerService.ListTargets(listTargetsOptions) - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(targetList).ToNot(BeNil()) - Expect(len(targetList.Targets)).To(BeNumerically(">", 0)) - - }) - }) - - Describe(`GetTarget - Retrieve a target`, func() { - BeforeEach(func() { - shouldSkipTest() - }) - - It(`Returns 403 when user is not authorized`, func() { - - getTargetOptions := &atrackerv1.GetTargetOptions{ - ID: core.StringPtr(targetIDLink), - } - - _, response, err := atrackerServiceNotAuthorized.GetTarget(getTargetOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(403)) - }) - - It(`Returns 404 when target id is not found`, func() { - - getTargetOptions := &atrackerv1.GetTargetOptions{ - ID: core.StringPtr(notFoundTargetID), - } - - _, response, err := atrackerService.GetTarget(getTargetOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(404)) - - }) - - It(`GetTarget(getTargetOptions *GetTargetOptions)`, func() { - - getTargetOptions := &atrackerv1.GetTargetOptions{ - ID: core.StringPtr(targetIDLink), - } - - target, response, err := atrackerService.GetTarget(getTargetOptions) - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(target).ToNot(BeNil()) - Expect(*target.Name).To(Equal("my-cos-target")) - - }) - }) - - Describe(`ReplaceTarget - Update a target`, func() { - BeforeEach(func() { - shouldSkipTest() - }) - - It(`Returns 403 when user is not authorized`, func() { - - cosEndpointModel := &atrackerv1.CosEndpoint{ - Endpoint: core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud"), - TargetCRN: core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::"), - Bucket: core.StringPtr("my-atracker-bucket"), - APIKey: core.StringPtr("xxxxxxxxxxxxxx"), - } - - replaceTargetOptions := &atrackerv1.ReplaceTargetOptions{ - ID: core.StringPtr(targetIDLink), - Name: core.StringPtr("my-cos-target-modified"), - TargetType: core.StringPtr("cloud_object_storage"), - CosEndpoint: cosEndpointModel, - } - - _, response, err := atrackerServiceNotAuthorized.ReplaceTarget(replaceTargetOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(403)) - }) - - It(`Returns 400 when target fields are not valid`, func() { - - cosEndpointModel := &atrackerv1.CosEndpoint{ - Endpoint: core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud"), - TargetCRN: core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::"), - Bucket: core.StringPtr("my-atracker-bucket"), - APIKey: core.StringPtr("xxxxxxxxxxxxxx"), - } - - replaceTargetOptions := &atrackerv1.ReplaceTargetOptions{ - ID: core.StringPtr(targetIDLink), - Name: core.StringPtr("my-cos-target-modified"), - TargetType: core.StringPtr(badTargetType), - CosEndpoint: cosEndpointModel, - } - _, response, err := atrackerService.ReplaceTarget(replaceTargetOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(400)) - - }) - - It(`Returns 404 when target id is not found`, func() { - - cosEndpointModel := &atrackerv1.CosEndpoint{ - Endpoint: core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud"), - TargetCRN: core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::"), - Bucket: core.StringPtr("my-atracker-bucket"), - APIKey: core.StringPtr("xxxxxxxxxxxxxx"), - } - - replaceTargetOptions := &atrackerv1.ReplaceTargetOptions{ - ID: core.StringPtr(notFoundTargetID), - Name: core.StringPtr("my-cos-target-modified"), - TargetType: core.StringPtr("cloud_object_storage"), - CosEndpoint: cosEndpointModel, - } - _, response, err := atrackerService.ReplaceTarget(replaceTargetOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(404)) - - }) - - It(`ReplaceTarget(replaceTargetOptions *ReplaceTargetOptions)`, func() { - - cosEndpointModel := &atrackerv1.CosEndpoint{ - Endpoint: core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud"), - TargetCRN: core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::"), - Bucket: core.StringPtr("my-atracker-bucket"), - APIKey: core.StringPtr("xxxxxxxxxxxxxx"), - } - - replaceTargetOptions := &atrackerv1.ReplaceTargetOptions{ - ID: core.StringPtr(targetIDLink), - Name: core.StringPtr("my-cos-target-modified"), - TargetType: core.StringPtr("cloud_object_storage"), - CosEndpoint: cosEndpointModel, - } - - target, response, err := atrackerService.ReplaceTarget(replaceTargetOptions) - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(target).ToNot(BeNil()) - Expect(*target.Name).To(Equal("my-cos-target-modified")) - - }) - }) - - Describe(`ValidateTarget - Update a target with cos validation results`, func() { - BeforeEach(func() { - shouldSkipTest() - }) - - It(`Returns 403 when user is not authorized`, func() { - - validateTargetOptions := &atrackerv1.ValidateTargetOptions{ - ID: core.StringPtr(targetIDLink), - } - - _, response, err := atrackerServiceNotAuthorized.ValidateTarget(validateTargetOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(403)) - }) - - It(`Returns 404 when target id is not found`, func() { - - validateTargetOptions := &atrackerv1.ValidateTargetOptions{ - ID: core.StringPtr(notFoundTargetID), - } - - _, response, err := atrackerService.ValidateTarget(validateTargetOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(404)) - - }) - - It(`ValidateTarget(validateTargetOptions *ValidateTargetOptions)`, func() { - - validateTargetOptions := &atrackerv1.ValidateTargetOptions{ - ID: core.StringPtr(targetIDLink), - } - - target, response, err := atrackerService.ValidateTarget(validateTargetOptions) - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(target).ToNot(BeNil()) - }) - - }) - - Describe(`CreateRoute - Create a Route for the region`, func() { - BeforeEach(func() { - shouldSkipTest() - }) - - It(`Returns 403 when user is not authorized`, func() { - - ruleModel := &atrackerv1.Rule{ - TargetIds: []string{targetIDLink}, - } - - createRouteOptions := &atrackerv1.CreateRouteOptions{ - Name: core.StringPtr("my-route"), - ReceiveGlobalEvents: core.BoolPtr(false), - Rules: []atrackerv1.Rule{*ruleModel}, - } - - _, response, err := atrackerServiceNotAuthorized.CreateRoute(createRouteOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(403)) - }) - - It(`Returns 400 when input validation fails`, func() { - - ruleModel := &atrackerv1.Rule{ - TargetIds: []string{notFoundTargetID}, - } - - createRouteOptions := &atrackerv1.CreateRouteOptions{ - Name: core.StringPtr("my-route"), - ReceiveGlobalEvents: core.BoolPtr(false), - Rules: []atrackerv1.Rule{*ruleModel}, - } - - _, response, err := atrackerService.CreateRoute(createRouteOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(400)) - - }) - - It(`CreateRoute(createRouteOptions *CreateRouteOptions)`, func() { - - ruleModel := &atrackerv1.Rule{ - TargetIds: []string{targetIDLink}, - } - - createRouteOptions := &atrackerv1.CreateRouteOptions{ - Name: core.StringPtr("my-route"), - ReceiveGlobalEvents: core.BoolPtr(false), - Rules: []atrackerv1.Rule{*ruleModel}, - } - - route, response, err := atrackerService.CreateRoute(createRouteOptions) - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(201)) - Expect(route).ToNot(BeNil()) - - routeIDLink = *route.ID - - }) - }) - - Describe(`ListRoutes - List routes for the region`, func() { - BeforeEach(func() { - shouldSkipTest() - }) - - It(`Returns 403 when user is not authorized`, func() { - - listRoutesOptions := &atrackerv1.ListRoutesOptions{} - - _, response, err := atrackerServiceNotAuthorized.ListRoutes(listRoutesOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(403)) - }) - - It(`ListRoutes(listRoutesOptions *ListRoutesOptions)`, func() { - - listRoutesOptions := &atrackerv1.ListRoutesOptions{} - - routeList, response, err := atrackerService.ListRoutes(listRoutesOptions) - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(routeList).ToNot(BeNil()) - Expect(len(routeList.Routes)).To(BeNumerically(">", 0)) - - }) - }) - - Describe(`GetRoute - Retrieve a route`, func() { - BeforeEach(func() { - shouldSkipTest() - }) - - It(`Returns 403 when user is not authorized`, func() { - - getRouteOptions := &atrackerv1.GetRouteOptions{ - ID: core.StringPtr(routeIDLink), - } - - _, response, err := atrackerServiceNotAuthorized.GetRoute(getRouteOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(403)) - }) - - It(`Returns 404 when route id is not found`, func() { - - getRouteOptions := &atrackerv1.GetRouteOptions{ - ID: core.StringPtr(notFoundRouteID), - } - - _, response, err := atrackerService.GetRoute(getRouteOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(404)) - - }) - - It(`GetRoute(getRouteOptions *GetRouteOptions)`, func() { - - getRouteOptions := &atrackerv1.GetRouteOptions{ - ID: core.StringPtr(routeIDLink), - } - - route, response, err := atrackerService.GetRoute(getRouteOptions) - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(route).ToNot(BeNil()) - Expect(*route.Name).To(Equal("my-route")) - - }) - }) - - Describe(`ReplaceRoute - Replace a route`, func() { - BeforeEach(func() { - shouldSkipTest() - }) - - It(`Returns 403 when user is not authorized`, func() { - - ruleModel := &atrackerv1.Rule{ - TargetIds: []string{targetIDLink}, - } - - replaceRouteOptions := &atrackerv1.ReplaceRouteOptions{ - ID: core.StringPtr(routeIDLink), - Name: core.StringPtr("my-route-modified"), - ReceiveGlobalEvents: core.BoolPtr(false), - Rules: []atrackerv1.Rule{*ruleModel}, - } - - _, response, err := atrackerServiceNotAuthorized.ReplaceRoute(replaceRouteOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(403)) - }) - - It(`Returns 404 when route id is not found`, func() { - - ruleModel := &atrackerv1.Rule{ - TargetIds: []string{targetIDLink}, - } - - replaceRouteOptions := &atrackerv1.ReplaceRouteOptions{ - ID: core.StringPtr(notFoundRouteID), - Name: core.StringPtr("my-route-modified"), - ReceiveGlobalEvents: core.BoolPtr(false), - Rules: []atrackerv1.Rule{*ruleModel}, - } - - _, response, err := atrackerService.ReplaceRoute(replaceRouteOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(404)) - - }) - - It(`ReplaceRoute(replaceRouteOptions *ReplaceRouteOptions)`, func() { - - ruleModel := &atrackerv1.Rule{ - TargetIds: []string{targetIDLink}, - } - - replaceRouteOptions := &atrackerv1.ReplaceRouteOptions{ - ID: core.StringPtr(routeIDLink), - Name: core.StringPtr("my-route-modified"), - ReceiveGlobalEvents: core.BoolPtr(false), - Rules: []atrackerv1.Rule{*ruleModel}, - } - - route, response, err := atrackerService.ReplaceRoute(replaceRouteOptions) - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(route).ToNot(BeNil()) - Expect(*route.Name).To(Equal("my-route-modified")) - - }) - }) - - Describe(`DeleteRoute - Delete a route`, func() { - BeforeEach(func() { - shouldSkipTest() - }) - - It(`Returns 403 when user is not authorized`, func() { - - deleteRouteOptions := &atrackerv1.DeleteRouteOptions{ - ID: core.StringPtr(routeIDLink), - } - - response, err := atrackerServiceNotAuthorized.DeleteRoute(deleteRouteOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(403)) - }) - - It(`Returns 404 when route id is not found`, func() { - - deleteRouteOptions := &atrackerv1.DeleteRouteOptions{ - ID: core.StringPtr(notFoundRouteID), - } - - response, err := atrackerService.DeleteRoute(deleteRouteOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(404)) - - }) - - It(`DeleteRoute(deleteRouteOptions *DeleteRouteOptions)`, func() { - - deleteRouteOptions := &atrackerv1.DeleteRouteOptions{ - ID: core.StringPtr(routeIDLink), - } - - response, err := atrackerService.DeleteRoute(deleteRouteOptions) - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(204)) - - }) - }) - - Describe(`DeleteTarget - Delete a target`, func() { - BeforeEach(func() { - shouldSkipTest() - }) - - It(`Returns 403 when user is not authorized`, func() { - - deleteTargetOptions := &atrackerv1.DeleteTargetOptions{ - ID: core.StringPtr(targetIDLink), - } - - _, response, err := atrackerServiceNotAuthorized.DeleteTarget(deleteTargetOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(403)) - }) - - It(`Returns 404 when target id is not found`, func() { - - deleteTargetOptions := &atrackerv1.DeleteTargetOptions{ - ID: core.StringPtr(notFoundTargetID), - } - - _, response, err := atrackerService.DeleteTarget(deleteTargetOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(404)) - - }) - - It(`DeleteTarget(deleteTargetOptions *DeleteTargetOptions)`, func() { - - deleteTargetOptions := &atrackerv1.DeleteTargetOptions{ - ID: core.StringPtr(targetIDLink), - } - - warningReport, response, err := atrackerService.DeleteTarget(deleteTargetOptions) - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(warningReport).ToNot(BeNil()) - - }) - }) - - Describe(`GetEndpoints - Get endpoints`, func() { - BeforeEach(func() { - shouldSkipTest() - }) - - It(`Returns 403 when user is not authorized`, func() { - - getEndpointsOptions := &atrackerv1.GetEndpointsOptions{} - - _, response, err := atrackerServiceNotAuthorized.GetEndpoints(getEndpointsOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(403)) - }) - - It(`GetEndpoints(getEndpointsOptions *GetEndpointsOptions)`, func() { - - getEndpointsOptions := &atrackerv1.GetEndpointsOptions{} - - endpoints, response, err := atrackerService.GetEndpoints(getEndpointsOptions) - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(endpoints).ToNot(BeNil()) - // more validations - Expect(endpoints.APIEndpoint.PublicURL).ToNot(BeNil()) - Expect(endpoints.APIEndpoint.PrivateURL).ToNot(BeNil()) - Expect(*endpoints.APIEndpoint.PrivateEnabled).To(Equal(true)) - }) - }) - - Describe(`PatchEndpoints - Modify endpoints`, func() { - BeforeEach(func() { - shouldSkipTest() - }) - - It(`Returns 403 when user is not authorized`, func() { - - endpointsRequestAPIEndpointModel := &atrackerv1.EndpointsRequestAPIEndpoint{ - PublicEnabled: core.BoolPtr(true), - } - - patchEndpointsOptions := &atrackerv1.PatchEndpointsOptions{ - APIEndpoint: endpointsRequestAPIEndpointModel, - } - - _, response, err := atrackerServiceNotAuthorized.PatchEndpoints(patchEndpointsOptions) - - Expect(err).NotTo(BeNil()) - Expect(response.StatusCode).To(Equal(403)) - }) - - It(`PatchEndpoints(patchEndpointsOptions *PatchEndpointsOptions)`, func() { - - endpointsRequestAPIEndpointModel := &atrackerv1.EndpointsRequestAPIEndpoint{ - PublicEnabled: core.BoolPtr(true), - } - - patchEndpointsOptions := &atrackerv1.PatchEndpointsOptions{ - APIEndpoint: endpointsRequestAPIEndpointModel, - } - - endpoints, response, err := atrackerService.PatchEndpoints(patchEndpointsOptions) - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(endpoints).ToNot(BeNil()) - Expect(endpoints.APIEndpoint).ToNot(BeNil()) - // more validations - Expect(endpoints.APIEndpoint.PublicURL).ToNot(BeNil()) - Expect(endpoints.APIEndpoint.PrivateURL).ToNot(BeNil()) - Expect(*endpoints.APIEndpoint.PublicEnabled).To(Equal(true)) - Expect(*endpoints.APIEndpoint.PrivateEnabled).To(Equal(true)) - }) - }) - -}) - -// -// Utility functions are declared in the unit test file -// diff --git a/atrackerv1/atracker_v1_suite_test.go b/atrackerv1/atracker_v1_suite_test.go deleted file mode 100644 index cba7bb9e..00000000 --- a/atrackerv1/atracker_v1_suite_test.go +++ /dev/null @@ -1,29 +0,0 @@ -/** - * (C) Copyright IBM Corp. 2021. - * - * 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 atrackerv1_test - -import ( - "testing" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -func TestAtrackerV1(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "AtrackerV1 Suite") -} diff --git a/atrackerv1/atracker_v1_test.go b/atrackerv1/atracker_v1_test.go deleted file mode 100644 index 7f44cdb5..00000000 --- a/atrackerv1/atracker_v1_test.go +++ /dev/null @@ -1,3447 +0,0 @@ -/** - * (C) Copyright IBM Corp. 2021. - * - * 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 atrackerv1_test - -import ( - "bytes" - "context" - "fmt" - "io" - "net/http" - "net/http/httptest" - "os" - "time" - - "github.com/IBM/go-sdk-core/v5/core" - "github.com/IBM/platform-services-go-sdk/atrackerv1" - "github.com/go-openapi/strfmt" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -var _ = Describe(`AtrackerV1`, func() { - var testServer *httptest.Server - Describe(`Service constructor tests`, func() { - It(`Instantiate service client`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(atrackerService).ToNot(BeNil()) - Expect(serviceErr).To(BeNil()) - }) - It(`Instantiate service client with error: Invalid URL`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: "{BAD_URL_STRING", - }) - Expect(atrackerService).To(BeNil()) - Expect(serviceErr).ToNot(BeNil()) - }) - It(`Instantiate service client with error: Invalid Auth`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: "https://atrackerv1/api", - Authenticator: &core.BasicAuthenticator{ - Username: "", - Password: "", - }, - }) - Expect(atrackerService).To(BeNil()) - Expect(serviceErr).ToNot(BeNil()) - }) - }) - Describe(`Service constructor tests using external config`, func() { - Context(`Using external config, construct service client instances`, func() { - // Map containing environment variables used in testing. - var testEnvironment = map[string]string{ - "ATRACKER_URL": "https://atrackerv1/api", - "ATRACKER_AUTH_TYPE": "noauth", - } - - It(`Create service client using external config successfully`, func() { - SetTestEnvironment(testEnvironment) - atrackerService, serviceErr := atrackerv1.NewAtrackerV1UsingExternalConfig(&atrackerv1.AtrackerV1Options{ - }) - Expect(atrackerService).ToNot(BeNil()) - Expect(serviceErr).To(BeNil()) - ClearTestEnvironment(testEnvironment) - - clone := atrackerService.Clone() - Expect(clone).ToNot(BeNil()) - Expect(clone.Service != atrackerService.Service).To(BeTrue()) - Expect(clone.GetServiceURL()).To(Equal(atrackerService.GetServiceURL())) - Expect(clone.Service.Options.Authenticator).To(Equal(atrackerService.Service.Options.Authenticator)) - }) - It(`Create service client using external config and set url from constructor successfully`, func() { - SetTestEnvironment(testEnvironment) - atrackerService, serviceErr := atrackerv1.NewAtrackerV1UsingExternalConfig(&atrackerv1.AtrackerV1Options{ - URL: "https://testService/api", - }) - Expect(atrackerService).ToNot(BeNil()) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService.Service.GetServiceURL()).To(Equal("https://testService/api")) - ClearTestEnvironment(testEnvironment) - - clone := atrackerService.Clone() - Expect(clone).ToNot(BeNil()) - Expect(clone.Service != atrackerService.Service).To(BeTrue()) - Expect(clone.GetServiceURL()).To(Equal(atrackerService.GetServiceURL())) - Expect(clone.Service.Options.Authenticator).To(Equal(atrackerService.Service.Options.Authenticator)) - }) - It(`Create service client using external config and set url programatically successfully`, func() { - SetTestEnvironment(testEnvironment) - atrackerService, serviceErr := atrackerv1.NewAtrackerV1UsingExternalConfig(&atrackerv1.AtrackerV1Options{ - }) - err := atrackerService.SetServiceURL("https://testService/api") - Expect(err).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService.Service.GetServiceURL()).To(Equal("https://testService/api")) - ClearTestEnvironment(testEnvironment) - - clone := atrackerService.Clone() - Expect(clone).ToNot(BeNil()) - Expect(clone.Service != atrackerService.Service).To(BeTrue()) - Expect(clone.GetServiceURL()).To(Equal(atrackerService.GetServiceURL())) - Expect(clone.Service.Options.Authenticator).To(Equal(atrackerService.Service.Options.Authenticator)) - }) - }) - Context(`Using external config, construct service client instances with error: Invalid Auth`, func() { - // Map containing environment variables used in testing. - var testEnvironment = map[string]string{ - "ATRACKER_URL": "https://atrackerv1/api", - "ATRACKER_AUTH_TYPE": "someOtherAuth", - } - - SetTestEnvironment(testEnvironment) - atrackerService, serviceErr := atrackerv1.NewAtrackerV1UsingExternalConfig(&atrackerv1.AtrackerV1Options{ - }) - - It(`Instantiate service client with error`, func() { - Expect(atrackerService).To(BeNil()) - Expect(serviceErr).ToNot(BeNil()) - ClearTestEnvironment(testEnvironment) - }) - }) - Context(`Using external config, construct service client instances with error: Invalid URL`, func() { - // Map containing environment variables used in testing. - var testEnvironment = map[string]string{ - "ATRACKER_AUTH_TYPE": "NOAuth", - } - - SetTestEnvironment(testEnvironment) - atrackerService, serviceErr := atrackerv1.NewAtrackerV1UsingExternalConfig(&atrackerv1.AtrackerV1Options{ - URL: "{BAD_URL_STRING", - }) - - It(`Instantiate service client with error`, func() { - Expect(atrackerService).To(BeNil()) - Expect(serviceErr).ToNot(BeNil()) - ClearTestEnvironment(testEnvironment) - }) - }) - }) - Describe(`Regional endpoint tests`, func() { - It(`GetServiceURLForRegion(region string)`, func() { - var url string - var err error - url, err = atrackerv1.GetServiceURLForRegion("us-south") - Expect(url).To(Equal("https://us-south.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("private.us-south") - Expect(url).To(Equal("https://private.us-south.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("us-east") - Expect(url).To(Equal("https://us-east.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("private.us-east") - Expect(url).To(Equal("https://private.us-east.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("eu-de") - Expect(url).To(Equal("https://eu-de.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("private.eu-de") - Expect(url).To(Equal("https://private.eu-de.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("eu-gb") - Expect(url).To(Equal("https://eu-gb.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("private.eu-gb") - Expect(url).To(Equal("https://private.eu-gb.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("au-syd") - Expect(url).To(Equal("https://au-syd.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("private.au-syd") - Expect(url).To(Equal("https://private.au-syd.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("ca-tor") - Expect(url).To(Equal("https://us-east.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("private.ca-tor") - Expect(url).To(Equal("https://private.us-east.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("br-sao") - Expect(url).To(Equal("https://us-south.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("private.br-sao") - Expect(url).To(Equal("https://private.us-south.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("eu-fr2") - Expect(url).To(Equal("https://eu-de.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("private.eu-fr2") - Expect(url).To(Equal("https://private.eu-de.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("jp-tok") - Expect(url).To(Equal("https://eu-de.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("private.jp-tok") - Expect(url).To(Equal("https://private.eu-de.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("jp-osa") - Expect(url).To(Equal("https://eu-de.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("private.jp-osa") - Expect(url).To(Equal("https://private.eu-de.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("in-che") - Expect(url).To(Equal("https://eu-de.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("private.in-che") - Expect(url).To(Equal("https://private.eu-de.atracker.cloud.ibm.com")) - Expect(err).To(BeNil()) - - url, err = atrackerv1.GetServiceURLForRegion("INVALID_REGION") - Expect(url).To(BeEmpty()) - Expect(err).ToNot(BeNil()) - fmt.Fprintf(GinkgoWriter, "Expected error: %s\n", err.Error()) - }) - }) - Describe(`CreateTarget(createTargetOptions *CreateTargetOptions) - Operation response error`, func() { - createTargetPath := "/api/v1/targets" - Context(`Using mock server endpoint with invalid JSON response`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(createTargetPath)) - Expect(req.Method).To(Equal("POST")) - res.Header().Set("Content-type", "application/json") - res.WriteHeader(201) - fmt.Fprintf(res, `} this is not valid json {`) - })) - }) - It(`Invoke CreateTarget with error: Operation response processing error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the CosEndpoint model - cosEndpointModel := new(atrackerv1.CosEndpoint) - cosEndpointModel.Endpoint = core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud") - cosEndpointModel.TargetCRN = core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::") - cosEndpointModel.Bucket = core.StringPtr("my-atracker-bucket") - cosEndpointModel.APIKey = core.StringPtr("xxxxxxxxxxxxxx") - - // Construct an instance of the CreateTargetOptions model - createTargetOptionsModel := new(atrackerv1.CreateTargetOptions) - createTargetOptionsModel.Name = core.StringPtr("my-cos-target") - createTargetOptionsModel.TargetType = core.StringPtr("cloud_object_storage") - createTargetOptionsModel.CosEndpoint = cosEndpointModel - createTargetOptionsModel.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 := atrackerService.CreateTarget(createTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - - // Enable retries and test again - atrackerService.EnableRetries(0, 0) - result, response, operationErr = atrackerService.CreateTarget(createTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`CreateTarget(createTargetOptions *CreateTargetOptions)`, func() { - createTargetPath := "/api/v1/targets" - Context(`Using mock server endpoint with timeout`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(createTargetPath)) - Expect(req.Method).To(Equal("POST")) - - // For gzip-disabled operation, verify Content-Encoding is not set. - Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) - - // If there is a body, then make sure we can read it - bodyBuf := new(bytes.Buffer) - if req.Header.Get("Content-Encoding") == "gzip" { - body, err := core.NewGzipDecompressionReader(req.Body) - Expect(err).To(BeNil()) - _, err = bodyBuf.ReadFrom(body) - Expect(err).To(BeNil()) - } else { - _, err := bodyBuf.ReadFrom(req.Body) - Expect(err).To(BeNil()) - } - fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) - - // Sleep a short time to support a timeout test - time.Sleep(100 * time.Millisecond) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(201) - fmt.Fprintf(res, "%s", `{"id": "f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "name": "a-cos-target-us-south", "crn": "crn:v1:bluemix:public:atracker:us-south:a/11111111111111111111111111111111:b6eec08b-5201-08ca-451b-cd71523e3626:target:f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "target_type": "cloud_object_storage", "encrypt_key": "REDACTED", "cos_endpoint": {"endpoint": "s3.private.us-east.cloud-object-storage.appdomain.cloud", "target_crn": "crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::", "bucket": "my-atracker-bucket", "api_key": "xxxxxxxxxxxxxx"}, "cos_write_status": {"status": "success", "last_failure": "2021-05-18T20:15:12.353Z", "reason_for_last_failure": "Provided API key could not be found"}, "created": "2021-05-18T20:15:12.353Z", "updated": "2021-05-18T20:15:12.353Z"}`) - })) - }) - It(`Invoke CreateTarget successfully with retries`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - atrackerService.EnableRetries(0, 0) - - // Construct an instance of the CosEndpoint model - cosEndpointModel := new(atrackerv1.CosEndpoint) - cosEndpointModel.Endpoint = core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud") - cosEndpointModel.TargetCRN = core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::") - cosEndpointModel.Bucket = core.StringPtr("my-atracker-bucket") - cosEndpointModel.APIKey = core.StringPtr("xxxxxxxxxxxxxx") - - // Construct an instance of the CreateTargetOptions model - createTargetOptionsModel := new(atrackerv1.CreateTargetOptions) - createTargetOptionsModel.Name = core.StringPtr("my-cos-target") - createTargetOptionsModel.TargetType = core.StringPtr("cloud_object_storage") - createTargetOptionsModel.CosEndpoint = cosEndpointModel - createTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with a Context to test a timeout error - ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc() - _, _, operationErr := atrackerService.CreateTargetWithContext(ctx, createTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - - // Disable retries and test again - atrackerService.DisableRetries() - result, response, operationErr := atrackerService.CreateTarget(createTargetOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - // Re-test the timeout error with retries disabled - ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc2() - _, _, operationErr = atrackerService.CreateTargetWithContext(ctx, createTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(createTargetPath)) - Expect(req.Method).To(Equal("POST")) - - // For gzip-disabled operation, verify Content-Encoding is not set. - Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) - - // If there is a body, then make sure we can read it - bodyBuf := new(bytes.Buffer) - if req.Header.Get("Content-Encoding") == "gzip" { - body, err := core.NewGzipDecompressionReader(req.Body) - Expect(err).To(BeNil()) - _, err = bodyBuf.ReadFrom(body) - Expect(err).To(BeNil()) - } else { - _, err := bodyBuf.ReadFrom(req.Body) - Expect(err).To(BeNil()) - } - fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(201) - fmt.Fprintf(res, "%s", `{"id": "f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "name": "a-cos-target-us-south", "crn": "crn:v1:bluemix:public:atracker:us-south:a/11111111111111111111111111111111:b6eec08b-5201-08ca-451b-cd71523e3626:target:f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "target_type": "cloud_object_storage", "encrypt_key": "REDACTED", "cos_endpoint": {"endpoint": "s3.private.us-east.cloud-object-storage.appdomain.cloud", "target_crn": "crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::", "bucket": "my-atracker-bucket", "api_key": "xxxxxxxxxxxxxx"}, "cos_write_status": {"status": "success", "last_failure": "2021-05-18T20:15:12.353Z", "reason_for_last_failure": "Provided API key could not be found"}, "created": "2021-05-18T20:15:12.353Z", "updated": "2021-05-18T20:15:12.353Z"}`) - })) - }) - It(`Invoke CreateTarget successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Invoke operation with nil options model (negative test) - result, response, operationErr := atrackerService.CreateTarget(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - - // Construct an instance of the CosEndpoint model - cosEndpointModel := new(atrackerv1.CosEndpoint) - cosEndpointModel.Endpoint = core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud") - cosEndpointModel.TargetCRN = core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::") - cosEndpointModel.Bucket = core.StringPtr("my-atracker-bucket") - cosEndpointModel.APIKey = core.StringPtr("xxxxxxxxxxxxxx") - - // Construct an instance of the CreateTargetOptions model - createTargetOptionsModel := new(atrackerv1.CreateTargetOptions) - createTargetOptionsModel.Name = core.StringPtr("my-cos-target") - createTargetOptionsModel.TargetType = core.StringPtr("cloud_object_storage") - createTargetOptionsModel.CosEndpoint = cosEndpointModel - createTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with valid options model (positive test) - result, response, operationErr = atrackerService.CreateTarget(createTargetOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - }) - It(`Invoke CreateTarget with error: Operation validation and request error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the CosEndpoint model - cosEndpointModel := new(atrackerv1.CosEndpoint) - cosEndpointModel.Endpoint = core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud") - cosEndpointModel.TargetCRN = core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::") - cosEndpointModel.Bucket = core.StringPtr("my-atracker-bucket") - cosEndpointModel.APIKey = core.StringPtr("xxxxxxxxxxxxxx") - - // Construct an instance of the CreateTargetOptions model - createTargetOptionsModel := new(atrackerv1.CreateTargetOptions) - createTargetOptionsModel.Name = core.StringPtr("my-cos-target") - createTargetOptionsModel.TargetType = core.StringPtr("cloud_object_storage") - createTargetOptionsModel.CosEndpoint = cosEndpointModel - createTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with empty URL (negative test) - err := atrackerService.SetServiceURL("") - Expect(err).To(BeNil()) - result, response, operationErr := atrackerService.CreateTarget(createTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - // Construct a second instance of the CreateTargetOptions model with no property values - createTargetOptionsModelNew := new(atrackerv1.CreateTargetOptions) - // Invoke operation with invalid model (negative test) - result, response, operationErr = atrackerService.CreateTarget(createTargetOptionsModelNew) - Expect(operationErr).ToNot(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint with missing response body`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Set success status code with no respoonse body - res.WriteHeader(201) - })) - }) - It(`Invoke CreateTarget successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the CosEndpoint model - cosEndpointModel := new(atrackerv1.CosEndpoint) - cosEndpointModel.Endpoint = core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud") - cosEndpointModel.TargetCRN = core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::") - cosEndpointModel.Bucket = core.StringPtr("my-atracker-bucket") - cosEndpointModel.APIKey = core.StringPtr("xxxxxxxxxxxxxx") - - // Construct an instance of the CreateTargetOptions model - createTargetOptionsModel := new(atrackerv1.CreateTargetOptions) - createTargetOptionsModel.Name = core.StringPtr("my-cos-target") - createTargetOptionsModel.TargetType = core.StringPtr("cloud_object_storage") - createTargetOptionsModel.CosEndpoint = cosEndpointModel - createTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation - result, response, operationErr := atrackerService.CreateTarget(createTargetOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - - // Verify a nil result - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`ListTargets(listTargetsOptions *ListTargetsOptions) - Operation response error`, func() { - listTargetsPath := "/api/v1/targets" - Context(`Using mock server endpoint with invalid JSON response`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(listTargetsPath)) - Expect(req.Method).To(Equal("GET")) - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, `} this is not valid json {`) - })) - }) - It(`Invoke ListTargets with error: Operation response processing error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the ListTargetsOptions model - listTargetsOptionsModel := new(atrackerv1.ListTargetsOptions) - listTargetsOptionsModel.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 := atrackerService.ListTargets(listTargetsOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - - // Enable retries and test again - atrackerService.EnableRetries(0, 0) - result, response, operationErr = atrackerService.ListTargets(listTargetsOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`ListTargets(listTargetsOptions *ListTargetsOptions)`, func() { - listTargetsPath := "/api/v1/targets" - Context(`Using mock server endpoint with timeout`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(listTargetsPath)) - Expect(req.Method).To(Equal("GET")) - - // Sleep a short time to support a timeout test - time.Sleep(100 * time.Millisecond) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"targets": [{"id": "f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "name": "a-cos-target-us-south", "crn": "crn:v1:bluemix:public:atracker:us-south:a/11111111111111111111111111111111:b6eec08b-5201-08ca-451b-cd71523e3626:target:f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "target_type": "cloud_object_storage", "encrypt_key": "REDACTED", "cos_endpoint": {"endpoint": "s3.private.us-east.cloud-object-storage.appdomain.cloud", "target_crn": "crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::", "bucket": "my-atracker-bucket", "api_key": "xxxxxxxxxxxxxx"}, "cos_write_status": {"status": "success", "last_failure": "2021-05-18T20:15:12.353Z", "reason_for_last_failure": "Provided API key could not be found"}, "created": "2021-05-18T20:15:12.353Z", "updated": "2021-05-18T20:15:12.353Z"}]}`) - })) - }) - It(`Invoke ListTargets successfully with retries`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - atrackerService.EnableRetries(0, 0) - - // Construct an instance of the ListTargetsOptions model - listTargetsOptionsModel := new(atrackerv1.ListTargetsOptions) - listTargetsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with a Context to test a timeout error - ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc() - _, _, operationErr := atrackerService.ListTargetsWithContext(ctx, listTargetsOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - - // Disable retries and test again - atrackerService.DisableRetries() - result, response, operationErr := atrackerService.ListTargets(listTargetsOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - // Re-test the timeout error with retries disabled - ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc2() - _, _, operationErr = atrackerService.ListTargetsWithContext(ctx, listTargetsOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(listTargetsPath)) - Expect(req.Method).To(Equal("GET")) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"targets": [{"id": "f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "name": "a-cos-target-us-south", "crn": "crn:v1:bluemix:public:atracker:us-south:a/11111111111111111111111111111111:b6eec08b-5201-08ca-451b-cd71523e3626:target:f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "target_type": "cloud_object_storage", "encrypt_key": "REDACTED", "cos_endpoint": {"endpoint": "s3.private.us-east.cloud-object-storage.appdomain.cloud", "target_crn": "crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::", "bucket": "my-atracker-bucket", "api_key": "xxxxxxxxxxxxxx"}, "cos_write_status": {"status": "success", "last_failure": "2021-05-18T20:15:12.353Z", "reason_for_last_failure": "Provided API key could not be found"}, "created": "2021-05-18T20:15:12.353Z", "updated": "2021-05-18T20:15:12.353Z"}]}`) - })) - }) - It(`Invoke ListTargets successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Invoke operation with nil options model (negative test) - result, response, operationErr := atrackerService.ListTargets(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - - // Construct an instance of the ListTargetsOptions model - listTargetsOptionsModel := new(atrackerv1.ListTargetsOptions) - listTargetsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with valid options model (positive test) - result, response, operationErr = atrackerService.ListTargets(listTargetsOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - }) - It(`Invoke ListTargets with error: Operation request error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the ListTargetsOptions model - listTargetsOptionsModel := new(atrackerv1.ListTargetsOptions) - listTargetsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with empty URL (negative test) - err := atrackerService.SetServiceURL("") - Expect(err).To(BeNil()) - result, response, operationErr := atrackerService.ListTargets(listTargetsOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint with missing response body`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Set success status code with no respoonse body - res.WriteHeader(200) - })) - }) - It(`Invoke ListTargets successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the ListTargetsOptions model - listTargetsOptionsModel := new(atrackerv1.ListTargetsOptions) - listTargetsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation - result, response, operationErr := atrackerService.ListTargets(listTargetsOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - - // Verify a nil result - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`GetTarget(getTargetOptions *GetTargetOptions) - Operation response error`, func() { - getTargetPath := "/api/v1/targets/testString" - Context(`Using mock server endpoint with invalid JSON response`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(getTargetPath)) - Expect(req.Method).To(Equal("GET")) - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, `} this is not valid json {`) - })) - }) - It(`Invoke GetTarget with error: Operation response processing error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the GetTargetOptions model - getTargetOptionsModel := new(atrackerv1.GetTargetOptions) - getTargetOptionsModel.ID = core.StringPtr("testString") - getTargetOptionsModel.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 := atrackerService.GetTarget(getTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - - // Enable retries and test again - atrackerService.EnableRetries(0, 0) - result, response, operationErr = atrackerService.GetTarget(getTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`GetTarget(getTargetOptions *GetTargetOptions)`, func() { - getTargetPath := "/api/v1/targets/testString" - Context(`Using mock server endpoint with timeout`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(getTargetPath)) - Expect(req.Method).To(Equal("GET")) - - // Sleep a short time to support a timeout test - time.Sleep(100 * time.Millisecond) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "name": "a-cos-target-us-south", "crn": "crn:v1:bluemix:public:atracker:us-south:a/11111111111111111111111111111111:b6eec08b-5201-08ca-451b-cd71523e3626:target:f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "target_type": "cloud_object_storage", "encrypt_key": "REDACTED", "cos_endpoint": {"endpoint": "s3.private.us-east.cloud-object-storage.appdomain.cloud", "target_crn": "crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::", "bucket": "my-atracker-bucket", "api_key": "xxxxxxxxxxxxxx"}, "cos_write_status": {"status": "success", "last_failure": "2021-05-18T20:15:12.353Z", "reason_for_last_failure": "Provided API key could not be found"}, "created": "2021-05-18T20:15:12.353Z", "updated": "2021-05-18T20:15:12.353Z"}`) - })) - }) - It(`Invoke GetTarget successfully with retries`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - atrackerService.EnableRetries(0, 0) - - // Construct an instance of the GetTargetOptions model - getTargetOptionsModel := new(atrackerv1.GetTargetOptions) - getTargetOptionsModel.ID = core.StringPtr("testString") - getTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with a Context to test a timeout error - ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc() - _, _, operationErr := atrackerService.GetTargetWithContext(ctx, getTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - - // Disable retries and test again - atrackerService.DisableRetries() - result, response, operationErr := atrackerService.GetTarget(getTargetOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - // Re-test the timeout error with retries disabled - ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc2() - _, _, operationErr = atrackerService.GetTargetWithContext(ctx, getTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(getTargetPath)) - Expect(req.Method).To(Equal("GET")) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "name": "a-cos-target-us-south", "crn": "crn:v1:bluemix:public:atracker:us-south:a/11111111111111111111111111111111:b6eec08b-5201-08ca-451b-cd71523e3626:target:f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "target_type": "cloud_object_storage", "encrypt_key": "REDACTED", "cos_endpoint": {"endpoint": "s3.private.us-east.cloud-object-storage.appdomain.cloud", "target_crn": "crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::", "bucket": "my-atracker-bucket", "api_key": "xxxxxxxxxxxxxx"}, "cos_write_status": {"status": "success", "last_failure": "2021-05-18T20:15:12.353Z", "reason_for_last_failure": "Provided API key could not be found"}, "created": "2021-05-18T20:15:12.353Z", "updated": "2021-05-18T20:15:12.353Z"}`) - })) - }) - It(`Invoke GetTarget successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Invoke operation with nil options model (negative test) - result, response, operationErr := atrackerService.GetTarget(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - - // Construct an instance of the GetTargetOptions model - getTargetOptionsModel := new(atrackerv1.GetTargetOptions) - getTargetOptionsModel.ID = core.StringPtr("testString") - getTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with valid options model (positive test) - result, response, operationErr = atrackerService.GetTarget(getTargetOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - }) - It(`Invoke GetTarget with error: Operation validation and request error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the GetTargetOptions model - getTargetOptionsModel := new(atrackerv1.GetTargetOptions) - getTargetOptionsModel.ID = core.StringPtr("testString") - getTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with empty URL (negative test) - err := atrackerService.SetServiceURL("") - Expect(err).To(BeNil()) - result, response, operationErr := atrackerService.GetTarget(getTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - // Construct a second instance of the GetTargetOptions model with no property values - getTargetOptionsModelNew := new(atrackerv1.GetTargetOptions) - // Invoke operation with invalid model (negative test) - result, response, operationErr = atrackerService.GetTarget(getTargetOptionsModelNew) - Expect(operationErr).ToNot(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint with missing response body`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Set success status code with no respoonse body - res.WriteHeader(200) - })) - }) - It(`Invoke GetTarget successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the GetTargetOptions model - getTargetOptionsModel := new(atrackerv1.GetTargetOptions) - getTargetOptionsModel.ID = core.StringPtr("testString") - getTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation - result, response, operationErr := atrackerService.GetTarget(getTargetOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - - // Verify a nil result - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`ReplaceTarget(replaceTargetOptions *ReplaceTargetOptions) - Operation response error`, func() { - replaceTargetPath := "/api/v1/targets/testString" - Context(`Using mock server endpoint with invalid JSON response`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(replaceTargetPath)) - Expect(req.Method).To(Equal("PUT")) - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, `} this is not valid json {`) - })) - }) - It(`Invoke ReplaceTarget with error: Operation response processing error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the CosEndpoint model - cosEndpointModel := new(atrackerv1.CosEndpoint) - cosEndpointModel.Endpoint = core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud") - cosEndpointModel.TargetCRN = core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::") - cosEndpointModel.Bucket = core.StringPtr("my-atracker-bucket") - cosEndpointModel.APIKey = core.StringPtr("xxxxxxxxxxxxxx") - - // Construct an instance of the ReplaceTargetOptions model - replaceTargetOptionsModel := new(atrackerv1.ReplaceTargetOptions) - replaceTargetOptionsModel.ID = core.StringPtr("testString") - replaceTargetOptionsModel.Name = core.StringPtr("my-cos-target") - replaceTargetOptionsModel.TargetType = core.StringPtr("cloud_object_storage") - replaceTargetOptionsModel.CosEndpoint = cosEndpointModel - replaceTargetOptionsModel.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 := atrackerService.ReplaceTarget(replaceTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - - // Enable retries and test again - atrackerService.EnableRetries(0, 0) - result, response, operationErr = atrackerService.ReplaceTarget(replaceTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`ReplaceTarget(replaceTargetOptions *ReplaceTargetOptions)`, func() { - replaceTargetPath := "/api/v1/targets/testString" - Context(`Using mock server endpoint with timeout`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(replaceTargetPath)) - Expect(req.Method).To(Equal("PUT")) - - // For gzip-disabled operation, verify Content-Encoding is not set. - Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) - - // If there is a body, then make sure we can read it - bodyBuf := new(bytes.Buffer) - if req.Header.Get("Content-Encoding") == "gzip" { - body, err := core.NewGzipDecompressionReader(req.Body) - Expect(err).To(BeNil()) - _, err = bodyBuf.ReadFrom(body) - Expect(err).To(BeNil()) - } else { - _, err := bodyBuf.ReadFrom(req.Body) - Expect(err).To(BeNil()) - } - fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) - - // Sleep a short time to support a timeout test - time.Sleep(100 * time.Millisecond) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "name": "a-cos-target-us-south", "crn": "crn:v1:bluemix:public:atracker:us-south:a/11111111111111111111111111111111:b6eec08b-5201-08ca-451b-cd71523e3626:target:f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "target_type": "cloud_object_storage", "encrypt_key": "REDACTED", "cos_endpoint": {"endpoint": "s3.private.us-east.cloud-object-storage.appdomain.cloud", "target_crn": "crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::", "bucket": "my-atracker-bucket", "api_key": "xxxxxxxxxxxxxx"}, "cos_write_status": {"status": "success", "last_failure": "2021-05-18T20:15:12.353Z", "reason_for_last_failure": "Provided API key could not be found"}, "created": "2021-05-18T20:15:12.353Z", "updated": "2021-05-18T20:15:12.353Z"}`) - })) - }) - It(`Invoke ReplaceTarget successfully with retries`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - atrackerService.EnableRetries(0, 0) - - // Construct an instance of the CosEndpoint model - cosEndpointModel := new(atrackerv1.CosEndpoint) - cosEndpointModel.Endpoint = core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud") - cosEndpointModel.TargetCRN = core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::") - cosEndpointModel.Bucket = core.StringPtr("my-atracker-bucket") - cosEndpointModel.APIKey = core.StringPtr("xxxxxxxxxxxxxx") - - // Construct an instance of the ReplaceTargetOptions model - replaceTargetOptionsModel := new(atrackerv1.ReplaceTargetOptions) - replaceTargetOptionsModel.ID = core.StringPtr("testString") - replaceTargetOptionsModel.Name = core.StringPtr("my-cos-target") - replaceTargetOptionsModel.TargetType = core.StringPtr("cloud_object_storage") - replaceTargetOptionsModel.CosEndpoint = cosEndpointModel - replaceTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with a Context to test a timeout error - ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc() - _, _, operationErr := atrackerService.ReplaceTargetWithContext(ctx, replaceTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - - // Disable retries and test again - atrackerService.DisableRetries() - result, response, operationErr := atrackerService.ReplaceTarget(replaceTargetOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - // Re-test the timeout error with retries disabled - ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc2() - _, _, operationErr = atrackerService.ReplaceTargetWithContext(ctx, replaceTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(replaceTargetPath)) - Expect(req.Method).To(Equal("PUT")) - - // For gzip-disabled operation, verify Content-Encoding is not set. - Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) - - // If there is a body, then make sure we can read it - bodyBuf := new(bytes.Buffer) - if req.Header.Get("Content-Encoding") == "gzip" { - body, err := core.NewGzipDecompressionReader(req.Body) - Expect(err).To(BeNil()) - _, err = bodyBuf.ReadFrom(body) - Expect(err).To(BeNil()) - } else { - _, err := bodyBuf.ReadFrom(req.Body) - Expect(err).To(BeNil()) - } - fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "name": "a-cos-target-us-south", "crn": "crn:v1:bluemix:public:atracker:us-south:a/11111111111111111111111111111111:b6eec08b-5201-08ca-451b-cd71523e3626:target:f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "target_type": "cloud_object_storage", "encrypt_key": "REDACTED", "cos_endpoint": {"endpoint": "s3.private.us-east.cloud-object-storage.appdomain.cloud", "target_crn": "crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::", "bucket": "my-atracker-bucket", "api_key": "xxxxxxxxxxxxxx"}, "cos_write_status": {"status": "success", "last_failure": "2021-05-18T20:15:12.353Z", "reason_for_last_failure": "Provided API key could not be found"}, "created": "2021-05-18T20:15:12.353Z", "updated": "2021-05-18T20:15:12.353Z"}`) - })) - }) - It(`Invoke ReplaceTarget successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Invoke operation with nil options model (negative test) - result, response, operationErr := atrackerService.ReplaceTarget(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - - // Construct an instance of the CosEndpoint model - cosEndpointModel := new(atrackerv1.CosEndpoint) - cosEndpointModel.Endpoint = core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud") - cosEndpointModel.TargetCRN = core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::") - cosEndpointModel.Bucket = core.StringPtr("my-atracker-bucket") - cosEndpointModel.APIKey = core.StringPtr("xxxxxxxxxxxxxx") - - // Construct an instance of the ReplaceTargetOptions model - replaceTargetOptionsModel := new(atrackerv1.ReplaceTargetOptions) - replaceTargetOptionsModel.ID = core.StringPtr("testString") - replaceTargetOptionsModel.Name = core.StringPtr("my-cos-target") - replaceTargetOptionsModel.TargetType = core.StringPtr("cloud_object_storage") - replaceTargetOptionsModel.CosEndpoint = cosEndpointModel - replaceTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with valid options model (positive test) - result, response, operationErr = atrackerService.ReplaceTarget(replaceTargetOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - }) - It(`Invoke ReplaceTarget with error: Operation validation and request error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the CosEndpoint model - cosEndpointModel := new(atrackerv1.CosEndpoint) - cosEndpointModel.Endpoint = core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud") - cosEndpointModel.TargetCRN = core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::") - cosEndpointModel.Bucket = core.StringPtr("my-atracker-bucket") - cosEndpointModel.APIKey = core.StringPtr("xxxxxxxxxxxxxx") - - // Construct an instance of the ReplaceTargetOptions model - replaceTargetOptionsModel := new(atrackerv1.ReplaceTargetOptions) - replaceTargetOptionsModel.ID = core.StringPtr("testString") - replaceTargetOptionsModel.Name = core.StringPtr("my-cos-target") - replaceTargetOptionsModel.TargetType = core.StringPtr("cloud_object_storage") - replaceTargetOptionsModel.CosEndpoint = cosEndpointModel - replaceTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with empty URL (negative test) - err := atrackerService.SetServiceURL("") - Expect(err).To(BeNil()) - result, response, operationErr := atrackerService.ReplaceTarget(replaceTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - // Construct a second instance of the ReplaceTargetOptions model with no property values - replaceTargetOptionsModelNew := new(atrackerv1.ReplaceTargetOptions) - // Invoke operation with invalid model (negative test) - result, response, operationErr = atrackerService.ReplaceTarget(replaceTargetOptionsModelNew) - Expect(operationErr).ToNot(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint with missing response body`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Set success status code with no respoonse body - res.WriteHeader(200) - })) - }) - It(`Invoke ReplaceTarget successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the CosEndpoint model - cosEndpointModel := new(atrackerv1.CosEndpoint) - cosEndpointModel.Endpoint = core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud") - cosEndpointModel.TargetCRN = core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::") - cosEndpointModel.Bucket = core.StringPtr("my-atracker-bucket") - cosEndpointModel.APIKey = core.StringPtr("xxxxxxxxxxxxxx") - - // Construct an instance of the ReplaceTargetOptions model - replaceTargetOptionsModel := new(atrackerv1.ReplaceTargetOptions) - replaceTargetOptionsModel.ID = core.StringPtr("testString") - replaceTargetOptionsModel.Name = core.StringPtr("my-cos-target") - replaceTargetOptionsModel.TargetType = core.StringPtr("cloud_object_storage") - replaceTargetOptionsModel.CosEndpoint = cosEndpointModel - replaceTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation - result, response, operationErr := atrackerService.ReplaceTarget(replaceTargetOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - - // Verify a nil result - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`DeleteTarget(deleteTargetOptions *DeleteTargetOptions) - Operation response error`, func() { - deleteTargetPath := "/api/v1/targets/testString" - Context(`Using mock server endpoint with invalid JSON response`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(deleteTargetPath)) - Expect(req.Method).To(Equal("DELETE")) - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, `} this is not valid json {`) - })) - }) - It(`Invoke DeleteTarget with error: Operation response processing error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the DeleteTargetOptions model - deleteTargetOptionsModel := new(atrackerv1.DeleteTargetOptions) - deleteTargetOptionsModel.ID = core.StringPtr("testString") - deleteTargetOptionsModel.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 := atrackerService.DeleteTarget(deleteTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - - // Enable retries and test again - atrackerService.EnableRetries(0, 0) - result, response, operationErr = atrackerService.DeleteTarget(deleteTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`DeleteTarget(deleteTargetOptions *DeleteTargetOptions)`, func() { - deleteTargetPath := "/api/v1/targets/testString" - Context(`Using mock server endpoint with timeout`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(deleteTargetPath)) - Expect(req.Method).To(Equal("DELETE")) - - // Sleep a short time to support a timeout test - time.Sleep(100 * time.Millisecond) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"status_code": 10, "trace": "Trace", "warnings": [{"code": "Code", "message": "Message"}]}`) - })) - }) - It(`Invoke DeleteTarget successfully with retries`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - atrackerService.EnableRetries(0, 0) - - // Construct an instance of the DeleteTargetOptions model - deleteTargetOptionsModel := new(atrackerv1.DeleteTargetOptions) - deleteTargetOptionsModel.ID = core.StringPtr("testString") - deleteTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with a Context to test a timeout error - ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc() - _, _, operationErr := atrackerService.DeleteTargetWithContext(ctx, deleteTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - - // Disable retries and test again - atrackerService.DisableRetries() - result, response, operationErr := atrackerService.DeleteTarget(deleteTargetOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - // Re-test the timeout error with retries disabled - ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc2() - _, _, operationErr = atrackerService.DeleteTargetWithContext(ctx, deleteTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(deleteTargetPath)) - Expect(req.Method).To(Equal("DELETE")) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"status_code": 10, "trace": "Trace", "warnings": [{"code": "Code", "message": "Message"}]}`) - })) - }) - It(`Invoke DeleteTarget successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Invoke operation with nil options model (negative test) - result, response, operationErr := atrackerService.DeleteTarget(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - - // Construct an instance of the DeleteTargetOptions model - deleteTargetOptionsModel := new(atrackerv1.DeleteTargetOptions) - deleteTargetOptionsModel.ID = core.StringPtr("testString") - deleteTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with valid options model (positive test) - result, response, operationErr = atrackerService.DeleteTarget(deleteTargetOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - }) - It(`Invoke DeleteTarget with error: Operation validation and request error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the DeleteTargetOptions model - deleteTargetOptionsModel := new(atrackerv1.DeleteTargetOptions) - deleteTargetOptionsModel.ID = core.StringPtr("testString") - deleteTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with empty URL (negative test) - err := atrackerService.SetServiceURL("") - Expect(err).To(BeNil()) - result, response, operationErr := atrackerService.DeleteTarget(deleteTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - // Construct a second instance of the DeleteTargetOptions model with no property values - deleteTargetOptionsModelNew := new(atrackerv1.DeleteTargetOptions) - // Invoke operation with invalid model (negative test) - result, response, operationErr = atrackerService.DeleteTarget(deleteTargetOptionsModelNew) - Expect(operationErr).ToNot(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint with missing response body`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Set success status code with no respoonse body - res.WriteHeader(200) - })) - }) - It(`Invoke DeleteTarget successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the DeleteTargetOptions model - deleteTargetOptionsModel := new(atrackerv1.DeleteTargetOptions) - deleteTargetOptionsModel.ID = core.StringPtr("testString") - deleteTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation - result, response, operationErr := atrackerService.DeleteTarget(deleteTargetOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - - // Verify a nil result - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`ValidateTarget(validateTargetOptions *ValidateTargetOptions) - Operation response error`, func() { - validateTargetPath := "/api/v1/targets/testString/validate" - Context(`Using mock server endpoint with invalid JSON response`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(validateTargetPath)) - Expect(req.Method).To(Equal("POST")) - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, `} this is not valid json {`) - })) - }) - It(`Invoke ValidateTarget with error: Operation response processing error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the ValidateTargetOptions model - validateTargetOptionsModel := new(atrackerv1.ValidateTargetOptions) - validateTargetOptionsModel.ID = core.StringPtr("testString") - validateTargetOptionsModel.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 := atrackerService.ValidateTarget(validateTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - - // Enable retries and test again - atrackerService.EnableRetries(0, 0) - result, response, operationErr = atrackerService.ValidateTarget(validateTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`ValidateTarget(validateTargetOptions *ValidateTargetOptions)`, func() { - validateTargetPath := "/api/v1/targets/testString/validate" - Context(`Using mock server endpoint with timeout`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(validateTargetPath)) - Expect(req.Method).To(Equal("POST")) - - // Sleep a short time to support a timeout test - time.Sleep(100 * time.Millisecond) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "name": "a-cos-target-us-south", "crn": "crn:v1:bluemix:public:atracker:us-south:a/11111111111111111111111111111111:b6eec08b-5201-08ca-451b-cd71523e3626:target:f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "target_type": "cloud_object_storage", "encrypt_key": "REDACTED", "cos_endpoint": {"endpoint": "s3.private.us-east.cloud-object-storage.appdomain.cloud", "target_crn": "crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::", "bucket": "my-atracker-bucket", "api_key": "xxxxxxxxxxxxxx"}, "cos_write_status": {"status": "success", "last_failure": "2021-05-18T20:15:12.353Z", "reason_for_last_failure": "Provided API key could not be found"}, "created": "2021-05-18T20:15:12.353Z", "updated": "2021-05-18T20:15:12.353Z"}`) - })) - }) - It(`Invoke ValidateTarget successfully with retries`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - atrackerService.EnableRetries(0, 0) - - // Construct an instance of the ValidateTargetOptions model - validateTargetOptionsModel := new(atrackerv1.ValidateTargetOptions) - validateTargetOptionsModel.ID = core.StringPtr("testString") - validateTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with a Context to test a timeout error - ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc() - _, _, operationErr := atrackerService.ValidateTargetWithContext(ctx, validateTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - - // Disable retries and test again - atrackerService.DisableRetries() - result, response, operationErr := atrackerService.ValidateTarget(validateTargetOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - // Re-test the timeout error with retries disabled - ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc2() - _, _, operationErr = atrackerService.ValidateTargetWithContext(ctx, validateTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(validateTargetPath)) - Expect(req.Method).To(Equal("POST")) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "name": "a-cos-target-us-south", "crn": "crn:v1:bluemix:public:atracker:us-south:a/11111111111111111111111111111111:b6eec08b-5201-08ca-451b-cd71523e3626:target:f7dcfae6-e7c5-08ca-451b-fdfa696c9bb6", "target_type": "cloud_object_storage", "encrypt_key": "REDACTED", "cos_endpoint": {"endpoint": "s3.private.us-east.cloud-object-storage.appdomain.cloud", "target_crn": "crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::", "bucket": "my-atracker-bucket", "api_key": "xxxxxxxxxxxxxx"}, "cos_write_status": {"status": "success", "last_failure": "2021-05-18T20:15:12.353Z", "reason_for_last_failure": "Provided API key could not be found"}, "created": "2021-05-18T20:15:12.353Z", "updated": "2021-05-18T20:15:12.353Z"}`) - })) - }) - It(`Invoke ValidateTarget successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Invoke operation with nil options model (negative test) - result, response, operationErr := atrackerService.ValidateTarget(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - - // Construct an instance of the ValidateTargetOptions model - validateTargetOptionsModel := new(atrackerv1.ValidateTargetOptions) - validateTargetOptionsModel.ID = core.StringPtr("testString") - validateTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with valid options model (positive test) - result, response, operationErr = atrackerService.ValidateTarget(validateTargetOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - }) - It(`Invoke ValidateTarget with error: Operation validation and request error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the ValidateTargetOptions model - validateTargetOptionsModel := new(atrackerv1.ValidateTargetOptions) - validateTargetOptionsModel.ID = core.StringPtr("testString") - validateTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with empty URL (negative test) - err := atrackerService.SetServiceURL("") - Expect(err).To(BeNil()) - result, response, operationErr := atrackerService.ValidateTarget(validateTargetOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - // Construct a second instance of the ValidateTargetOptions model with no property values - validateTargetOptionsModelNew := new(atrackerv1.ValidateTargetOptions) - // Invoke operation with invalid model (negative test) - result, response, operationErr = atrackerService.ValidateTarget(validateTargetOptionsModelNew) - Expect(operationErr).ToNot(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint with missing response body`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Set success status code with no respoonse body - res.WriteHeader(200) - })) - }) - It(`Invoke ValidateTarget successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the ValidateTargetOptions model - validateTargetOptionsModel := new(atrackerv1.ValidateTargetOptions) - validateTargetOptionsModel.ID = core.StringPtr("testString") - validateTargetOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation - result, response, operationErr := atrackerService.ValidateTarget(validateTargetOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - - // Verify a nil result - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`CreateRoute(createRouteOptions *CreateRouteOptions) - Operation response error`, func() { - createRoutePath := "/api/v1/routes" - Context(`Using mock server endpoint with invalid JSON response`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(createRoutePath)) - Expect(req.Method).To(Equal("POST")) - res.Header().Set("Content-type", "application/json") - res.WriteHeader(201) - fmt.Fprintf(res, `} this is not valid json {`) - })) - }) - It(`Invoke CreateRoute with error: Operation response processing error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the Rule model - ruleModel := new(atrackerv1.Rule) - ruleModel.TargetIds = []string{"c3af557f-fb0e-4476-85c3-0889e7fe7bc4"} - - // Construct an instance of the CreateRouteOptions model - createRouteOptionsModel := new(atrackerv1.CreateRouteOptions) - createRouteOptionsModel.Name = core.StringPtr("my-route") - createRouteOptionsModel.ReceiveGlobalEvents = core.BoolPtr(false) - createRouteOptionsModel.Rules = []atrackerv1.Rule{*ruleModel} - createRouteOptionsModel.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 := atrackerService.CreateRoute(createRouteOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - - // Enable retries and test again - atrackerService.EnableRetries(0, 0) - result, response, operationErr = atrackerService.CreateRoute(createRouteOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`CreateRoute(createRouteOptions *CreateRouteOptions)`, func() { - createRoutePath := "/api/v1/routes" - Context(`Using mock server endpoint with timeout`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(createRoutePath)) - Expect(req.Method).To(Equal("POST")) - - // For gzip-disabled operation, verify Content-Encoding is not set. - Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) - - // If there is a body, then make sure we can read it - bodyBuf := new(bytes.Buffer) - if req.Header.Get("Content-Encoding") == "gzip" { - body, err := core.NewGzipDecompressionReader(req.Body) - Expect(err).To(BeNil()) - _, err = bodyBuf.ReadFrom(body) - Expect(err).To(BeNil()) - } else { - _, err := bodyBuf.ReadFrom(req.Body) - Expect(err).To(BeNil()) - } - fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) - - // Sleep a short time to support a timeout test - time.Sleep(100 * time.Millisecond) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(201) - fmt.Fprintf(res, "%s", `{"id": "c3af557f-fb0e-4476-85c3-0889e7fe7bc4", "name": "my-route", "crn": "crn:v1:bluemix:public:atracker:us-south:a/11111111111111111111111111111111:b6eec08b-5201-08ca-451b-cd71523e3626:route:c3af557f-fb0e-4476-85c3-0889e7fe7bc4", "version": 0, "receive_global_events": false, "rules": [{"target_ids": ["c3af557f-fb0e-4476-85c3-0889e7fe7bc4"]}], "created": "2021-05-18T20:15:12.353Z", "updated": "2021-05-18T20:15:12.353Z"}`) - })) - }) - It(`Invoke CreateRoute successfully with retries`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - atrackerService.EnableRetries(0, 0) - - // Construct an instance of the Rule model - ruleModel := new(atrackerv1.Rule) - ruleModel.TargetIds = []string{"c3af557f-fb0e-4476-85c3-0889e7fe7bc4"} - - // Construct an instance of the CreateRouteOptions model - createRouteOptionsModel := new(atrackerv1.CreateRouteOptions) - createRouteOptionsModel.Name = core.StringPtr("my-route") - createRouteOptionsModel.ReceiveGlobalEvents = core.BoolPtr(false) - createRouteOptionsModel.Rules = []atrackerv1.Rule{*ruleModel} - createRouteOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with a Context to test a timeout error - ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc() - _, _, operationErr := atrackerService.CreateRouteWithContext(ctx, createRouteOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - - // Disable retries and test again - atrackerService.DisableRetries() - result, response, operationErr := atrackerService.CreateRoute(createRouteOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - // Re-test the timeout error with retries disabled - ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc2() - _, _, operationErr = atrackerService.CreateRouteWithContext(ctx, createRouteOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(createRoutePath)) - Expect(req.Method).To(Equal("POST")) - - // For gzip-disabled operation, verify Content-Encoding is not set. - Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) - - // If there is a body, then make sure we can read it - bodyBuf := new(bytes.Buffer) - if req.Header.Get("Content-Encoding") == "gzip" { - body, err := core.NewGzipDecompressionReader(req.Body) - Expect(err).To(BeNil()) - _, err = bodyBuf.ReadFrom(body) - Expect(err).To(BeNil()) - } else { - _, err := bodyBuf.ReadFrom(req.Body) - Expect(err).To(BeNil()) - } - fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(201) - fmt.Fprintf(res, "%s", `{"id": "c3af557f-fb0e-4476-85c3-0889e7fe7bc4", "name": "my-route", "crn": "crn:v1:bluemix:public:atracker:us-south:a/11111111111111111111111111111111:b6eec08b-5201-08ca-451b-cd71523e3626:route:c3af557f-fb0e-4476-85c3-0889e7fe7bc4", "version": 0, "receive_global_events": false, "rules": [{"target_ids": ["c3af557f-fb0e-4476-85c3-0889e7fe7bc4"]}], "created": "2021-05-18T20:15:12.353Z", "updated": "2021-05-18T20:15:12.353Z"}`) - })) - }) - It(`Invoke CreateRoute successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Invoke operation with nil options model (negative test) - result, response, operationErr := atrackerService.CreateRoute(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - - // Construct an instance of the Rule model - ruleModel := new(atrackerv1.Rule) - ruleModel.TargetIds = []string{"c3af557f-fb0e-4476-85c3-0889e7fe7bc4"} - - // Construct an instance of the CreateRouteOptions model - createRouteOptionsModel := new(atrackerv1.CreateRouteOptions) - createRouteOptionsModel.Name = core.StringPtr("my-route") - createRouteOptionsModel.ReceiveGlobalEvents = core.BoolPtr(false) - createRouteOptionsModel.Rules = []atrackerv1.Rule{*ruleModel} - createRouteOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with valid options model (positive test) - result, response, operationErr = atrackerService.CreateRoute(createRouteOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - }) - It(`Invoke CreateRoute with error: Operation validation and request error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the Rule model - ruleModel := new(atrackerv1.Rule) - ruleModel.TargetIds = []string{"c3af557f-fb0e-4476-85c3-0889e7fe7bc4"} - - // Construct an instance of the CreateRouteOptions model - createRouteOptionsModel := new(atrackerv1.CreateRouteOptions) - createRouteOptionsModel.Name = core.StringPtr("my-route") - createRouteOptionsModel.ReceiveGlobalEvents = core.BoolPtr(false) - createRouteOptionsModel.Rules = []atrackerv1.Rule{*ruleModel} - createRouteOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with empty URL (negative test) - err := atrackerService.SetServiceURL("") - Expect(err).To(BeNil()) - result, response, operationErr := atrackerService.CreateRoute(createRouteOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - // Construct a second instance of the CreateRouteOptions model with no property values - createRouteOptionsModelNew := new(atrackerv1.CreateRouteOptions) - // Invoke operation with invalid model (negative test) - result, response, operationErr = atrackerService.CreateRoute(createRouteOptionsModelNew) - Expect(operationErr).ToNot(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint with missing response body`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Set success status code with no respoonse body - res.WriteHeader(201) - })) - }) - It(`Invoke CreateRoute successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the Rule model - ruleModel := new(atrackerv1.Rule) - ruleModel.TargetIds = []string{"c3af557f-fb0e-4476-85c3-0889e7fe7bc4"} - - // Construct an instance of the CreateRouteOptions model - createRouteOptionsModel := new(atrackerv1.CreateRouteOptions) - createRouteOptionsModel.Name = core.StringPtr("my-route") - createRouteOptionsModel.ReceiveGlobalEvents = core.BoolPtr(false) - createRouteOptionsModel.Rules = []atrackerv1.Rule{*ruleModel} - createRouteOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation - result, response, operationErr := atrackerService.CreateRoute(createRouteOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - - // Verify a nil result - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`ListRoutes(listRoutesOptions *ListRoutesOptions) - Operation response error`, func() { - listRoutesPath := "/api/v1/routes" - Context(`Using mock server endpoint with invalid JSON response`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(listRoutesPath)) - Expect(req.Method).To(Equal("GET")) - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, `} this is not valid json {`) - })) - }) - It(`Invoke ListRoutes with error: Operation response processing error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the ListRoutesOptions model - listRoutesOptionsModel := new(atrackerv1.ListRoutesOptions) - listRoutesOptionsModel.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 := atrackerService.ListRoutes(listRoutesOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - - // Enable retries and test again - atrackerService.EnableRetries(0, 0) - result, response, operationErr = atrackerService.ListRoutes(listRoutesOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`ListRoutes(listRoutesOptions *ListRoutesOptions)`, func() { - listRoutesPath := "/api/v1/routes" - Context(`Using mock server endpoint with timeout`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(listRoutesPath)) - Expect(req.Method).To(Equal("GET")) - - // Sleep a short time to support a timeout test - time.Sleep(100 * time.Millisecond) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"routes": [{"id": "c3af557f-fb0e-4476-85c3-0889e7fe7bc4", "name": "my-route", "crn": "crn:v1:bluemix:public:atracker:us-south:a/11111111111111111111111111111111:b6eec08b-5201-08ca-451b-cd71523e3626:route:c3af557f-fb0e-4476-85c3-0889e7fe7bc4", "version": 0, "receive_global_events": false, "rules": [{"target_ids": ["c3af557f-fb0e-4476-85c3-0889e7fe7bc4"]}], "created": "2021-05-18T20:15:12.353Z", "updated": "2021-05-18T20:15:12.353Z"}]}`) - })) - }) - It(`Invoke ListRoutes successfully with retries`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - atrackerService.EnableRetries(0, 0) - - // Construct an instance of the ListRoutesOptions model - listRoutesOptionsModel := new(atrackerv1.ListRoutesOptions) - listRoutesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with a Context to test a timeout error - ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc() - _, _, operationErr := atrackerService.ListRoutesWithContext(ctx, listRoutesOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - - // Disable retries and test again - atrackerService.DisableRetries() - result, response, operationErr := atrackerService.ListRoutes(listRoutesOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - // Re-test the timeout error with retries disabled - ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc2() - _, _, operationErr = atrackerService.ListRoutesWithContext(ctx, listRoutesOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(listRoutesPath)) - Expect(req.Method).To(Equal("GET")) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"routes": [{"id": "c3af557f-fb0e-4476-85c3-0889e7fe7bc4", "name": "my-route", "crn": "crn:v1:bluemix:public:atracker:us-south:a/11111111111111111111111111111111:b6eec08b-5201-08ca-451b-cd71523e3626:route:c3af557f-fb0e-4476-85c3-0889e7fe7bc4", "version": 0, "receive_global_events": false, "rules": [{"target_ids": ["c3af557f-fb0e-4476-85c3-0889e7fe7bc4"]}], "created": "2021-05-18T20:15:12.353Z", "updated": "2021-05-18T20:15:12.353Z"}]}`) - })) - }) - It(`Invoke ListRoutes successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Invoke operation with nil options model (negative test) - result, response, operationErr := atrackerService.ListRoutes(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - - // Construct an instance of the ListRoutesOptions model - listRoutesOptionsModel := new(atrackerv1.ListRoutesOptions) - listRoutesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with valid options model (positive test) - result, response, operationErr = atrackerService.ListRoutes(listRoutesOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - }) - It(`Invoke ListRoutes with error: Operation request error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the ListRoutesOptions model - listRoutesOptionsModel := new(atrackerv1.ListRoutesOptions) - listRoutesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with empty URL (negative test) - err := atrackerService.SetServiceURL("") - Expect(err).To(BeNil()) - result, response, operationErr := atrackerService.ListRoutes(listRoutesOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint with missing response body`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Set success status code with no respoonse body - res.WriteHeader(200) - })) - }) - It(`Invoke ListRoutes successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the ListRoutesOptions model - listRoutesOptionsModel := new(atrackerv1.ListRoutesOptions) - listRoutesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation - result, response, operationErr := atrackerService.ListRoutes(listRoutesOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - - // Verify a nil result - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`GetRoute(getRouteOptions *GetRouteOptions) - Operation response error`, func() { - getRoutePath := "/api/v1/routes/testString" - Context(`Using mock server endpoint with invalid JSON response`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(getRoutePath)) - Expect(req.Method).To(Equal("GET")) - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, `} this is not valid json {`) - })) - }) - It(`Invoke GetRoute with error: Operation response processing error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the GetRouteOptions model - getRouteOptionsModel := new(atrackerv1.GetRouteOptions) - getRouteOptionsModel.ID = core.StringPtr("testString") - getRouteOptionsModel.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 := atrackerService.GetRoute(getRouteOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - - // Enable retries and test again - atrackerService.EnableRetries(0, 0) - result, response, operationErr = atrackerService.GetRoute(getRouteOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`GetRoute(getRouteOptions *GetRouteOptions)`, func() { - getRoutePath := "/api/v1/routes/testString" - Context(`Using mock server endpoint with timeout`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(getRoutePath)) - Expect(req.Method).To(Equal("GET")) - - // Sleep a short time to support a timeout test - time.Sleep(100 * time.Millisecond) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "c3af557f-fb0e-4476-85c3-0889e7fe7bc4", "name": "my-route", "crn": "crn:v1:bluemix:public:atracker:us-south:a/11111111111111111111111111111111:b6eec08b-5201-08ca-451b-cd71523e3626:route:c3af557f-fb0e-4476-85c3-0889e7fe7bc4", "version": 0, "receive_global_events": false, "rules": [{"target_ids": ["c3af557f-fb0e-4476-85c3-0889e7fe7bc4"]}], "created": "2021-05-18T20:15:12.353Z", "updated": "2021-05-18T20:15:12.353Z"}`) - })) - }) - It(`Invoke GetRoute successfully with retries`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - atrackerService.EnableRetries(0, 0) - - // Construct an instance of the GetRouteOptions model - getRouteOptionsModel := new(atrackerv1.GetRouteOptions) - getRouteOptionsModel.ID = core.StringPtr("testString") - getRouteOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with a Context to test a timeout error - ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc() - _, _, operationErr := atrackerService.GetRouteWithContext(ctx, getRouteOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - - // Disable retries and test again - atrackerService.DisableRetries() - result, response, operationErr := atrackerService.GetRoute(getRouteOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - // Re-test the timeout error with retries disabled - ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc2() - _, _, operationErr = atrackerService.GetRouteWithContext(ctx, getRouteOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(getRoutePath)) - Expect(req.Method).To(Equal("GET")) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "c3af557f-fb0e-4476-85c3-0889e7fe7bc4", "name": "my-route", "crn": "crn:v1:bluemix:public:atracker:us-south:a/11111111111111111111111111111111:b6eec08b-5201-08ca-451b-cd71523e3626:route:c3af557f-fb0e-4476-85c3-0889e7fe7bc4", "version": 0, "receive_global_events": false, "rules": [{"target_ids": ["c3af557f-fb0e-4476-85c3-0889e7fe7bc4"]}], "created": "2021-05-18T20:15:12.353Z", "updated": "2021-05-18T20:15:12.353Z"}`) - })) - }) - It(`Invoke GetRoute successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Invoke operation with nil options model (negative test) - result, response, operationErr := atrackerService.GetRoute(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - - // Construct an instance of the GetRouteOptions model - getRouteOptionsModel := new(atrackerv1.GetRouteOptions) - getRouteOptionsModel.ID = core.StringPtr("testString") - getRouteOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with valid options model (positive test) - result, response, operationErr = atrackerService.GetRoute(getRouteOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - }) - It(`Invoke GetRoute with error: Operation validation and request error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the GetRouteOptions model - getRouteOptionsModel := new(atrackerv1.GetRouteOptions) - getRouteOptionsModel.ID = core.StringPtr("testString") - getRouteOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with empty URL (negative test) - err := atrackerService.SetServiceURL("") - Expect(err).To(BeNil()) - result, response, operationErr := atrackerService.GetRoute(getRouteOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - // Construct a second instance of the GetRouteOptions model with no property values - getRouteOptionsModelNew := new(atrackerv1.GetRouteOptions) - // Invoke operation with invalid model (negative test) - result, response, operationErr = atrackerService.GetRoute(getRouteOptionsModelNew) - Expect(operationErr).ToNot(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint with missing response body`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Set success status code with no respoonse body - res.WriteHeader(200) - })) - }) - It(`Invoke GetRoute successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the GetRouteOptions model - getRouteOptionsModel := new(atrackerv1.GetRouteOptions) - getRouteOptionsModel.ID = core.StringPtr("testString") - getRouteOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation - result, response, operationErr := atrackerService.GetRoute(getRouteOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - - // Verify a nil result - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`ReplaceRoute(replaceRouteOptions *ReplaceRouteOptions) - Operation response error`, func() { - replaceRoutePath := "/api/v1/routes/testString" - Context(`Using mock server endpoint with invalid JSON response`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(replaceRoutePath)) - Expect(req.Method).To(Equal("PUT")) - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, `} this is not valid json {`) - })) - }) - It(`Invoke ReplaceRoute with error: Operation response processing error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the Rule model - ruleModel := new(atrackerv1.Rule) - ruleModel.TargetIds = []string{"c3af557f-fb0e-4476-85c3-0889e7fe7bc4"} - - // Construct an instance of the ReplaceRouteOptions model - replaceRouteOptionsModel := new(atrackerv1.ReplaceRouteOptions) - replaceRouteOptionsModel.ID = core.StringPtr("testString") - replaceRouteOptionsModel.Name = core.StringPtr("my-route") - replaceRouteOptionsModel.ReceiveGlobalEvents = core.BoolPtr(false) - replaceRouteOptionsModel.Rules = []atrackerv1.Rule{*ruleModel} - replaceRouteOptionsModel.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 := atrackerService.ReplaceRoute(replaceRouteOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - - // Enable retries and test again - atrackerService.EnableRetries(0, 0) - result, response, operationErr = atrackerService.ReplaceRoute(replaceRouteOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`ReplaceRoute(replaceRouteOptions *ReplaceRouteOptions)`, func() { - replaceRoutePath := "/api/v1/routes/testString" - Context(`Using mock server endpoint with timeout`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(replaceRoutePath)) - Expect(req.Method).To(Equal("PUT")) - - // For gzip-disabled operation, verify Content-Encoding is not set. - Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) - - // If there is a body, then make sure we can read it - bodyBuf := new(bytes.Buffer) - if req.Header.Get("Content-Encoding") == "gzip" { - body, err := core.NewGzipDecompressionReader(req.Body) - Expect(err).To(BeNil()) - _, err = bodyBuf.ReadFrom(body) - Expect(err).To(BeNil()) - } else { - _, err := bodyBuf.ReadFrom(req.Body) - Expect(err).To(BeNil()) - } - fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) - - // Sleep a short time to support a timeout test - time.Sleep(100 * time.Millisecond) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "c3af557f-fb0e-4476-85c3-0889e7fe7bc4", "name": "my-route", "crn": "crn:v1:bluemix:public:atracker:us-south:a/11111111111111111111111111111111:b6eec08b-5201-08ca-451b-cd71523e3626:route:c3af557f-fb0e-4476-85c3-0889e7fe7bc4", "version": 0, "receive_global_events": false, "rules": [{"target_ids": ["c3af557f-fb0e-4476-85c3-0889e7fe7bc4"]}], "created": "2021-05-18T20:15:12.353Z", "updated": "2021-05-18T20:15:12.353Z"}`) - })) - }) - It(`Invoke ReplaceRoute successfully with retries`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - atrackerService.EnableRetries(0, 0) - - // Construct an instance of the Rule model - ruleModel := new(atrackerv1.Rule) - ruleModel.TargetIds = []string{"c3af557f-fb0e-4476-85c3-0889e7fe7bc4"} - - // Construct an instance of the ReplaceRouteOptions model - replaceRouteOptionsModel := new(atrackerv1.ReplaceRouteOptions) - replaceRouteOptionsModel.ID = core.StringPtr("testString") - replaceRouteOptionsModel.Name = core.StringPtr("my-route") - replaceRouteOptionsModel.ReceiveGlobalEvents = core.BoolPtr(false) - replaceRouteOptionsModel.Rules = []atrackerv1.Rule{*ruleModel} - replaceRouteOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with a Context to test a timeout error - ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc() - _, _, operationErr := atrackerService.ReplaceRouteWithContext(ctx, replaceRouteOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - - // Disable retries and test again - atrackerService.DisableRetries() - result, response, operationErr := atrackerService.ReplaceRoute(replaceRouteOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - // Re-test the timeout error with retries disabled - ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc2() - _, _, operationErr = atrackerService.ReplaceRouteWithContext(ctx, replaceRouteOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(replaceRoutePath)) - Expect(req.Method).To(Equal("PUT")) - - // For gzip-disabled operation, verify Content-Encoding is not set. - Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) - - // If there is a body, then make sure we can read it - bodyBuf := new(bytes.Buffer) - if req.Header.Get("Content-Encoding") == "gzip" { - body, err := core.NewGzipDecompressionReader(req.Body) - Expect(err).To(BeNil()) - _, err = bodyBuf.ReadFrom(body) - Expect(err).To(BeNil()) - } else { - _, err := bodyBuf.ReadFrom(req.Body) - Expect(err).To(BeNil()) - } - fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "c3af557f-fb0e-4476-85c3-0889e7fe7bc4", "name": "my-route", "crn": "crn:v1:bluemix:public:atracker:us-south:a/11111111111111111111111111111111:b6eec08b-5201-08ca-451b-cd71523e3626:route:c3af557f-fb0e-4476-85c3-0889e7fe7bc4", "version": 0, "receive_global_events": false, "rules": [{"target_ids": ["c3af557f-fb0e-4476-85c3-0889e7fe7bc4"]}], "created": "2021-05-18T20:15:12.353Z", "updated": "2021-05-18T20:15:12.353Z"}`) - })) - }) - It(`Invoke ReplaceRoute successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Invoke operation with nil options model (negative test) - result, response, operationErr := atrackerService.ReplaceRoute(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - - // Construct an instance of the Rule model - ruleModel := new(atrackerv1.Rule) - ruleModel.TargetIds = []string{"c3af557f-fb0e-4476-85c3-0889e7fe7bc4"} - - // Construct an instance of the ReplaceRouteOptions model - replaceRouteOptionsModel := new(atrackerv1.ReplaceRouteOptions) - replaceRouteOptionsModel.ID = core.StringPtr("testString") - replaceRouteOptionsModel.Name = core.StringPtr("my-route") - replaceRouteOptionsModel.ReceiveGlobalEvents = core.BoolPtr(false) - replaceRouteOptionsModel.Rules = []atrackerv1.Rule{*ruleModel} - replaceRouteOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with valid options model (positive test) - result, response, operationErr = atrackerService.ReplaceRoute(replaceRouteOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - }) - It(`Invoke ReplaceRoute with error: Operation validation and request error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the Rule model - ruleModel := new(atrackerv1.Rule) - ruleModel.TargetIds = []string{"c3af557f-fb0e-4476-85c3-0889e7fe7bc4"} - - // Construct an instance of the ReplaceRouteOptions model - replaceRouteOptionsModel := new(atrackerv1.ReplaceRouteOptions) - replaceRouteOptionsModel.ID = core.StringPtr("testString") - replaceRouteOptionsModel.Name = core.StringPtr("my-route") - replaceRouteOptionsModel.ReceiveGlobalEvents = core.BoolPtr(false) - replaceRouteOptionsModel.Rules = []atrackerv1.Rule{*ruleModel} - replaceRouteOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with empty URL (negative test) - err := atrackerService.SetServiceURL("") - Expect(err).To(BeNil()) - result, response, operationErr := atrackerService.ReplaceRoute(replaceRouteOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - // Construct a second instance of the ReplaceRouteOptions model with no property values - replaceRouteOptionsModelNew := new(atrackerv1.ReplaceRouteOptions) - // Invoke operation with invalid model (negative test) - result, response, operationErr = atrackerService.ReplaceRoute(replaceRouteOptionsModelNew) - Expect(operationErr).ToNot(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint with missing response body`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Set success status code with no respoonse body - res.WriteHeader(200) - })) - }) - It(`Invoke ReplaceRoute successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the Rule model - ruleModel := new(atrackerv1.Rule) - ruleModel.TargetIds = []string{"c3af557f-fb0e-4476-85c3-0889e7fe7bc4"} - - // Construct an instance of the ReplaceRouteOptions model - replaceRouteOptionsModel := new(atrackerv1.ReplaceRouteOptions) - replaceRouteOptionsModel.ID = core.StringPtr("testString") - replaceRouteOptionsModel.Name = core.StringPtr("my-route") - replaceRouteOptionsModel.ReceiveGlobalEvents = core.BoolPtr(false) - replaceRouteOptionsModel.Rules = []atrackerv1.Rule{*ruleModel} - replaceRouteOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation - result, response, operationErr := atrackerService.ReplaceRoute(replaceRouteOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - - // Verify a nil result - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`DeleteRoute(deleteRouteOptions *DeleteRouteOptions)`, func() { - deleteRoutePath := "/api/v1/routes/testString" - Context(`Using mock server endpoint`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(deleteRoutePath)) - Expect(req.Method).To(Equal("DELETE")) - - res.WriteHeader(204) - })) - }) - It(`Invoke DeleteRoute successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Invoke operation with nil options model (negative test) - response, operationErr := atrackerService.DeleteRoute(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - - // Construct an instance of the DeleteRouteOptions model - deleteRouteOptionsModel := new(atrackerv1.DeleteRouteOptions) - deleteRouteOptionsModel.ID = core.StringPtr("testString") - deleteRouteOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with valid options model (positive test) - response, operationErr = atrackerService.DeleteRoute(deleteRouteOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - }) - It(`Invoke DeleteRoute with error: Operation validation and request error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the DeleteRouteOptions model - deleteRouteOptionsModel := new(atrackerv1.DeleteRouteOptions) - deleteRouteOptionsModel.ID = core.StringPtr("testString") - deleteRouteOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with empty URL (negative test) - err := atrackerService.SetServiceURL("") - Expect(err).To(BeNil()) - response, operationErr := atrackerService.DeleteRoute(deleteRouteOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) - Expect(response).To(BeNil()) - // Construct a second instance of the DeleteRouteOptions model with no property values - deleteRouteOptionsModelNew := new(atrackerv1.DeleteRouteOptions) - // Invoke operation with invalid model (negative test) - response, operationErr = atrackerService.DeleteRoute(deleteRouteOptionsModelNew) - Expect(operationErr).ToNot(BeNil()) - Expect(response).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`GetEndpoints(getEndpointsOptions *GetEndpointsOptions) - Operation response error`, func() { - getEndpointsPath := "/api/v1/endpoints" - Context(`Using mock server endpoint with invalid JSON response`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(getEndpointsPath)) - Expect(req.Method).To(Equal("GET")) - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, `} this is not valid json {`) - })) - }) - It(`Invoke GetEndpoints with error: Operation response processing error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the GetEndpointsOptions model - getEndpointsOptionsModel := new(atrackerv1.GetEndpointsOptions) - getEndpointsOptionsModel.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 := atrackerService.GetEndpoints(getEndpointsOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - - // Enable retries and test again - atrackerService.EnableRetries(0, 0) - result, response, operationErr = atrackerService.GetEndpoints(getEndpointsOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`GetEndpoints(getEndpointsOptions *GetEndpointsOptions)`, func() { - getEndpointsPath := "/api/v1/endpoints" - Context(`Using mock server endpoint with timeout`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(getEndpointsPath)) - Expect(req.Method).To(Equal("GET")) - - // Sleep a short time to support a timeout test - time.Sleep(100 * time.Millisecond) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"api_endpoint": {"public_url": "https://us-south.atracker.cloud.ibm.com", "public_enabled": true, "private_url": "https://private.us-south.atracker.cloud.ibm.com", "private_enabled": true}}`) - })) - }) - It(`Invoke GetEndpoints successfully with retries`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - atrackerService.EnableRetries(0, 0) - - // Construct an instance of the GetEndpointsOptions model - getEndpointsOptionsModel := new(atrackerv1.GetEndpointsOptions) - getEndpointsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with a Context to test a timeout error - ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc() - _, _, operationErr := atrackerService.GetEndpointsWithContext(ctx, getEndpointsOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - - // Disable retries and test again - atrackerService.DisableRetries() - result, response, operationErr := atrackerService.GetEndpoints(getEndpointsOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - // Re-test the timeout error with retries disabled - ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc2() - _, _, operationErr = atrackerService.GetEndpointsWithContext(ctx, getEndpointsOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(getEndpointsPath)) - Expect(req.Method).To(Equal("GET")) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"api_endpoint": {"public_url": "https://us-south.atracker.cloud.ibm.com", "public_enabled": true, "private_url": "https://private.us-south.atracker.cloud.ibm.com", "private_enabled": true}}`) - })) - }) - It(`Invoke GetEndpoints successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Invoke operation with nil options model (negative test) - result, response, operationErr := atrackerService.GetEndpoints(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - - // Construct an instance of the GetEndpointsOptions model - getEndpointsOptionsModel := new(atrackerv1.GetEndpointsOptions) - getEndpointsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with valid options model (positive test) - result, response, operationErr = atrackerService.GetEndpoints(getEndpointsOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - }) - It(`Invoke GetEndpoints with error: Operation request error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the GetEndpointsOptions model - getEndpointsOptionsModel := new(atrackerv1.GetEndpointsOptions) - getEndpointsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with empty URL (negative test) - err := atrackerService.SetServiceURL("") - Expect(err).To(BeNil()) - result, response, operationErr := atrackerService.GetEndpoints(getEndpointsOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint with missing response body`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Set success status code with no respoonse body - res.WriteHeader(200) - })) - }) - It(`Invoke GetEndpoints successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the GetEndpointsOptions model - getEndpointsOptionsModel := new(atrackerv1.GetEndpointsOptions) - getEndpointsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation - result, response, operationErr := atrackerService.GetEndpoints(getEndpointsOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - - // Verify a nil result - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`PatchEndpoints(patchEndpointsOptions *PatchEndpointsOptions) - Operation response error`, func() { - patchEndpointsPath := "/api/v1/endpoints" - Context(`Using mock server endpoint with invalid JSON response`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(patchEndpointsPath)) - Expect(req.Method).To(Equal("PATCH")) - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, `} this is not valid json {`) - })) - }) - It(`Invoke PatchEndpoints with error: Operation response processing error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the EndpointsRequestAPIEndpoint model - endpointsRequestAPIEndpointModel := new(atrackerv1.EndpointsRequestAPIEndpoint) - endpointsRequestAPIEndpointModel.PublicEnabled = core.BoolPtr(true) - - // Construct an instance of the PatchEndpointsOptions model - patchEndpointsOptionsModel := new(atrackerv1.PatchEndpointsOptions) - patchEndpointsOptionsModel.APIEndpoint = endpointsRequestAPIEndpointModel - patchEndpointsOptionsModel.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 := atrackerService.PatchEndpoints(patchEndpointsOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - - // Enable retries and test again - atrackerService.EnableRetries(0, 0) - result, response, operationErr = atrackerService.PatchEndpoints(patchEndpointsOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`PatchEndpoints(patchEndpointsOptions *PatchEndpointsOptions)`, func() { - patchEndpointsPath := "/api/v1/endpoints" - Context(`Using mock server endpoint with timeout`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(patchEndpointsPath)) - Expect(req.Method).To(Equal("PATCH")) - - // For gzip-disabled operation, verify Content-Encoding is not set. - Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) - - // If there is a body, then make sure we can read it - bodyBuf := new(bytes.Buffer) - if req.Header.Get("Content-Encoding") == "gzip" { - body, err := core.NewGzipDecompressionReader(req.Body) - Expect(err).To(BeNil()) - _, err = bodyBuf.ReadFrom(body) - Expect(err).To(BeNil()) - } else { - _, err := bodyBuf.ReadFrom(req.Body) - Expect(err).To(BeNil()) - } - fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) - - // Sleep a short time to support a timeout test - time.Sleep(100 * time.Millisecond) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"api_endpoint": {"public_url": "https://us-south.atracker.cloud.ibm.com", "public_enabled": true, "private_url": "https://private.us-south.atracker.cloud.ibm.com", "private_enabled": true}}`) - })) - }) - It(`Invoke PatchEndpoints successfully with retries`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - atrackerService.EnableRetries(0, 0) - - // Construct an instance of the EndpointsRequestAPIEndpoint model - endpointsRequestAPIEndpointModel := new(atrackerv1.EndpointsRequestAPIEndpoint) - endpointsRequestAPIEndpointModel.PublicEnabled = core.BoolPtr(true) - - // Construct an instance of the PatchEndpointsOptions model - patchEndpointsOptionsModel := new(atrackerv1.PatchEndpointsOptions) - patchEndpointsOptionsModel.APIEndpoint = endpointsRequestAPIEndpointModel - patchEndpointsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with a Context to test a timeout error - ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc() - _, _, operationErr := atrackerService.PatchEndpointsWithContext(ctx, patchEndpointsOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - - // Disable retries and test again - atrackerService.DisableRetries() - result, response, operationErr := atrackerService.PatchEndpoints(patchEndpointsOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - // Re-test the timeout error with retries disabled - ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc2() - _, _, operationErr = atrackerService.PatchEndpointsWithContext(ctx, patchEndpointsOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(patchEndpointsPath)) - Expect(req.Method).To(Equal("PATCH")) - - // For gzip-disabled operation, verify Content-Encoding is not set. - Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) - - // If there is a body, then make sure we can read it - bodyBuf := new(bytes.Buffer) - if req.Header.Get("Content-Encoding") == "gzip" { - body, err := core.NewGzipDecompressionReader(req.Body) - Expect(err).To(BeNil()) - _, err = bodyBuf.ReadFrom(body) - Expect(err).To(BeNil()) - } else { - _, err := bodyBuf.ReadFrom(req.Body) - Expect(err).To(BeNil()) - } - fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) - - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"api_endpoint": {"public_url": "https://us-south.atracker.cloud.ibm.com", "public_enabled": true, "private_url": "https://private.us-south.atracker.cloud.ibm.com", "private_enabled": true}}`) - })) - }) - It(`Invoke PatchEndpoints successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Invoke operation with nil options model (negative test) - result, response, operationErr := atrackerService.PatchEndpoints(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - - // Construct an instance of the EndpointsRequestAPIEndpoint model - endpointsRequestAPIEndpointModel := new(atrackerv1.EndpointsRequestAPIEndpoint) - endpointsRequestAPIEndpointModel.PublicEnabled = core.BoolPtr(true) - - // Construct an instance of the PatchEndpointsOptions model - patchEndpointsOptionsModel := new(atrackerv1.PatchEndpointsOptions) - patchEndpointsOptionsModel.APIEndpoint = endpointsRequestAPIEndpointModel - patchEndpointsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with valid options model (positive test) - result, response, operationErr = atrackerService.PatchEndpoints(patchEndpointsOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - }) - It(`Invoke PatchEndpoints with error: Operation request error`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the EndpointsRequestAPIEndpoint model - endpointsRequestAPIEndpointModel := new(atrackerv1.EndpointsRequestAPIEndpoint) - endpointsRequestAPIEndpointModel.PublicEnabled = core.BoolPtr(true) - - // Construct an instance of the PatchEndpointsOptions model - patchEndpointsOptionsModel := new(atrackerv1.PatchEndpointsOptions) - patchEndpointsOptionsModel.APIEndpoint = endpointsRequestAPIEndpointModel - patchEndpointsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with empty URL (negative test) - err := atrackerService.SetServiceURL("") - Expect(err).To(BeNil()) - result, response, operationErr := atrackerService.PatchEndpoints(patchEndpointsOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - Context(`Using mock server endpoint with missing response body`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Set success status code with no respoonse body - res.WriteHeader(200) - })) - }) - It(`Invoke PatchEndpoints successfully`, func() { - atrackerService, serviceErr := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(atrackerService).ToNot(BeNil()) - - // Construct an instance of the EndpointsRequestAPIEndpoint model - endpointsRequestAPIEndpointModel := new(atrackerv1.EndpointsRequestAPIEndpoint) - endpointsRequestAPIEndpointModel.PublicEnabled = core.BoolPtr(true) - - // Construct an instance of the PatchEndpointsOptions model - patchEndpointsOptionsModel := new(atrackerv1.PatchEndpointsOptions) - patchEndpointsOptionsModel.APIEndpoint = endpointsRequestAPIEndpointModel - patchEndpointsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation - result, response, operationErr := atrackerService.PatchEndpoints(patchEndpointsOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - - // Verify a nil result - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`Model constructor tests`, func() { - Context(`Using a service client instance`, func() { - atrackerService, _ := atrackerv1.NewAtrackerV1(&atrackerv1.AtrackerV1Options{ - URL: "http://atrackerv1modelgenerator.com", - Authenticator: &core.NoAuthAuthenticator{}, - }) - It(`Invoke NewCreateRouteOptions successfully`, func() { - // Construct an instance of the Rule model - ruleModel := new(atrackerv1.Rule) - Expect(ruleModel).ToNot(BeNil()) - ruleModel.TargetIds = []string{"c3af557f-fb0e-4476-85c3-0889e7fe7bc4"} - Expect(ruleModel.TargetIds).To(Equal([]string{"c3af557f-fb0e-4476-85c3-0889e7fe7bc4"})) - - // Construct an instance of the CreateRouteOptions model - createRouteOptionsName := "my-route" - createRouteOptionsReceiveGlobalEvents := false - createRouteOptionsRules := []atrackerv1.Rule{} - createRouteOptionsModel := atrackerService.NewCreateRouteOptions(createRouteOptionsName, createRouteOptionsReceiveGlobalEvents, createRouteOptionsRules) - createRouteOptionsModel.SetName("my-route") - createRouteOptionsModel.SetReceiveGlobalEvents(false) - createRouteOptionsModel.SetRules([]atrackerv1.Rule{*ruleModel}) - createRouteOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) - Expect(createRouteOptionsModel).ToNot(BeNil()) - Expect(createRouteOptionsModel.Name).To(Equal(core.StringPtr("my-route"))) - Expect(createRouteOptionsModel.ReceiveGlobalEvents).To(Equal(core.BoolPtr(false))) - Expect(createRouteOptionsModel.Rules).To(Equal([]atrackerv1.Rule{*ruleModel})) - Expect(createRouteOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) - }) - It(`Invoke NewCreateTargetOptions successfully`, func() { - // Construct an instance of the CosEndpoint model - cosEndpointModel := new(atrackerv1.CosEndpoint) - Expect(cosEndpointModel).ToNot(BeNil()) - cosEndpointModel.Endpoint = core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud") - cosEndpointModel.TargetCRN = core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::") - cosEndpointModel.Bucket = core.StringPtr("my-atracker-bucket") - cosEndpointModel.APIKey = core.StringPtr("xxxxxxxxxxxxxx") - Expect(cosEndpointModel.Endpoint).To(Equal(core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud"))) - Expect(cosEndpointModel.TargetCRN).To(Equal(core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::"))) - Expect(cosEndpointModel.Bucket).To(Equal(core.StringPtr("my-atracker-bucket"))) - Expect(cosEndpointModel.APIKey).To(Equal(core.StringPtr("xxxxxxxxxxxxxx"))) - - // Construct an instance of the CreateTargetOptions model - createTargetOptionsName := "my-cos-target" - createTargetOptionsTargetType := "cloud_object_storage" - var createTargetOptionsCosEndpoint *atrackerv1.CosEndpoint = nil - createTargetOptionsModel := atrackerService.NewCreateTargetOptions(createTargetOptionsName, createTargetOptionsTargetType, createTargetOptionsCosEndpoint) - createTargetOptionsModel.SetName("my-cos-target") - createTargetOptionsModel.SetTargetType("cloud_object_storage") - createTargetOptionsModel.SetCosEndpoint(cosEndpointModel) - createTargetOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) - Expect(createTargetOptionsModel).ToNot(BeNil()) - Expect(createTargetOptionsModel.Name).To(Equal(core.StringPtr("my-cos-target"))) - Expect(createTargetOptionsModel.TargetType).To(Equal(core.StringPtr("cloud_object_storage"))) - Expect(createTargetOptionsModel.CosEndpoint).To(Equal(cosEndpointModel)) - Expect(createTargetOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) - }) - It(`Invoke NewDeleteRouteOptions successfully`, func() { - // Construct an instance of the DeleteRouteOptions model - id := "testString" - deleteRouteOptionsModel := atrackerService.NewDeleteRouteOptions(id) - deleteRouteOptionsModel.SetID("testString") - deleteRouteOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) - Expect(deleteRouteOptionsModel).ToNot(BeNil()) - Expect(deleteRouteOptionsModel.ID).To(Equal(core.StringPtr("testString"))) - Expect(deleteRouteOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) - }) - It(`Invoke NewDeleteTargetOptions successfully`, func() { - // Construct an instance of the DeleteTargetOptions model - id := "testString" - deleteTargetOptionsModel := atrackerService.NewDeleteTargetOptions(id) - deleteTargetOptionsModel.SetID("testString") - deleteTargetOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) - Expect(deleteTargetOptionsModel).ToNot(BeNil()) - Expect(deleteTargetOptionsModel.ID).To(Equal(core.StringPtr("testString"))) - Expect(deleteTargetOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) - }) - It(`Invoke NewGetEndpointsOptions successfully`, func() { - // Construct an instance of the GetEndpointsOptions model - getEndpointsOptionsModel := atrackerService.NewGetEndpointsOptions() - getEndpointsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) - Expect(getEndpointsOptionsModel).ToNot(BeNil()) - Expect(getEndpointsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) - }) - It(`Invoke NewGetRouteOptions successfully`, func() { - // Construct an instance of the GetRouteOptions model - id := "testString" - getRouteOptionsModel := atrackerService.NewGetRouteOptions(id) - getRouteOptionsModel.SetID("testString") - getRouteOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) - Expect(getRouteOptionsModel).ToNot(BeNil()) - Expect(getRouteOptionsModel.ID).To(Equal(core.StringPtr("testString"))) - Expect(getRouteOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) - }) - It(`Invoke NewGetTargetOptions successfully`, func() { - // Construct an instance of the GetTargetOptions model - id := "testString" - getTargetOptionsModel := atrackerService.NewGetTargetOptions(id) - getTargetOptionsModel.SetID("testString") - getTargetOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) - Expect(getTargetOptionsModel).ToNot(BeNil()) - Expect(getTargetOptionsModel.ID).To(Equal(core.StringPtr("testString"))) - Expect(getTargetOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) - }) - It(`Invoke NewListRoutesOptions successfully`, func() { - // Construct an instance of the ListRoutesOptions model - listRoutesOptionsModel := atrackerService.NewListRoutesOptions() - listRoutesOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) - Expect(listRoutesOptionsModel).ToNot(BeNil()) - Expect(listRoutesOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) - }) - It(`Invoke NewListTargetsOptions successfully`, func() { - // Construct an instance of the ListTargetsOptions model - listTargetsOptionsModel := atrackerService.NewListTargetsOptions() - listTargetsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) - Expect(listTargetsOptionsModel).ToNot(BeNil()) - Expect(listTargetsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) - }) - It(`Invoke NewPatchEndpointsOptions successfully`, func() { - // Construct an instance of the EndpointsRequestAPIEndpoint model - endpointsRequestAPIEndpointModel := new(atrackerv1.EndpointsRequestAPIEndpoint) - Expect(endpointsRequestAPIEndpointModel).ToNot(BeNil()) - endpointsRequestAPIEndpointModel.PublicEnabled = core.BoolPtr(true) - Expect(endpointsRequestAPIEndpointModel.PublicEnabled).To(Equal(core.BoolPtr(true))) - - // Construct an instance of the PatchEndpointsOptions model - patchEndpointsOptionsModel := atrackerService.NewPatchEndpointsOptions() - patchEndpointsOptionsModel.SetAPIEndpoint(endpointsRequestAPIEndpointModel) - patchEndpointsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) - Expect(patchEndpointsOptionsModel).ToNot(BeNil()) - Expect(patchEndpointsOptionsModel.APIEndpoint).To(Equal(endpointsRequestAPIEndpointModel)) - Expect(patchEndpointsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) - }) - It(`Invoke NewReplaceRouteOptions successfully`, func() { - // Construct an instance of the Rule model - ruleModel := new(atrackerv1.Rule) - Expect(ruleModel).ToNot(BeNil()) - ruleModel.TargetIds = []string{"c3af557f-fb0e-4476-85c3-0889e7fe7bc4"} - Expect(ruleModel.TargetIds).To(Equal([]string{"c3af557f-fb0e-4476-85c3-0889e7fe7bc4"})) - - // Construct an instance of the ReplaceRouteOptions model - id := "testString" - replaceRouteOptionsName := "my-route" - replaceRouteOptionsReceiveGlobalEvents := false - replaceRouteOptionsRules := []atrackerv1.Rule{} - replaceRouteOptionsModel := atrackerService.NewReplaceRouteOptions(id, replaceRouteOptionsName, replaceRouteOptionsReceiveGlobalEvents, replaceRouteOptionsRules) - replaceRouteOptionsModel.SetID("testString") - replaceRouteOptionsModel.SetName("my-route") - replaceRouteOptionsModel.SetReceiveGlobalEvents(false) - replaceRouteOptionsModel.SetRules([]atrackerv1.Rule{*ruleModel}) - replaceRouteOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) - Expect(replaceRouteOptionsModel).ToNot(BeNil()) - Expect(replaceRouteOptionsModel.ID).To(Equal(core.StringPtr("testString"))) - Expect(replaceRouteOptionsModel.Name).To(Equal(core.StringPtr("my-route"))) - Expect(replaceRouteOptionsModel.ReceiveGlobalEvents).To(Equal(core.BoolPtr(false))) - Expect(replaceRouteOptionsModel.Rules).To(Equal([]atrackerv1.Rule{*ruleModel})) - Expect(replaceRouteOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) - }) - It(`Invoke NewReplaceTargetOptions successfully`, func() { - // Construct an instance of the CosEndpoint model - cosEndpointModel := new(atrackerv1.CosEndpoint) - Expect(cosEndpointModel).ToNot(BeNil()) - cosEndpointModel.Endpoint = core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud") - cosEndpointModel.TargetCRN = core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::") - cosEndpointModel.Bucket = core.StringPtr("my-atracker-bucket") - cosEndpointModel.APIKey = core.StringPtr("xxxxxxxxxxxxxx") - Expect(cosEndpointModel.Endpoint).To(Equal(core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud"))) - Expect(cosEndpointModel.TargetCRN).To(Equal(core.StringPtr("crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::"))) - Expect(cosEndpointModel.Bucket).To(Equal(core.StringPtr("my-atracker-bucket"))) - Expect(cosEndpointModel.APIKey).To(Equal(core.StringPtr("xxxxxxxxxxxxxx"))) - - // Construct an instance of the ReplaceTargetOptions model - id := "testString" - replaceTargetOptionsName := "my-cos-target" - replaceTargetOptionsTargetType := "cloud_object_storage" - var replaceTargetOptionsCosEndpoint *atrackerv1.CosEndpoint = nil - replaceTargetOptionsModel := atrackerService.NewReplaceTargetOptions(id, replaceTargetOptionsName, replaceTargetOptionsTargetType, replaceTargetOptionsCosEndpoint) - replaceTargetOptionsModel.SetID("testString") - replaceTargetOptionsModel.SetName("my-cos-target") - replaceTargetOptionsModel.SetTargetType("cloud_object_storage") - replaceTargetOptionsModel.SetCosEndpoint(cosEndpointModel) - replaceTargetOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) - Expect(replaceTargetOptionsModel).ToNot(BeNil()) - Expect(replaceTargetOptionsModel.ID).To(Equal(core.StringPtr("testString"))) - Expect(replaceTargetOptionsModel.Name).To(Equal(core.StringPtr("my-cos-target"))) - Expect(replaceTargetOptionsModel.TargetType).To(Equal(core.StringPtr("cloud_object_storage"))) - Expect(replaceTargetOptionsModel.CosEndpoint).To(Equal(cosEndpointModel)) - Expect(replaceTargetOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) - }) - It(`Invoke NewRule successfully`, func() { - targetIds := []string{"c3af557f-fb0e-4476-85c3-0889e7fe7bc4"} - _model, err := atrackerService.NewRule(targetIds) - Expect(_model).ToNot(BeNil()) - Expect(err).To(BeNil()) - }) - It(`Invoke NewValidateTargetOptions successfully`, func() { - // Construct an instance of the ValidateTargetOptions model - id := "testString" - validateTargetOptionsModel := atrackerService.NewValidateTargetOptions(id) - validateTargetOptionsModel.SetID("testString") - validateTargetOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) - Expect(validateTargetOptionsModel).ToNot(BeNil()) - Expect(validateTargetOptionsModel.ID).To(Equal(core.StringPtr("testString"))) - Expect(validateTargetOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) - }) - It(`Invoke NewCosEndpoint successfully`, func() { - endpoint := "s3.private.us-east.cloud-object-storage.appdomain.cloud" - targetCRN := "crn:v1:bluemix:public:cloud-object-storage:global:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::" - bucket := "my-atracker-bucket" - apiKey := "xxxxxxxxxxxxxx" - _model, err := atrackerService.NewCosEndpoint(endpoint, targetCRN, bucket, apiKey) - Expect(_model).ToNot(BeNil()) - Expect(err).To(BeNil()) - }) - }) - }) - Describe(`Utility function tests`, func() { - It(`Invoke CreateMockByteArray() successfully`, func() { - mockByteArray := CreateMockByteArray("This is a test") - Expect(mockByteArray).ToNot(BeNil()) - }) - It(`Invoke CreateMockUUID() successfully`, func() { - mockUUID := CreateMockUUID("9fab83da-98cb-4f18-a7ba-b6f0435c9673") - Expect(mockUUID).ToNot(BeNil()) - }) - It(`Invoke CreateMockReader() successfully`, func() { - mockReader := CreateMockReader("This is a test.") - Expect(mockReader).ToNot(BeNil()) - }) - It(`Invoke CreateMockDate() successfully`, func() { - mockDate := CreateMockDate("2019-01-01") - Expect(mockDate).ToNot(BeNil()) - }) - It(`Invoke CreateMockDateTime() successfully`, func() { - mockDateTime := CreateMockDateTime("2019-01-01T12:00:00.000Z") - Expect(mockDateTime).ToNot(BeNil()) - }) - }) -}) - -// -// Utility functions used by the generated test code -// - -func CreateMockByteArray(mockData string) *[]byte { - ba := make([]byte, 0) - ba = append(ba, mockData...) - return &ba -} - -func CreateMockUUID(mockData string) *strfmt.UUID { - uuid := strfmt.UUID(mockData) - return &uuid -} - -func CreateMockReader(mockData string) io.ReadCloser { - return io.NopCloser(bytes.NewReader([]byte(mockData))) -} - -func CreateMockDate(mockData string) *strfmt.Date { - d, err := core.ParseDate(mockData) - if err != nil { - return nil - } - return &d -} - -func CreateMockDateTime(mockData string) *strfmt.DateTime { - d, err := core.ParseDateTime(mockData) - if err != nil { - return nil - } - return &d -} - -func SetTestEnvironment(testEnvironment map[string]string) { - for key, value := range testEnvironment { - os.Setenv(key, value) - } -} - -func ClearTestEnvironment(testEnvironment map[string]string) { - for key := range testEnvironment { - os.Unsetenv(key) - } -}