From fe683e34222b4f328cccba3cf83bd7ba515da65e Mon Sep 17 00:00:00 2001 From: Drew Malin Date: Thu, 28 Aug 2025 10:00:42 -0700 Subject: [PATCH 1/2] fix(BREV-1638): fix compilation error on shadeform validation test --- .../gen/shadeform/test/api_default_test.go | 53 ++----------------- 1 file changed, 3 insertions(+), 50 deletions(-) diff --git a/internal/shadeform/gen/shadeform/test/api_default_test.go b/internal/shadeform/gen/shadeform/test/api_default_test.go index 2ba4390..ed79488 100644 --- a/internal/shadeform/gen/shadeform/test/api_default_test.go +++ b/internal/shadeform/gen/shadeform/test/api_default_test.go @@ -11,19 +11,18 @@ package openapi import ( "context" - openapiclient "github.com/brevdev/cloud" + "testing" + + openapiclient "github.com/brevdev/cloud/internal/shadeform/gen/shadeform" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" ) func Test_openapi_DefaultAPIService(t *testing.T) { - configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) t.Run("Test DefaultAPIService Instances", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.DefaultAPI.Instances(context.Background()).Execute() @@ -31,11 +30,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService InstancesCreate", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.DefaultAPI.InstancesCreate(context.Background()).Execute() @@ -43,11 +40,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService InstancesDelete", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -56,11 +51,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService InstancesInfo", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -70,11 +63,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService InstancesRestart", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -83,11 +74,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService InstancesTypes", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.DefaultAPI.InstancesTypes(context.Background()).Execute() @@ -95,11 +84,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService InstancesUpdate", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -108,11 +95,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService SshKeys", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.DefaultAPI.SshKeys(context.Background()).Execute() @@ -120,11 +105,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService SshKeysAdd", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.DefaultAPI.SshKeysAdd(context.Background()).Execute() @@ -132,11 +115,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService SshKeysDelete", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -145,11 +126,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService SshKeysInfo", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -159,11 +138,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService SshKeysSetDefault", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -172,11 +149,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService Templates", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.DefaultAPI.Templates(context.Background()).Execute() @@ -184,11 +159,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService TemplatesDelete", func(t *testing.T) { - t.Skip("skip test") // remove to run test var templateId string @@ -197,11 +170,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService TemplatesFeatured", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.DefaultAPI.TemplatesFeatured(context.Background()).Execute() @@ -209,11 +180,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService TemplatesInfo", func(t *testing.T) { - t.Skip("skip test") // remove to run test var templateId string @@ -223,11 +192,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService TemplatesSave", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.DefaultAPI.TemplatesSave(context.Background()).Execute() @@ -235,11 +202,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService TemplatesUpdate", func(t *testing.T) { - t.Skip("skip test") // remove to run test var templateId string @@ -248,11 +213,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService Volumes", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.DefaultAPI.Volumes(context.Background()).Execute() @@ -260,11 +223,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService VolumesCreate", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.DefaultAPI.VolumesCreate(context.Background()).Execute() @@ -272,11 +233,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService VolumesDelete", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -285,11 +244,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService VolumesInfo", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -299,11 +256,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService VolumesTypes", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.DefaultAPI.VolumesTypes(context.Background()).Execute() @@ -311,7 +266,5 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) - } From 3e51a97e49613214ad815cd5ce120afc4f75b1d5 Mon Sep 17 00:00:00 2001 From: Drew Malin Date: Thu, 28 Aug 2025 10:25:23 -0700 Subject: [PATCH 2/2] gofumpt, linting --- Makefile | 8 +++---- .../fluidstack/test/api_capabilities_test.go | 7 ++---- .../gen/fluidstack/test/api_capacity_test.go | 7 ++---- .../fluidstack/test/api_filesystems_test.go | 13 ++--------- .../test/api_instance_types_test.go | 7 ++---- .../gen/fluidstack/test/api_instances_test.go | 17 ++------------ .../fluidstack/test/api_kubernetes_test.go | 23 ++----------------- .../gen/fluidstack/test/api_projects_test.go | 13 ++--------- .../gen/fluidstack/test/api_slurm_test.go | 21 ++--------------- .../gen/lambdalabs/test/api_default_test.go | 22 ------------------ internal/shadeform/v1/capabilities.go | 1 + internal/shadeform/v1/client.go | 11 ++++----- internal/shadeform/v1/configuration.go | 1 - internal/shadeform/v1/instance.go | 13 ++++++----- internal/shadeform/v1/instancetype.go | 6 ++--- internal/shadeform/v1/ufw.go | 3 ++- internal/shadeform/v1/validation_test.go | 12 ++++++---- 17 files changed, 45 insertions(+), 140 deletions(-) diff --git a/Makefile b/Makefile index 154128f..87d0f54 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ GOGET=$(GOCMD) get GOMOD=$(GOCMD) mod GOLINT=golangci-lint GOVET=$(GOCMD) vet -GOFMT=gofmt +GOFMT=gofumpt GOSEC=gosec # Build flags @@ -122,15 +122,15 @@ vet: .PHONY: fmt fmt: @echo "Formatting code..." - $(GOFMT) -s -w . + $(GOFMT) -w . # Check if code is formatted .PHONY: fmt-check fmt-check: @echo "Checking code formatting..." - @if [ "$$(gofmt -s -l . | wc -l)" -gt 0 ]; then \ + @if [ "$$($(GOFMT) -l . | wc -l)" -gt 0 ]; then \ echo "Code is not formatted. Run 'make fmt' to format."; \ - gofmt -s -l .; \ + $(GOFMT) -l .; \ exit 1; \ else \ echo "Code is properly formatted."; \ diff --git a/internal/fluidstack/gen/fluidstack/test/api_capabilities_test.go b/internal/fluidstack/gen/fluidstack/test/api_capabilities_test.go index 9228757..2cdf48b 100644 --- a/internal/fluidstack/gen/fluidstack/test/api_capabilities_test.go +++ b/internal/fluidstack/gen/fluidstack/test/api_capabilities_test.go @@ -11,19 +11,18 @@ package openapi import ( "context" + "testing" + openapiclient "github.com/brevdev/cloud/internal/fluidstack/gen/fluidstack" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" ) func Test_openapi_CapabilitiesAPIService(t *testing.T) { - configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) t.Run("Test CapabilitiesAPIService ListCapabilities", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.CapabilitiesAPI.ListCapabilities(context.Background()).Execute() @@ -31,7 +30,5 @@ func Test_openapi_CapabilitiesAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) - } diff --git a/internal/fluidstack/gen/fluidstack/test/api_capacity_test.go b/internal/fluidstack/gen/fluidstack/test/api_capacity_test.go index 74100ff..619d438 100644 --- a/internal/fluidstack/gen/fluidstack/test/api_capacity_test.go +++ b/internal/fluidstack/gen/fluidstack/test/api_capacity_test.go @@ -11,19 +11,18 @@ package openapi import ( "context" + "testing" + openapiclient "github.com/brevdev/cloud/internal/fluidstack/gen/fluidstack" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" ) func Test_openapi_CapacityAPIService(t *testing.T) { - configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) t.Run("Test CapacityAPIService ListCapacity", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.CapacityAPI.ListCapacity(context.Background()).Execute() @@ -31,7 +30,5 @@ func Test_openapi_CapacityAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) - } diff --git a/internal/fluidstack/gen/fluidstack/test/api_filesystems_test.go b/internal/fluidstack/gen/fluidstack/test/api_filesystems_test.go index 48a2149..16241f4 100644 --- a/internal/fluidstack/gen/fluidstack/test/api_filesystems_test.go +++ b/internal/fluidstack/gen/fluidstack/test/api_filesystems_test.go @@ -11,19 +11,18 @@ package openapi import ( "context" + "testing" + openapiclient "github.com/brevdev/cloud/internal/fluidstack/gen/fluidstack" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" ) func Test_openapi_FilesystemsAPIService(t *testing.T) { - configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) t.Run("Test FilesystemsAPIService CreateFilesystem", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.FilesystemsAPI.CreateFilesystem(context.Background()).Execute() @@ -31,11 +30,9 @@ func Test_openapi_FilesystemsAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test FilesystemsAPIService DeleteFilesystem", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -44,11 +41,9 @@ func Test_openapi_FilesystemsAPIService(t *testing.T) { require.Nil(t, err) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test FilesystemsAPIService GetFilesystem", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -58,11 +53,9 @@ func Test_openapi_FilesystemsAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test FilesystemsAPIService ListFilesystems", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.FilesystemsAPI.ListFilesystems(context.Background()).Execute() @@ -70,7 +63,5 @@ func Test_openapi_FilesystemsAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) - } diff --git a/internal/fluidstack/gen/fluidstack/test/api_instance_types_test.go b/internal/fluidstack/gen/fluidstack/test/api_instance_types_test.go index 279f207..2f08599 100644 --- a/internal/fluidstack/gen/fluidstack/test/api_instance_types_test.go +++ b/internal/fluidstack/gen/fluidstack/test/api_instance_types_test.go @@ -11,19 +11,18 @@ package openapi import ( "context" + "testing" + openapiclient "github.com/brevdev/cloud/internal/fluidstack/gen/fluidstack" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" ) func Test_openapi_InstanceTypesAPIService(t *testing.T) { - configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) t.Run("Test InstanceTypesAPIService ListInstanceTypes", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.InstanceTypesAPI.ListInstanceTypes(context.Background()).Execute() @@ -31,7 +30,5 @@ func Test_openapi_InstanceTypesAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) - } diff --git a/internal/fluidstack/gen/fluidstack/test/api_instances_test.go b/internal/fluidstack/gen/fluidstack/test/api_instances_test.go index 1653ee2..c906c16 100644 --- a/internal/fluidstack/gen/fluidstack/test/api_instances_test.go +++ b/internal/fluidstack/gen/fluidstack/test/api_instances_test.go @@ -11,19 +11,18 @@ package openapi import ( "context" + "testing" + openapiclient "github.com/brevdev/cloud/internal/fluidstack/gen/fluidstack" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" ) func Test_openapi_InstancesAPIService(t *testing.T) { - configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) t.Run("Test InstancesAPIService CreateInstance", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.InstancesAPI.CreateInstance(context.Background()).Execute() @@ -31,11 +30,9 @@ func Test_openapi_InstancesAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test InstancesAPIService DeleteInstance", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -44,11 +41,9 @@ func Test_openapi_InstancesAPIService(t *testing.T) { require.Nil(t, err) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test InstancesAPIService GetInstance", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -58,11 +53,9 @@ func Test_openapi_InstancesAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test InstancesAPIService ListInstances", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.InstancesAPI.ListInstances(context.Background()).Execute() @@ -70,11 +63,9 @@ func Test_openapi_InstancesAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test InstancesAPIService StartInstance", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -83,11 +74,9 @@ func Test_openapi_InstancesAPIService(t *testing.T) { require.Nil(t, err) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test InstancesAPIService StopInstance", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -96,7 +85,5 @@ func Test_openapi_InstancesAPIService(t *testing.T) { require.Nil(t, err) assert.Equal(t, 200, httpRes.StatusCode) - }) - } diff --git a/internal/fluidstack/gen/fluidstack/test/api_kubernetes_test.go b/internal/fluidstack/gen/fluidstack/test/api_kubernetes_test.go index b49480e..51be8ba 100644 --- a/internal/fluidstack/gen/fluidstack/test/api_kubernetes_test.go +++ b/internal/fluidstack/gen/fluidstack/test/api_kubernetes_test.go @@ -11,19 +11,18 @@ package openapi import ( "context" + "testing" + openapiclient "github.com/brevdev/cloud/internal/fluidstack/gen/fluidstack" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" ) func Test_openapi_KubernetesAPIService(t *testing.T) { - configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) t.Run("Test KubernetesAPIService CreateKubernetesCluster", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.KubernetesAPI.CreateKubernetesCluster(context.Background()).Execute() @@ -31,11 +30,9 @@ func Test_openapi_KubernetesAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test KubernetesAPIService CreateKubernetesNodePool", func(t *testing.T) { - t.Skip("skip test") // remove to run test var clusterId string @@ -45,11 +42,9 @@ func Test_openapi_KubernetesAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test KubernetesAPIService DeleteKubernetesCluster", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -58,11 +53,9 @@ func Test_openapi_KubernetesAPIService(t *testing.T) { require.Nil(t, err) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test KubernetesAPIService DeleteKubernetesNodePool", func(t *testing.T) { - t.Skip("skip test") // remove to run test var clusterId string @@ -72,11 +65,9 @@ func Test_openapi_KubernetesAPIService(t *testing.T) { require.Nil(t, err) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test KubernetesAPIService GetKubernetesCluster", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -86,11 +77,9 @@ func Test_openapi_KubernetesAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test KubernetesAPIService GetKubernetesClusterCredentials", func(t *testing.T) { - t.Skip("skip test") // remove to run test var clusterId string @@ -100,11 +89,9 @@ func Test_openapi_KubernetesAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test KubernetesAPIService GetKubernetesNodePool", func(t *testing.T) { - t.Skip("skip test") // remove to run test var clusterId string @@ -115,11 +102,9 @@ func Test_openapi_KubernetesAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test KubernetesAPIService ListKubernetesClusters", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.KubernetesAPI.ListKubernetesClusters(context.Background()).Execute() @@ -127,11 +112,9 @@ func Test_openapi_KubernetesAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test KubernetesAPIService ListKubernetesNodePools", func(t *testing.T) { - t.Skip("skip test") // remove to run test var clusterId string @@ -141,7 +124,5 @@ func Test_openapi_KubernetesAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) - } diff --git a/internal/fluidstack/gen/fluidstack/test/api_projects_test.go b/internal/fluidstack/gen/fluidstack/test/api_projects_test.go index fc1a944..020ed0c 100644 --- a/internal/fluidstack/gen/fluidstack/test/api_projects_test.go +++ b/internal/fluidstack/gen/fluidstack/test/api_projects_test.go @@ -11,19 +11,18 @@ package openapi import ( "context" + "testing" + openapiclient "github.com/brevdev/cloud/internal/fluidstack/gen/fluidstack" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" ) func Test_openapi_ProjectsAPIService(t *testing.T) { - configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) t.Run("Test ProjectsAPIService CreateProject", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.ProjectsAPI.CreateProject(context.Background()).Execute() @@ -31,11 +30,9 @@ func Test_openapi_ProjectsAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test ProjectsAPIService DeleteProject", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -44,11 +41,9 @@ func Test_openapi_ProjectsAPIService(t *testing.T) { require.Nil(t, err) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test ProjectsAPIService GetProject", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -58,11 +53,9 @@ func Test_openapi_ProjectsAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test ProjectsAPIService ListProjects", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.ProjectsAPI.ListProjects(context.Background()).Execute() @@ -70,7 +63,5 @@ func Test_openapi_ProjectsAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) - } diff --git a/internal/fluidstack/gen/fluidstack/test/api_slurm_test.go b/internal/fluidstack/gen/fluidstack/test/api_slurm_test.go index ec30af9..71b5a02 100644 --- a/internal/fluidstack/gen/fluidstack/test/api_slurm_test.go +++ b/internal/fluidstack/gen/fluidstack/test/api_slurm_test.go @@ -11,19 +11,18 @@ package openapi import ( "context" + "testing" + openapiclient "github.com/brevdev/cloud/internal/fluidstack/gen/fluidstack" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" ) func Test_openapi_SlurmAPIService(t *testing.T) { - configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) t.Run("Test SlurmAPIService CreateSlurmCluster", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.SlurmAPI.CreateSlurmCluster(context.Background()).Execute() @@ -31,11 +30,9 @@ func Test_openapi_SlurmAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test SlurmAPIService CreateSlurmNodePool", func(t *testing.T) { - t.Skip("skip test") // remove to run test var clusterId string @@ -45,11 +42,9 @@ func Test_openapi_SlurmAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test SlurmAPIService DeleteSlurmCluster", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -58,11 +53,9 @@ func Test_openapi_SlurmAPIService(t *testing.T) { require.Nil(t, err) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test SlurmAPIService DeleteSlurmNodePool", func(t *testing.T) { - t.Skip("skip test") // remove to run test var clusterId string @@ -72,11 +65,9 @@ func Test_openapi_SlurmAPIService(t *testing.T) { require.Nil(t, err) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test SlurmAPIService GetSlurmCluster", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -86,11 +77,9 @@ func Test_openapi_SlurmAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test SlurmAPIService GetSlurmNodePool", func(t *testing.T) { - t.Skip("skip test") // remove to run test var clusterId string @@ -101,11 +90,9 @@ func Test_openapi_SlurmAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test SlurmAPIService ListSlurmClusters", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.SlurmAPI.ListSlurmClusters(context.Background()).Execute() @@ -113,11 +100,9 @@ func Test_openapi_SlurmAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test SlurmAPIService ListSlurmNodePools", func(t *testing.T) { - t.Skip("skip test") // remove to run test var clusterId string @@ -127,7 +112,5 @@ func Test_openapi_SlurmAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) - } diff --git a/internal/lambdalabs/gen/lambdalabs/test/api_default_test.go b/internal/lambdalabs/gen/lambdalabs/test/api_default_test.go index 5bc39ec..d5ee001 100644 --- a/internal/lambdalabs/gen/lambdalabs/test/api_default_test.go +++ b/internal/lambdalabs/gen/lambdalabs/test/api_default_test.go @@ -19,12 +19,10 @@ import ( ) func Test_openapi_DefaultAPIService(t *testing.T) { - configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) t.Run("Test DefaultAPIService AddSSHKey", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.DefaultAPI.AddSSHKey(context.Background()).Execute() @@ -32,11 +30,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService DeleteSSHKey", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -45,11 +41,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService GetInstance", func(t *testing.T) { - t.Skip("skip test") // remove to run test var id string @@ -59,11 +53,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService InstanceTypes", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.DefaultAPI.InstanceTypes(context.Background()).Execute() @@ -71,11 +63,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService LaunchInstance", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.DefaultAPI.LaunchInstance(context.Background()).Execute() @@ -83,11 +73,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService ListFileSystems", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.DefaultAPI.ListFileSystems(context.Background()).Execute() @@ -95,11 +83,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService ListInstances", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.DefaultAPI.ListInstances(context.Background()).Execute() @@ -107,11 +93,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService ListSSHKeys", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.DefaultAPI.ListSSHKeys(context.Background()).Execute() @@ -119,11 +103,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService RestartInstance", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.DefaultAPI.RestartInstance(context.Background()).Execute() @@ -131,11 +113,9 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) t.Run("Test DefaultAPIService TerminateInstance", func(t *testing.T) { - t.Skip("skip test") // remove to run test resp, httpRes, err := apiClient.DefaultAPI.TerminateInstance(context.Background()).Execute() @@ -143,7 +123,5 @@ func Test_openapi_DefaultAPIService(t *testing.T) { require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, httpRes.StatusCode) - }) - } diff --git a/internal/shadeform/v1/capabilities.go b/internal/shadeform/v1/capabilities.go index 3f0b833..1971f36 100644 --- a/internal/shadeform/v1/capabilities.go +++ b/internal/shadeform/v1/capabilities.go @@ -2,6 +2,7 @@ package v1 import ( "context" + v1 "github.com/brevdev/cloud/pkg/v1" ) diff --git a/internal/shadeform/v1/client.go b/internal/shadeform/v1/client.go index aa69565..14ed1b7 100644 --- a/internal/shadeform/v1/client.go +++ b/internal/shadeform/v1/client.go @@ -66,12 +66,11 @@ func (c *ShadeformCredential) MakeClient(_ context.Context, _ string) (v1.CloudC // It embeds NotImplCloudClient to handle unsupported features type ShadeformClient struct { v1.NotImplCloudClient - refID string - apiKey string - baseURL string - projectID string - client *openapi.APIClient - config *Configuration + refID string + apiKey string + baseURL string + client *openapi.APIClient + config *Configuration } var _ v1.CloudClient = &ShadeformClient{} diff --git a/internal/shadeform/v1/configuration.go b/internal/shadeform/v1/configuration.go index 36c82b7..604a93c 100644 --- a/internal/shadeform/v1/configuration.go +++ b/internal/shadeform/v1/configuration.go @@ -9,7 +9,6 @@ type Configuration struct { } func (c *Configuration) isAllowed(cloud openapi.Cloud, shadeInstanceType string) bool { - allowedClouds, found := c.AllowedInstanceTypes[cloud] if !found { return false diff --git a/internal/shadeform/v1/instance.go b/internal/shadeform/v1/instance.go index 53104a4..f98d563 100644 --- a/internal/shadeform/v1/instance.go +++ b/internal/shadeform/v1/instance.go @@ -4,20 +4,21 @@ import ( "context" "errors" "fmt" + "strings" + "github.com/alecthomas/units" openapi "github.com/brevdev/cloud/internal/shadeform/gen/shadeform" "github.com/brevdev/cloud/pkg/v1" "github.com/google/uuid" - "strings" ) const ( hostname = "shadecloud" refIDTagName = "refID" - cloudCredRefIDTagName = "cloudCredRefID" + cloudCredRefIDTagName = "cloudCredRefID" //nolint:gosec // not a secret ) -func (c *ShadeformClient) CreateInstance(ctx context.Context, attrs v1.CreateInstanceAttrs) (*v1.Instance, error) { +func (c *ShadeformClient) CreateInstance(ctx context.Context, attrs v1.CreateInstanceAttrs) (*v1.Instance, error) { //nolint:gocyclo,funlen // ok authCtx := c.makeAuthContext(ctx) // Check if the instance type is allowed by configuration @@ -38,7 +39,7 @@ func (c *ShadeformClient) CreateInstance(ctx context.Context, attrs v1.CreateIns if attrs.PublicKey != "" { var err error - sshKeyID, err = c.addSshKey(ctx, keyPairName, attrs.PublicKey) + sshKeyID, err = c.addSSHKey(ctx, keyPairName, attrs.PublicKey) if err != nil && !strings.Contains(err.Error(), "name must be unique") { return nil, fmt.Errorf("failed to add SSH key: %w", err) } @@ -120,7 +121,7 @@ func (c *ShadeformClient) CreateInstance(ctx context.Context, attrs v1.CreateIns return createdInstance, nil } -func (c *ShadeformClient) addSshKey(ctx context.Context, keyPairName string, publicKey string) (string, error) { +func (c *ShadeformClient) addSSHKey(ctx context.Context, keyPairName string, publicKey string) (string, error) { authCtx := c.makeAuthContext(ctx) request := openapi.AddSshKeyRequest{ @@ -353,7 +354,7 @@ func (c *ShadeformClient) createTag(key string, value string) (string, error) { func (c *ShadeformClient) getTag(shadeformTag string) (string, string, error) { key, value, found := strings.Cut(shadeformTag, "=") if !found { - return "", "", errors.New(fmt.Sprintf("tag %v does not conform to the key value tag format", shadeformTag)) + return "", "", fmt.Errorf("tag %v does not conform to the key value tag format", shadeformTag) } return key, value, nil } diff --git a/internal/shadeform/v1/instancetype.go b/internal/shadeform/v1/instancetype.go index 2e852eb..10f6dc3 100644 --- a/internal/shadeform/v1/instancetype.go +++ b/internal/shadeform/v1/instancetype.go @@ -4,11 +4,12 @@ import ( "context" "errors" "fmt" - "github.com/alecthomas/units" - "github.com/bojanz/currency" "strings" "time" + "github.com/alecthomas/units" + "github.com/bojanz/currency" + openapi "github.com/brevdev/cloud/internal/shadeform/gen/shadeform" "github.com/brevdev/cloud/pkg/v1" @@ -102,7 +103,6 @@ func (c *ShadeformClient) GetLocations(ctx context.Context, _ v1.GetLocationsArg // isInstanceTypeAllowed - determines if an instance type is allowed based on configuration func (c *ShadeformClient) isInstanceTypeAllowed(instanceType string) bool { - // By default, everything is allowed if c.config == nil || c.config.AllowedInstanceTypes == nil { return true diff --git a/internal/shadeform/v1/ufw.go b/internal/shadeform/v1/ufw.go index 17db526..16e3333 100644 --- a/internal/shadeform/v1/ufw.go +++ b/internal/shadeform/v1/ufw.go @@ -3,6 +3,7 @@ package v1 import ( "encoding/base64" "fmt" + v1 "github.com/brevdev/cloud/pkg/v1" ) @@ -31,7 +32,7 @@ func (c *ShadeformClient) GenerateFirewallScript(firewallRules v1.FirewallRules) script := "" for _, command := range commands { - script = script + fmt.Sprintf("%v\n", command) + script += fmt.Sprintf("%v\n", command) } encoded := base64.StdEncoding.EncodeToString([]byte(script)) diff --git a/internal/shadeform/v1/validation_test.go b/internal/shadeform/v1/validation_test.go index 211b231..71204fd 100644 --- a/internal/shadeform/v1/validation_test.go +++ b/internal/shadeform/v1/validation_test.go @@ -2,15 +2,16 @@ package v1 import ( "context" + "os" + "testing" + "time" + openapi "github.com/brevdev/cloud/internal/shadeform/gen/shadeform" "github.com/brevdev/cloud/internal/validation" "github.com/brevdev/cloud/pkg/ssh" v1 "github.com/brevdev/cloud/pkg/v1" "github.com/google/uuid" "github.com/stretchr/testify/require" - "os" - "testing" - "time" ) func TestValidationFunctions(t *testing.T) { @@ -44,7 +45,7 @@ func TestInstanceTypeFilter(t *testing.T) { apiKey := getAPIKey() ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute) - defer cancel() + t.Cleanup(cancel) client := NewShadeformClient("validation-test", apiKey) client.WithConfiguration(Configuration{ @@ -102,18 +103,19 @@ func TestInstanceTypeFilter(t *testing.T) { }, }, }) - if err != nil { t.Fatalf("ValidateCreateInstance failed: %v", err) } require.NotNil(t, instance) t.Run("ValidateSSHAccessible", func(t *testing.T) { + t.Parallel() err := v1.ValidateInstanceSSHAccessible(ctx, client, instance, ssh.GetTestPrivateKey()) require.NoError(t, err, "ValidateSSHAccessible should pass") }) t.Run("ValidateTerminateInstance", func(t *testing.T) { + t.Parallel() err := v1.ValidateTerminateInstance(ctx, client, instance) require.NoError(t, err, "ValidateTerminateInstance should pass") })