-
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* testing-client Signed-off-by: Shubham Gupta <[email protected]> * client_test.go Signed-off-by: Shubham Gupta <[email protected]> * fix Signed-off-by: Shubham Gupta <[email protected]> * push Signed-off-by: Shubham Gupta <[email protected]> * fix Client Signed-off-by: Shubham Gupta <[email protected]> * fix Dockerfile Signed-off-by: Shubham Gupta <[email protected]> * try fixing lint Signed-off-by: Shubham Gupta <[email protected]> * fix ci Signed-off-by: Shubham Gupta <[email protected]> * fix CI Signed-off-by: Shubham Gupta <[email protected]> * fix CI Signed-off-by: Shubham Gupta <[email protected]> * ignoree Signed-off-by: Shubham Gupta <[email protected]> * change location Signed-off-by: Shubham Gupta <[email protected]> --------- Signed-off-by: Shubham Gupta <[email protected]>
- Loading branch information
1 parent
56996ef
commit 9167791
Showing
17 changed files
with
399 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package k8sutils | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
func mockK8sConfigProvider() (*rest.Config, error) { | ||
return &rest.Config{}, nil | ||
} | ||
func mockInvalidK8sConfigProvider() (*rest.Config, error) { | ||
return nil, errors.New("invalid configuration") | ||
} | ||
|
||
func TestGenerateK8sClient(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
configProvider func() (*rest.Config, error) | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "valid config", | ||
configProvider: mockK8sConfigProvider, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "invalid config", | ||
configProvider: mockInvalidK8sConfigProvider, | ||
wantErr: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
client, err := GenerateK8sClient(tt.configProvider) | ||
if tt.wantErr { | ||
assert.Error(t, err, "GenerateK8sClient() should return an error for invalid config") | ||
} else { | ||
assert.NoError(t, err, "GenerateK8sClient() should not return an error for valid config") | ||
assert.NotNil(t, client, "expected a non-nil Kubernetes client") | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestGenerateK8sDynamicClient(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
configProvider func() (*rest.Config, error) | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "valid config", | ||
configProvider: mockK8sConfigProvider, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "invalid config", | ||
configProvider: mockInvalidK8sConfigProvider, | ||
wantErr: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
client, err := GenerateK8sDynamicClient(tt.configProvider) | ||
if tt.wantErr { | ||
assert.Error(t, err, "GenerateK8sDynamicClient() should return an error for invalid config") | ||
} else { | ||
assert.NoError(t, err, "GenerateK8sDynamicClient() should not return an error for valid config") | ||
assert.NotNil(t, client, "expected a non-nil Kubernetes client") | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.