mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
feat(helm): update helm view [r8s-256] (#582)
Co-authored-by: Cara Ryan <cara.ryan@portainer.io> Co-authored-by: James Player <james.player@portainer.io> Co-authored-by: stevensbkang <skan070@gmail.com>
This commit is contained in:
parent
46eddbe7b9
commit
0ca9321db1
57 changed files with 2635 additions and 222 deletions
101
pkg/libkubectl/client_test.go
Normal file
101
pkg/libkubectl/client_test.go
Normal file
|
@ -0,0 +1,101 @@
|
|||
package libkubectl
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewClient(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
libKubectlAccess ClientAccess
|
||||
namespace string
|
||||
kubeconfig string
|
||||
insecure bool
|
||||
wantErr bool
|
||||
errContains string
|
||||
}{
|
||||
{
|
||||
name: "valid client with token and server",
|
||||
libKubectlAccess: ClientAccess{Token: "test-token", ServerUrl: "https://localhost:6443"},
|
||||
namespace: "default",
|
||||
insecure: true,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "valid client with kubeconfig",
|
||||
kubeconfig: "/path/to/kubeconfig",
|
||||
namespace: "test-namespace",
|
||||
insecure: false,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "missing both token/server and kubeconfig",
|
||||
namespace: "default",
|
||||
insecure: false,
|
||||
wantErr: true,
|
||||
errContains: "must provide either a kubeconfig path or a server and token",
|
||||
},
|
||||
{
|
||||
name: "missing token with server",
|
||||
libKubectlAccess: ClientAccess{ServerUrl: "https://localhost:6443"},
|
||||
namespace: "default",
|
||||
insecure: false,
|
||||
wantErr: true,
|
||||
errContains: "must provide either a kubeconfig path or a server and token",
|
||||
},
|
||||
{
|
||||
name: "missing server with token",
|
||||
libKubectlAccess: ClientAccess{Token: "test-token"},
|
||||
namespace: "default",
|
||||
insecure: false,
|
||||
wantErr: true,
|
||||
errContains: "must provide either a kubeconfig path or a server and token",
|
||||
},
|
||||
{
|
||||
name: "empty namespace is valid",
|
||||
libKubectlAccess: ClientAccess{Token: "test-token", ServerUrl: "https://localhost:6443"},
|
||||
namespace: "",
|
||||
insecure: false,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "insecure true with valid credentials",
|
||||
libKubectlAccess: ClientAccess{Token: "test-token", ServerUrl: "https://localhost:6443"},
|
||||
namespace: "default",
|
||||
insecure: true,
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
client, err := NewClient(&tt.libKubectlAccess, tt.namespace, tt.kubeconfig, tt.insecure)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("NewClient() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil && tt.errContains != "" {
|
||||
if got := err.Error(); got != tt.errContains {
|
||||
t.Errorf("NewClient() error = %v, want error containing %v", got, tt.errContains)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if !tt.wantErr {
|
||||
if client == nil {
|
||||
t.Error("NewClient() returned nil client when no error was expected")
|
||||
return
|
||||
}
|
||||
|
||||
// Verify client fields are properly initialized
|
||||
if client.factory == nil {
|
||||
t.Error("NewClient() client.factory is nil")
|
||||
}
|
||||
if client.out == nil {
|
||||
t.Error("NewClient() client.out is nil")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue