/* STACKIT Run Commands Service API Testing DefaultApiService */ // Code generated by OpenAPI Generator (https://openapi-generator.tech); package runcommandbeta import ( "context" "encoding/json" "net/http" "net/http/httptest" "net/url" "strings" "testing" "github.com/stackitcloud/stackit-sdk-go/core/config" ) func Test_runcommandbeta_DefaultApiService(t *testing.T) { t.Run("Test DefaultApiService CreateCommand", func(t *testing.T) { _apiUrlPath := "/v2beta/projects/{projectId}/regions/{region}/servers/{serverId}/commands" projectIdValue := "projectId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) serverIdValue := "serverId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"serverId"+"}", url.PathEscape(ParameterValueToString(serverIdValue, "serverId")), -1) regionValue := "region-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"region"+"}", url.PathEscape(ParameterValueToString(regionValue, "region")), -1) testDefaultApiServeMux := http.NewServeMux() testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) { data := NewCommandResponse{} 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 runcommandbeta_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 serverId := serverIdValue region := regionValue resp, reqErr := apiClient.CreateCommand(context.Background(), projectId, serverId, region).Execute() if reqErr != nil { t.Fatalf("error in call: %v", reqErr) } if IsNil(resp) { t.Fatalf("response not present") } }) t.Run("Test DefaultApiService GetCommand", func(t *testing.T) { _apiUrlPath := "/v2beta/projects/{projectId}/regions/{region}/servers/{serverId}/commands/{commandId}" projectIdValue := "projectId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) regionValue := "region-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"region"+"}", url.PathEscape(ParameterValueToString(regionValue, "region")), -1) serverIdValue := "serverId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"serverId"+"}", url.PathEscape(ParameterValueToString(serverIdValue, "serverId")), -1) commandIdValue := "commandId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"commandId"+"}", url.PathEscape(ParameterValueToString(commandIdValue, "commandId")), -1) testDefaultApiServeMux := http.NewServeMux() testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) { data := CommandDetails{} 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 runcommandbeta_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 region := regionValue serverId := serverIdValue commandId := commandIdValue resp, reqErr := apiClient.GetCommand(context.Background(), projectId, region, serverId, commandId).Execute() if reqErr != nil { t.Fatalf("error in call: %v", reqErr) } if IsNil(resp) { t.Fatalf("response not present") } }) t.Run("Test DefaultApiService GetCommandTemplate", func(t *testing.T) { _apiUrlPath := "/v2beta/projects/{projectId}/regions/{region}/servers/{serverId}/command-templates/{commandTemplateName}" projectIdValue := "projectId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) serverIdValue := "serverId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"serverId"+"}", url.PathEscape(ParameterValueToString(serverIdValue, "serverId")), -1) commandTemplateNameValue := "commandTemplateName-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"commandTemplateName"+"}", url.PathEscape(ParameterValueToString(commandTemplateNameValue, "commandTemplateName")), -1) regionValue := "region-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"region"+"}", url.PathEscape(ParameterValueToString(regionValue, "region")), -1) testDefaultApiServeMux := http.NewServeMux() testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) { data := CommandTemplateSchema{} 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 runcommandbeta_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 serverId := serverIdValue commandTemplateName := commandTemplateNameValue region := regionValue resp, reqErr := apiClient.GetCommandTemplate(context.Background(), projectId, serverId, commandTemplateName, region).Execute() if reqErr != nil { t.Fatalf("error in call: %v", reqErr) } if IsNil(resp) { t.Fatalf("response not present") } }) t.Run("Test DefaultApiService ListCommandTemplates", func(t *testing.T) { _apiUrlPath := "/v2beta/command-templates" testDefaultApiServeMux := http.NewServeMux() testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) { data := CommandTemplateResponse{} 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 runcommandbeta_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) } resp, reqErr := apiClient.ListCommandTemplates(context.Background()).Execute() if reqErr != nil { t.Fatalf("error in call: %v", reqErr) } if IsNil(resp) { t.Fatalf("response not present") } }) t.Run("Test DefaultApiService ListCommands", func(t *testing.T) { _apiUrlPath := "/v2beta/projects/{projectId}/regions/{region}/servers/{serverId}/commands" projectIdValue := "projectId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) serverIdValue := "serverId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"serverId"+"}", url.PathEscape(ParameterValueToString(serverIdValue, "serverId")), -1) regionValue := "region-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"region"+"}", url.PathEscape(ParameterValueToString(regionValue, "region")), -1) testDefaultApiServeMux := http.NewServeMux() testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) { data := GetCommandsResponse{} 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 runcommandbeta_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 serverId := serverIdValue region := regionValue resp, reqErr := apiClient.ListCommands(context.Background(), projectId, serverId, region).Execute() if reqErr != nil { t.Fatalf("error in call: %v", reqErr) } if IsNil(resp) { t.Fatalf("response not present") } }) }