Skip to content

Commit

Permalink
feat: add kubernetes tests - wip
Browse files Browse the repository at this point in the history
  • Loading branch information
geffersonFerraz committed Jan 31, 2025
1 parent 7ccad25 commit b6cef71
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 3 deletions.
5 changes: 2 additions & 3 deletions internal/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,11 @@ func Do[T any](c *client.Config, ctx context.Context, req *http.Request, v *T) (
}

if v != nil && resp.StatusCode != http.StatusNoContent {
if strings.Contains(resp.Header.Get("Content-Type"), "application/json") {
return decodeJsonResponse(resp, v)
}
if strings.Contains(resp.Header.Get("Content-Type"), "application/x-yaml") {
return decodeYamlResponse(resp, v)
}
// JSON is the default
return decodeJsonResponse(resp, v)
}

return nil, nil
Expand Down
78 changes: 78 additions & 0 deletions kubernetes/client_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,79 @@
package kubernetes

import (
"net/http"
"testing"

"github.com/MagaluCloud/mgc-sdk-go/client"
)

func TestNewKubernetesClient(t *testing.T) {
tests := []struct {
name string
core *client.CoreClient
wantNil bool
}{
{
name: "valid core client",
core: client.NewMgcClient("test-token"),
wantNil: false,
},
{
name: "nil core client",
core: nil,
wantNil: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
client := New(tt.core)
if (client == nil) != tt.wantNil {
t.Errorf("New() returned nil = %v, want nil = %v", client == nil, tt.wantNil)
}
})
}
}

func TestKubernetesClient_Services(t *testing.T) {
core := client.NewMgcClient("test-token",
client.WithHTTPClient(&http.Client{}),
client.WithBaseURL("https://api.test.com"))

k8sClient := New(core)

t.Run("Clusters service", func(t *testing.T) {
service := k8sClient.Clusters()
if service == nil {
t.Error("Clusters() returned nil")
}
})

t.Run("Flavors service", func(t *testing.T) {
service := k8sClient.Flavors()
if service == nil {
t.Error("Flavors() returned nil")
}
})

t.Run("Info service", func(t *testing.T) {
service := k8sClient.Info()
if service == nil {
t.Error("Info() returned nil")
}
})

t.Run("Nodepools service", func(t *testing.T) {
service := k8sClient.Nodepools()
if service == nil {
t.Error("Nodepools() returned nil")
}
})

t.Run("Versions service", func(t *testing.T) {
service := k8sClient.Versions()
if service == nil {
t.Error("Versions() returned nil")
}
})
}

0 comments on commit b6cef71

Please sign in to comment.