diff --git a/pkg/stores/proxy/proxy_store_test.go b/pkg/stores/proxy/proxy_store_test.go index 47fe2b37..6d41c8ae 100644 --- a/pkg/stores/proxy/proxy_store_test.go +++ b/pkg/stores/proxy/proxy_store_test.go @@ -508,14 +508,14 @@ func TestUpdate(t *testing.T) { apiOp: &types.APIRequest{ Request: &http.Request{ URL: &url.URL{}, - Method: http.MethodPut, + Method: http.MethodPost, }, Schema: &types.APISchema{ Schema: &schemas.Schema{ ID: "testing", }, }, - Method: http.MethodPut, + Method: http.MethodPost, }, schema: &types.APISchema{ Schema: &schemas.Schema{ @@ -579,7 +579,7 @@ func TestUpdate(t *testing.T) { }, params: types.APIObject{ Object: map[string]interface{}{ - "apiVersion": "v1", + "apiVersion": "v2", "kind": "Secret", "metadata": map[string]interface{}{ "name": "testing-secret", @@ -603,6 +603,116 @@ func TestUpdate(t *testing.T) { err: nil, }, }, + { + name: "update - different apiVersion and kind (params and schema) - should copy from schema", + updateCallbackFunc: func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) { + return false, ret, nil + }, + createInput: &sampleCreateInput, + updateInput: input{ + apiOp: &types.APIRequest{ + Request: &http.Request{ + URL: &url.URL{}, + Method: http.MethodPut, + }, + Schema: &types.APISchema{ + Schema: &schemas.Schema{ + ID: "testing", + }, + }, + Method: http.MethodPut, + }, + + schema: &types.APISchema{ + Schema: &schemas.Schema{ + ID: "testing", + Attributes: map[string]interface{}{ + "version": "v2", + "kind": "Secret", + "namespaced": true, + }, + }, + }, + params: types.APIObject{ + Object: map[string]interface{}{ + "apiVersion": "v1", + "kind": "ConfigMap", + "metadata": map[string]interface{}{ + "name": "testing-secret", + "namespace": "testing-ns", + "resourceVersion": "1", + }, + }, + }, + }, + expected: expected{ + value: &unstructured.Unstructured{Object: map[string]interface{}{ + "apiVersion": "v2", + "kind": "Secret", + "metadata": map[string]interface{}{ + "name": "testing-secret", + "namespace": "testing-ns", + "resourceVersion": "1", + }, + }}, + warning: []types.Warning{}, + err: nil, + }, + }, + { + name: "update - missing apiVersion and kind in params - should copy from schema", + updateCallbackFunc: func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) { + return false, ret, nil + }, + createInput: &sampleCreateInput, + updateInput: input{ + apiOp: &types.APIRequest{ + Request: &http.Request{ + URL: &url.URL{}, + Method: http.MethodPost, + }, + Schema: &types.APISchema{ + Schema: &schemas.Schema{ + ID: "testing", + }, + }, + Method: http.MethodPost, + }, + + schema: &types.APISchema{ + Schema: &schemas.Schema{ + ID: "testing", + Attributes: map[string]interface{}{ + "version": "v2", + "kind": "Secret", + "namespaced": true, + }, + }, + }, + params: types.APIObject{ + Object: map[string]interface{}{ + "metadata": map[string]interface{}{ + "name": "testing-secret", + "namespace": "testing-ns", + "resourceVersion": "1", + }, + }, + }, + }, + expected: expected{ + value: &unstructured.Unstructured{Object: map[string]interface{}{ + "apiVersion": "v2", + "kind": "Secret", + "metadata": map[string]interface{}{ + "name": "testing-secret", + "namespace": "testing-ns", + "resourceVersion": "1", + }, + }}, + warning: []types.Warning{}, + err: nil, + }, + }, { name: "update - missing resource version", updateCallbackFunc: func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) { diff --git a/pkg/stores/sqlproxy/proxy_store_test.go b/pkg/stores/sqlproxy/proxy_store_test.go index 8e61deca..96173c7d 100644 --- a/pkg/stores/sqlproxy/proxy_store_test.go +++ b/pkg/stores/sqlproxy/proxy_store_test.go @@ -1123,14 +1123,14 @@ func TestUpdate(t *testing.T) { apiOp: &types.APIRequest{ Request: &http.Request{ URL: &url.URL{}, - Method: http.MethodPut, + Method: http.MethodPost, }, Schema: &types.APISchema{ Schema: &schemas.Schema{ ID: "testing", }, }, - Method: http.MethodPut, + Method: http.MethodPost, }, schema: &types.APISchema{ Schema: &schemas.Schema{ @@ -1194,7 +1194,7 @@ func TestUpdate(t *testing.T) { }, params: types.APIObject{ Object: map[string]interface{}{ - "apiVersion": "v1", + "apiVersion": "v2", "kind": "Secret", "metadata": map[string]interface{}{ "name": "testing-secret", @@ -1218,6 +1218,116 @@ func TestUpdate(t *testing.T) { err: nil, }, }, + { + name: "update - different apiVersion and kind (params and schema) - should copy from schema", + updateCallbackFunc: func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) { + return false, ret, nil + }, + createInput: &sampleCreateInput, + updateInput: input{ + apiOp: &types.APIRequest{ + Request: &http.Request{ + URL: &url.URL{}, + Method: http.MethodPut, + }, + Schema: &types.APISchema{ + Schema: &schemas.Schema{ + ID: "testing", + }, + }, + Method: http.MethodPut, + }, + + schema: &types.APISchema{ + Schema: &schemas.Schema{ + ID: "testing", + Attributes: map[string]interface{}{ + "version": "v2", + "kind": "Secret", + "namespaced": true, + }, + }, + }, + params: types.APIObject{ + Object: map[string]interface{}{ + "apiVersion": "v1", + "kind": "ConfigMap", + "metadata": map[string]interface{}{ + "name": "testing-secret", + "namespace": "testing-ns", + "resourceVersion": "1", + }, + }, + }, + }, + expected: expected{ + value: &unstructured.Unstructured{Object: map[string]interface{}{ + "apiVersion": "v2", + "kind": "Secret", + "metadata": map[string]interface{}{ + "name": "testing-secret", + "namespace": "testing-ns", + "resourceVersion": "1", + }, + }}, + warning: []types.Warning{}, + err: nil, + }, + }, + { + name: "update - missing apiVersion and kind in params - should copy from schema", + updateCallbackFunc: func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) { + return false, ret, nil + }, + createInput: &sampleCreateInput, + updateInput: input{ + apiOp: &types.APIRequest{ + Request: &http.Request{ + URL: &url.URL{}, + Method: http.MethodPost, + }, + Schema: &types.APISchema{ + Schema: &schemas.Schema{ + ID: "testing", + }, + }, + Method: http.MethodPost, + }, + + schema: &types.APISchema{ + Schema: &schemas.Schema{ + ID: "testing", + Attributes: map[string]interface{}{ + "version": "v2", + "kind": "Secret", + "namespaced": true, + }, + }, + }, + params: types.APIObject{ + Object: map[string]interface{}{ + "metadata": map[string]interface{}{ + "name": "testing-secret", + "namespace": "testing-ns", + "resourceVersion": "1", + }, + }, + }, + }, + expected: expected{ + value: &unstructured.Unstructured{Object: map[string]interface{}{ + "apiVersion": "v2", + "kind": "Secret", + "metadata": map[string]interface{}{ + "name": "testing-secret", + "namespace": "testing-ns", + "resourceVersion": "1", + }, + }}, + warning: []types.Warning{}, + err: nil, + }, + }, { name: "update - missing resource version", updateCallbackFunc: func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) {