Skip to content

Commit

Permalink
Merge pull request #683 from mengqiy/fakeclient
Browse files Browse the repository at this point in the history
👻add apiversion handling to fake client
  • Loading branch information
k8s-ci-robot committed Nov 14, 2019
2 parents 2f2e975 + cd4d24b commit 15b5243
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions pkg/client/fake/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func (c *fakeClient) Get(ctx context.Context, key client.ObjectKey, obj runtime.
return err
}
ta.SetKind(gvk.Kind)
ta.SetAPIVersion(gvk.GroupVersion().String())

j, err := json.Marshal(o)
if err != nil {
Expand Down Expand Up @@ -154,6 +155,7 @@ func (c *fakeClient) List(ctx context.Context, obj runtime.Object, opts ...clien
return err
}
ta.SetKind(OriginalKind)
ta.SetAPIVersion(gvk.GroupVersion().String())

j, err := json.Marshal(o)
if err != nil {
Expand Down Expand Up @@ -317,6 +319,7 @@ func (c *fakeClient) Patch(ctx context.Context, obj runtime.Object, patch client
return err
}
ta.SetKind(gvk.Kind)
ta.SetAPIVersion(gvk.GroupVersion().String())

j, err := json.Marshal(o)
if err != nil {
Expand Down
15 changes: 10 additions & 5 deletions pkg/client/fake/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ var _ = Describe("Fake client", func() {
BeforeEach(func() {
dep = &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Kind: "Deployment",
APIVersion: "apps/v1",
Kind: "Deployment",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-deployment",
Expand All @@ -50,7 +51,8 @@ var _ = Describe("Fake client", func() {
}
dep2 = &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Kind: "Deployment",
APIVersion: "apps/v1",
Kind: "Deployment",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-deployment-2",
Expand All @@ -62,7 +64,8 @@ var _ = Describe("Fake client", func() {
}
cm = &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
Kind: "ConfigMap",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-cm",
Expand Down Expand Up @@ -135,7 +138,8 @@ var _ = Describe("Fake client", func() {
By("Creating a new configmap")
newcm := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
Kind: "ConfigMap",
},
ObjectMeta: metav1.ObjectMeta{
Name: "new-test-cm",
Expand All @@ -161,7 +165,8 @@ var _ = Describe("Fake client", func() {
By("Updating a new configmap")
newcm := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
Kind: "ConfigMap",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-cm",
Expand Down

0 comments on commit 15b5243

Please sign in to comment.