terraform-provider-stackitp.../pkg/cdnbeta/api_default_test.go

804 lines
27 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: Apache-2.0
/*
CDN API
Testing DefaultApiService
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech);
package cdnbeta
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
"time"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-sdk-go/core/config"
)
func Test_cdnbeta_DefaultApiService(t *testing.T) {
t.Run("Test DefaultApiService CreateDistribution", func(t *testing.T) {
_apiUrlPath := "/v1beta2/projects/{projectId}/distributions"
projectIdValue := "projectId-value"
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1)
testDefaultApiServeMux := http.NewServeMux()
testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) {
data := CreateDistributionResponse{}
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(data)
})
testServer := httptest.NewServer(testDefaultApiServeMux)
defer testServer.Close()
configuration := &config.Configuration{
DefaultHeader: make(map[string]string),
UserAgent: "OpenAPI-Generator/1.0.0/go",
Debug: false,
Region: "test_region",
Servers: config.ServerConfigurations{
{
URL: testServer.URL,
Description: "Localhost for cdnbeta_DefaultApi",
Variables: map[string]config.ServerVariable{
"region": {
DefaultValue: "test_region.",
EnumValues: []string{
"test_region.",
},
},
},
},
},
OperationServers: map[string]config.ServerConfigurations{},
}
apiClient, err := NewAPIClient(config.WithCustomConfiguration(configuration), config.WithoutAuthentication())
if err != nil {
t.Fatalf("creating API client: %v", err)
}
projectId := projectIdValue
createDistributionPayload := CreateDistributionPayload{}
resp, reqErr := apiClient.CreateDistribution(context.Background(), projectId).CreateDistributionPayload(createDistributionPayload).Execute()
if reqErr != nil {
t.Fatalf("error in call: %v", reqErr)
}
if IsNil(resp) {
t.Fatalf("response not present")
}
})
t.Run("Test DefaultApiService DeleteCustomDomain", func(t *testing.T) {
_apiUrlPath := "/v1beta2/projects/{projectId}/distributions/{distributionId}/customDomains/{domain}"
projectIdValue := "projectId-value"
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1)
distributionIdValue := uuid.NewString()
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"distributionId"+"}", url.PathEscape(ParameterValueToString(distributionIdValue, "distributionId")), -1)
domainValue := randString(72)
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"domain"+"}", url.PathEscape(ParameterValueToString(domainValue, "domain")), -1)
testDefaultApiServeMux := http.NewServeMux()
testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) {
data := DeleteCustomDomainResponse{}
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(data)
})
testServer := httptest.NewServer(testDefaultApiServeMux)
defer testServer.Close()
configuration := &config.Configuration{
DefaultHeader: make(map[string]string),
UserAgent: "OpenAPI-Generator/1.0.0/go",
Debug: false,
Region: "test_region",
Servers: config.ServerConfigurations{
{
URL: testServer.URL,
Description: "Localhost for cdnbeta_DefaultApi",
Variables: map[string]config.ServerVariable{
"region": {
DefaultValue: "test_region.",
EnumValues: []string{
"test_region.",
},
},
},
},
},
OperationServers: map[string]config.ServerConfigurations{},
}
apiClient, err := NewAPIClient(config.WithCustomConfiguration(configuration), config.WithoutAuthentication())
if err != nil {
t.Fatalf("creating API client: %v", err)
}
projectId := projectIdValue
distributionId := distributionIdValue
domain := domainValue
resp, reqErr := apiClient.DeleteCustomDomain(context.Background(), projectId, distributionId, domain).Execute()
if reqErr != nil {
t.Fatalf("error in call: %v", reqErr)
}
if IsNil(resp) {
t.Fatalf("response not present")
}
})
t.Run("Test DefaultApiService DeleteDistribution", func(t *testing.T) {
_apiUrlPath := "/v1beta2/projects/{projectId}/distributions/{distributionId}"
projectIdValue := "projectId-value"
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1)
distributionIdValue := uuid.NewString()
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"distributionId"+"}", url.PathEscape(ParameterValueToString(distributionIdValue, "distributionId")), -1)
testDefaultApiServeMux := http.NewServeMux()
testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) {
data := DeleteDistributionResponse{}
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(data)
})
testServer := httptest.NewServer(testDefaultApiServeMux)
defer testServer.Close()
configuration := &config.Configuration{
DefaultHeader: make(map[string]string),
UserAgent: "OpenAPI-Generator/1.0.0/go",
Debug: false,
Region: "test_region",
Servers: config.ServerConfigurations{
{
URL: testServer.URL,
Description: "Localhost for cdnbeta_DefaultApi",
Variables: map[string]config.ServerVariable{
"region": {
DefaultValue: "test_region.",
EnumValues: []string{
"test_region.",
},
},
},
},
},
OperationServers: map[string]config.ServerConfigurations{},
}
apiClient, err := NewAPIClient(config.WithCustomConfiguration(configuration), config.WithoutAuthentication())
if err != nil {
t.Fatalf("creating API client: %v", err)
}
projectId := projectIdValue
distributionId := distributionIdValue
resp, reqErr := apiClient.DeleteDistribution(context.Background(), projectId, distributionId).Execute()
if reqErr != nil {
t.Fatalf("error in call: %v", reqErr)
}
if IsNil(resp) {
t.Fatalf("response not present")
}
})
t.Run("Test DefaultApiService FindCachePaths", func(t *testing.T) {
_apiUrlPath := "/v1beta2/projects/{projectId}/distributions/{distributionId}/cache/paths"
projectIdValue := "projectId-value"
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1)
distributionIdValue := uuid.NewString()
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"distributionId"+"}", url.PathEscape(ParameterValueToString(distributionIdValue, "distributionId")), -1)
testDefaultApiServeMux := http.NewServeMux()
testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) {
data := FindCachePathsResponse{}
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(data)
})
testServer := httptest.NewServer(testDefaultApiServeMux)
defer testServer.Close()
configuration := &config.Configuration{
DefaultHeader: make(map[string]string),
UserAgent: "OpenAPI-Generator/1.0.0/go",
Debug: false,
Region: "test_region",
Servers: config.ServerConfigurations{
{
URL: testServer.URL,
Description: "Localhost for cdnbeta_DefaultApi",
Variables: map[string]config.ServerVariable{
"region": {
DefaultValue: "test_region.",
EnumValues: []string{
"test_region.",
},
},
},
},
},
OperationServers: map[string]config.ServerConfigurations{},
}
apiClient, err := NewAPIClient(config.WithCustomConfiguration(configuration), config.WithoutAuthentication())
if err != nil {
t.Fatalf("creating API client: %v", err)
}
projectId := projectIdValue
distributionId := distributionIdValue
var path string
resp, reqErr := apiClient.FindCachePaths(context.Background(), projectId, distributionId).Path(path).Execute()
if reqErr != nil {
t.Fatalf("error in call: %v", reqErr)
}
if IsNil(resp) {
t.Fatalf("response not present")
}
})
t.Run("Test DefaultApiService GetCacheInfo", func(t *testing.T) {
_apiUrlPath := "/v1beta2/projects/{projectId}/distributions/{distributionId}/cache"
projectIdValue := "projectId-value"
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1)
distributionIdValue := uuid.NewString()
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"distributionId"+"}", url.PathEscape(ParameterValueToString(distributionIdValue, "distributionId")), -1)
testDefaultApiServeMux := http.NewServeMux()
testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) {
data := GetCacheInfoResponse{}
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(data)
})
testServer := httptest.NewServer(testDefaultApiServeMux)
defer testServer.Close()
configuration := &config.Configuration{
DefaultHeader: make(map[string]string),
UserAgent: "OpenAPI-Generator/1.0.0/go",
Debug: false,
Region: "test_region",
Servers: config.ServerConfigurations{
{
URL: testServer.URL,
Description: "Localhost for cdnbeta_DefaultApi",
Variables: map[string]config.ServerVariable{
"region": {
DefaultValue: "test_region.",
EnumValues: []string{
"test_region.",
},
},
},
},
},
OperationServers: map[string]config.ServerConfigurations{},
}
apiClient, err := NewAPIClient(config.WithCustomConfiguration(configuration), config.WithoutAuthentication())
if err != nil {
t.Fatalf("creating API client: %v", err)
}
projectId := projectIdValue
distributionId := distributionIdValue
resp, reqErr := apiClient.GetCacheInfo(context.Background(), projectId, distributionId).Execute()
if reqErr != nil {
t.Fatalf("error in call: %v", reqErr)
}
if IsNil(resp) {
t.Fatalf("response not present")
}
})
t.Run("Test DefaultApiService GetCustomDomain", func(t *testing.T) {
_apiUrlPath := "/v1beta2/projects/{projectId}/distributions/{distributionId}/customDomains/{domain}"
projectIdValue := "projectId-value"
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1)
distributionIdValue := uuid.NewString()
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"distributionId"+"}", url.PathEscape(ParameterValueToString(distributionIdValue, "distributionId")), -1)
domainValue := randString(72)
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"domain"+"}", url.PathEscape(ParameterValueToString(domainValue, "domain")), -1)
testDefaultApiServeMux := http.NewServeMux()
testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) {
data := GetCustomDomainResponse{}
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(data)
})
testServer := httptest.NewServer(testDefaultApiServeMux)
defer testServer.Close()
configuration := &config.Configuration{
DefaultHeader: make(map[string]string),
UserAgent: "OpenAPI-Generator/1.0.0/go",
Debug: false,
Region: "test_region",
Servers: config.ServerConfigurations{
{
URL: testServer.URL,
Description: "Localhost for cdnbeta_DefaultApi",
Variables: map[string]config.ServerVariable{
"region": {
DefaultValue: "test_region.",
EnumValues: []string{
"test_region.",
},
},
},
},
},
OperationServers: map[string]config.ServerConfigurations{},
}
apiClient, err := NewAPIClient(config.WithCustomConfiguration(configuration), config.WithoutAuthentication())
if err != nil {
t.Fatalf("creating API client: %v", err)
}
projectId := projectIdValue
distributionId := distributionIdValue
domain := domainValue
resp, reqErr := apiClient.GetCustomDomain(context.Background(), projectId, distributionId, domain).Execute()
if reqErr != nil {
t.Fatalf("error in call: %v", reqErr)
}
if IsNil(resp) {
t.Fatalf("response not present")
}
})
t.Run("Test DefaultApiService GetDistribution", func(t *testing.T) {
_apiUrlPath := "/v1beta2/projects/{projectId}/distributions/{distributionId}"
projectIdValue := "projectId-value"
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1)
distributionIdValue := uuid.NewString()
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"distributionId"+"}", url.PathEscape(ParameterValueToString(distributionIdValue, "distributionId")), -1)
testDefaultApiServeMux := http.NewServeMux()
testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) {
data := GetDistributionResponse{}
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(data)
})
testServer := httptest.NewServer(testDefaultApiServeMux)
defer testServer.Close()
configuration := &config.Configuration{
DefaultHeader: make(map[string]string),
UserAgent: "OpenAPI-Generator/1.0.0/go",
Debug: false,
Region: "test_region",
Servers: config.ServerConfigurations{
{
URL: testServer.URL,
Description: "Localhost for cdnbeta_DefaultApi",
Variables: map[string]config.ServerVariable{
"region": {
DefaultValue: "test_region.",
EnumValues: []string{
"test_region.",
},
},
},
},
},
OperationServers: map[string]config.ServerConfigurations{},
}
apiClient, err := NewAPIClient(config.WithCustomConfiguration(configuration), config.WithoutAuthentication())
if err != nil {
t.Fatalf("creating API client: %v", err)
}
projectId := projectIdValue
distributionId := distributionIdValue
resp, reqErr := apiClient.GetDistribution(context.Background(), projectId, distributionId).Execute()
if reqErr != nil {
t.Fatalf("error in call: %v", reqErr)
}
if IsNil(resp) {
t.Fatalf("response not present")
}
})
t.Run("Test DefaultApiService GetLogs", func(t *testing.T) {
_apiUrlPath := "/v1beta2/projects/{projectId}/distributions/{distributionId}/logs"
projectIdValue := "projectId-value"
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1)
distributionIdValue := uuid.NewString()
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"distributionId"+"}", url.PathEscape(ParameterValueToString(distributionIdValue, "distributionId")), -1)
testDefaultApiServeMux := http.NewServeMux()
testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) {
data := GetLogsResponse{}
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(data)
})
testServer := httptest.NewServer(testDefaultApiServeMux)
defer testServer.Close()
configuration := &config.Configuration{
DefaultHeader: make(map[string]string),
UserAgent: "OpenAPI-Generator/1.0.0/go",
Debug: false,
Region: "test_region",
Servers: config.ServerConfigurations{
{
URL: testServer.URL,
Description: "Localhost for cdnbeta_DefaultApi",
Variables: map[string]config.ServerVariable{
"region": {
DefaultValue: "test_region.",
EnumValues: []string{
"test_region.",
},
},
},
},
},
OperationServers: map[string]config.ServerConfigurations{},
}
apiClient, err := NewAPIClient(config.WithCustomConfiguration(configuration), config.WithoutAuthentication())
if err != nil {
t.Fatalf("creating API client: %v", err)
}
projectId := projectIdValue
distributionId := distributionIdValue
resp, reqErr := apiClient.GetLogs(context.Background(), projectId, distributionId).Execute()
if reqErr != nil {
t.Fatalf("error in call: %v", reqErr)
}
if IsNil(resp) {
t.Fatalf("response not present")
}
})
t.Run("Test DefaultApiService GetStatistics", func(t *testing.T) {
_apiUrlPath := "/v1beta2/projects/{projectId}/distributions/{distributionId}/statistics"
projectIdValue := "projectId-value"
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1)
distributionIdValue := uuid.NewString()
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"distributionId"+"}", url.PathEscape(ParameterValueToString(distributionIdValue, "distributionId")), -1)
testDefaultApiServeMux := http.NewServeMux()
testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) {
data := GetStatisticsResponse{}
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(data)
})
testServer := httptest.NewServer(testDefaultApiServeMux)
defer testServer.Close()
configuration := &config.Configuration{
DefaultHeader: make(map[string]string),
UserAgent: "OpenAPI-Generator/1.0.0/go",
Debug: false,
Region: "test_region",
Servers: config.ServerConfigurations{
{
URL: testServer.URL,
Description: "Localhost for cdnbeta_DefaultApi",
Variables: map[string]config.ServerVariable{
"region": {
DefaultValue: "test_region.",
EnumValues: []string{
"test_region.",
},
},
},
},
},
OperationServers: map[string]config.ServerConfigurations{},
}
apiClient, err := NewAPIClient(config.WithCustomConfiguration(configuration), config.WithoutAuthentication())
if err != nil {
t.Fatalf("creating API client: %v", err)
}
projectId := projectIdValue
distributionId := distributionIdValue
var from time.Time
resp, reqErr := apiClient.GetStatistics(context.Background(), projectId, distributionId).From(from).Execute()
if reqErr != nil {
t.Fatalf("error in call: %v", reqErr)
}
if IsNil(resp) {
t.Fatalf("response not present")
}
})
t.Run("Test DefaultApiService ListDistributions", func(t *testing.T) {
_apiUrlPath := "/v1beta2/projects/{projectId}/distributions"
projectIdValue := "projectId-value"
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1)
testDefaultApiServeMux := http.NewServeMux()
testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) {
data := ListDistributionsResponse{}
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(data)
})
testServer := httptest.NewServer(testDefaultApiServeMux)
defer testServer.Close()
configuration := &config.Configuration{
DefaultHeader: make(map[string]string),
UserAgent: "OpenAPI-Generator/1.0.0/go",
Debug: false,
Region: "test_region",
Servers: config.ServerConfigurations{
{
URL: testServer.URL,
Description: "Localhost for cdnbeta_DefaultApi",
Variables: map[string]config.ServerVariable{
"region": {
DefaultValue: "test_region.",
EnumValues: []string{
"test_region.",
},
},
},
},
},
OperationServers: map[string]config.ServerConfigurations{},
}
apiClient, err := NewAPIClient(config.WithCustomConfiguration(configuration), config.WithoutAuthentication())
if err != nil {
t.Fatalf("creating API client: %v", err)
}
projectId := projectIdValue
resp, reqErr := apiClient.ListDistributions(context.Background(), projectId).Execute()
if reqErr != nil {
t.Fatalf("error in call: %v", reqErr)
}
if IsNil(resp) {
t.Fatalf("response not present")
}
})
t.Run("Test DefaultApiService ListWafCollections", func(t *testing.T) {
_apiUrlPath := "/v1beta2/projects/{projectId}/waf/collections"
projectIdValue := "projectId-value"
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1)
testDefaultApiServeMux := http.NewServeMux()
testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) {
data := ListWafCollectionsResponse{}
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(data)
})
testServer := httptest.NewServer(testDefaultApiServeMux)
defer testServer.Close()
configuration := &config.Configuration{
DefaultHeader: make(map[string]string),
UserAgent: "OpenAPI-Generator/1.0.0/go",
Debug: false,
Region: "test_region",
Servers: config.ServerConfigurations{
{
URL: testServer.URL,
Description: "Localhost for cdnbeta_DefaultApi",
Variables: map[string]config.ServerVariable{
"region": {
DefaultValue: "test_region.",
EnumValues: []string{
"test_region.",
},
},
},
},
},
OperationServers: map[string]config.ServerConfigurations{},
}
apiClient, err := NewAPIClient(config.WithCustomConfiguration(configuration), config.WithoutAuthentication())
if err != nil {
t.Fatalf("creating API client: %v", err)
}
projectId := projectIdValue
resp, reqErr := apiClient.ListWafCollections(context.Background(), projectId).Execute()
if reqErr != nil {
t.Fatalf("error in call: %v", reqErr)
}
if IsNil(resp) {
t.Fatalf("response not present")
}
})
t.Run("Test DefaultApiService PatchDistribution", func(t *testing.T) {
_apiUrlPath := "/v1beta2/projects/{projectId}/distributions/{distributionId}"
projectIdValue := "projectId-value"
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1)
distributionIdValue := "distributionId-value"
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"distributionId"+"}", url.PathEscape(ParameterValueToString(distributionIdValue, "distributionId")), -1)
testDefaultApiServeMux := http.NewServeMux()
testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) {
data := PatchDistributionResponse{}
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(data)
})
testServer := httptest.NewServer(testDefaultApiServeMux)
defer testServer.Close()
configuration := &config.Configuration{
DefaultHeader: make(map[string]string),
UserAgent: "OpenAPI-Generator/1.0.0/go",
Debug: false,
Region: "test_region",
Servers: config.ServerConfigurations{
{
URL: testServer.URL,
Description: "Localhost for cdnbeta_DefaultApi",
Variables: map[string]config.ServerVariable{
"region": {
DefaultValue: "test_region.",
EnumValues: []string{
"test_region.",
},
},
},
},
},
OperationServers: map[string]config.ServerConfigurations{},
}
apiClient, err := NewAPIClient(config.WithCustomConfiguration(configuration), config.WithoutAuthentication())
if err != nil {
t.Fatalf("creating API client: %v", err)
}
projectId := projectIdValue
distributionId := distributionIdValue
resp, reqErr := apiClient.PatchDistribution(context.Background(), projectId, distributionId).Execute()
if reqErr != nil {
t.Fatalf("error in call: %v", reqErr)
}
if IsNil(resp) {
t.Fatalf("response not present")
}
})
t.Run("Test DefaultApiService PurgeCache", func(t *testing.T) {
_apiUrlPath := "/v1beta2/projects/{projectId}/distributions/{distributionId}/cache/purge"
projectIdValue := "projectId-value"
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1)
distributionIdValue := uuid.NewString()
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"distributionId"+"}", url.PathEscape(ParameterValueToString(distributionIdValue, "distributionId")), -1)
testDefaultApiServeMux := http.NewServeMux()
testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) {
data := map[string]interface{}{}
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(data)
})
testServer := httptest.NewServer(testDefaultApiServeMux)
defer testServer.Close()
configuration := &config.Configuration{
DefaultHeader: make(map[string]string),
UserAgent: "OpenAPI-Generator/1.0.0/go",
Debug: false,
Region: "test_region",
Servers: config.ServerConfigurations{
{
URL: testServer.URL,
Description: "Localhost for cdnbeta_DefaultApi",
Variables: map[string]config.ServerVariable{
"region": {
DefaultValue: "test_region.",
EnumValues: []string{
"test_region.",
},
},
},
},
},
OperationServers: map[string]config.ServerConfigurations{},
}
apiClient, err := NewAPIClient(config.WithCustomConfiguration(configuration), config.WithoutAuthentication())
if err != nil {
t.Fatalf("creating API client: %v", err)
}
projectId := projectIdValue
distributionId := distributionIdValue
resp, reqErr := apiClient.PurgeCache(context.Background(), projectId, distributionId).Execute()
if reqErr != nil {
t.Fatalf("error in call: %v", reqErr)
}
if IsNil(resp) {
t.Fatalf("response not present")
}
})
t.Run("Test DefaultApiService PutCustomDomain", func(t *testing.T) {
_apiUrlPath := "/v1beta2/projects/{projectId}/distributions/{distributionId}/customDomains/{domain}"
projectIdValue := "projectId-value"
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1)
distributionIdValue := uuid.NewString()
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"distributionId"+"}", url.PathEscape(ParameterValueToString(distributionIdValue, "distributionId")), -1)
domainValue := randString(72)
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"domain"+"}", url.PathEscape(ParameterValueToString(domainValue, "domain")), -1)
testDefaultApiServeMux := http.NewServeMux()
testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) {
data := PutCustomDomainResponse{}
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(data)
})
testServer := httptest.NewServer(testDefaultApiServeMux)
defer testServer.Close()
configuration := &config.Configuration{
DefaultHeader: make(map[string]string),
UserAgent: "OpenAPI-Generator/1.0.0/go",
Debug: false,
Region: "test_region",
Servers: config.ServerConfigurations{
{
URL: testServer.URL,
Description: "Localhost for cdnbeta_DefaultApi",
Variables: map[string]config.ServerVariable{
"region": {
DefaultValue: "test_region.",
EnumValues: []string{
"test_region.",
},
},
},
},
},
OperationServers: map[string]config.ServerConfigurations{},
}
apiClient, err := NewAPIClient(config.WithCustomConfiguration(configuration), config.WithoutAuthentication())
if err != nil {
t.Fatalf("creating API client: %v", err)
}
projectId := projectIdValue
distributionId := distributionIdValue
domain := domainValue
resp, reqErr := apiClient.PutCustomDomain(context.Background(), projectId, distributionId, domain).Execute()
if reqErr != nil {
t.Fatalf("error in call: %v", reqErr)
}
if IsNil(resp) {
t.Fatalf("response not present")
}
})
}