-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
longhorn/longhorn-9752 Signed-off-by: Chin-Ya Huang <[email protected]>
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/longhorn/go-common-libs/test" | ||
. "gopkg.in/check.v1" | ||
|
||
"k8s.io/client-go/kubernetes/fake" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func (s *TestSuite) TestGetDeployment(c *C) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
type testCase struct { | ||
deployment *appsv1.Deployment | ||
expectNotFound bool | ||
} | ||
testCases := map[string]testCase{ | ||
"GetDeployment(...):": { | ||
deployment: &appsv1.Deployment{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test", | ||
Namespace: "default", | ||
}, | ||
}, | ||
}, | ||
"GetDeployment(...): not found": { | ||
deployment: &appsv1.Deployment{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test", | ||
Namespace: "default", | ||
}, | ||
}, | ||
expectNotFound: true, | ||
}, | ||
} | ||
for testName, testCase := range testCases { | ||
c.Logf("testing kubernetes.%v", testName) | ||
|
||
kubeClient := fake.NewSimpleClientset() | ||
|
||
if !testCase.expectNotFound { | ||
_, err := kubeClient.AppsV1().Deployments(testCase.deployment.Namespace).Create(ctx, testCase.deployment, metav1.CreateOptions{}) | ||
c.Assert(err, IsNil, Commentf(test.ErrErrorFmt, testName)) | ||
} | ||
|
||
daemonSet, err := GetDeployment(kubeClient, testCase.deployment.Namespace, testCase.deployment.Name) | ||
if testCase.expectNotFound { | ||
c.Assert(apierrors.IsNotFound(err), Equals, true, Commentf(test.ErrResultFmt, testName)) | ||
return | ||
} | ||
c.Assert(err, IsNil, Commentf(test.ErrErrorFmt, testName)) | ||
c.Assert(daemonSet.Name, Equals, testCase.deployment.Name, Commentf(test.ErrResultFmt, testName)) | ||
} | ||
} |