mirror of
https://github.com/rancher/steve.git
synced 2025-09-01 23:47:50 +00:00
updated tests
This commit is contained in:
@@ -508,14 +508,14 @@ func TestUpdate(t *testing.T) {
|
|||||||
apiOp: &types.APIRequest{
|
apiOp: &types.APIRequest{
|
||||||
Request: &http.Request{
|
Request: &http.Request{
|
||||||
URL: &url.URL{},
|
URL: &url.URL{},
|
||||||
Method: http.MethodPut,
|
Method: http.MethodPost,
|
||||||
},
|
},
|
||||||
Schema: &types.APISchema{
|
Schema: &types.APISchema{
|
||||||
Schema: &schemas.Schema{
|
Schema: &schemas.Schema{
|
||||||
ID: "testing",
|
ID: "testing",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Method: http.MethodPut,
|
Method: http.MethodPost,
|
||||||
},
|
},
|
||||||
schema: &types.APISchema{
|
schema: &types.APISchema{
|
||||||
Schema: &schemas.Schema{
|
Schema: &schemas.Schema{
|
||||||
@@ -579,7 +579,7 @@ func TestUpdate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
params: types.APIObject{
|
params: types.APIObject{
|
||||||
Object: map[string]interface{}{
|
Object: map[string]interface{}{
|
||||||
"apiVersion": "v1",
|
"apiVersion": "v2",
|
||||||
"kind": "Secret",
|
"kind": "Secret",
|
||||||
"metadata": map[string]interface{}{
|
"metadata": map[string]interface{}{
|
||||||
"name": "testing-secret",
|
"name": "testing-secret",
|
||||||
@@ -603,6 +603,116 @@ func TestUpdate(t *testing.T) {
|
|||||||
err: nil,
|
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",
|
name: "update - missing resource version",
|
||||||
updateCallbackFunc: func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) {
|
updateCallbackFunc: func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) {
|
||||||
|
@@ -1123,14 +1123,14 @@ func TestUpdate(t *testing.T) {
|
|||||||
apiOp: &types.APIRequest{
|
apiOp: &types.APIRequest{
|
||||||
Request: &http.Request{
|
Request: &http.Request{
|
||||||
URL: &url.URL{},
|
URL: &url.URL{},
|
||||||
Method: http.MethodPut,
|
Method: http.MethodPost,
|
||||||
},
|
},
|
||||||
Schema: &types.APISchema{
|
Schema: &types.APISchema{
|
||||||
Schema: &schemas.Schema{
|
Schema: &schemas.Schema{
|
||||||
ID: "testing",
|
ID: "testing",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Method: http.MethodPut,
|
Method: http.MethodPost,
|
||||||
},
|
},
|
||||||
schema: &types.APISchema{
|
schema: &types.APISchema{
|
||||||
Schema: &schemas.Schema{
|
Schema: &schemas.Schema{
|
||||||
@@ -1194,7 +1194,7 @@ func TestUpdate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
params: types.APIObject{
|
params: types.APIObject{
|
||||||
Object: map[string]interface{}{
|
Object: map[string]interface{}{
|
||||||
"apiVersion": "v1",
|
"apiVersion": "v2",
|
||||||
"kind": "Secret",
|
"kind": "Secret",
|
||||||
"metadata": map[string]interface{}{
|
"metadata": map[string]interface{}{
|
||||||
"name": "testing-secret",
|
"name": "testing-secret",
|
||||||
@@ -1218,6 +1218,116 @@ func TestUpdate(t *testing.T) {
|
|||||||
err: nil,
|
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",
|
name: "update - missing resource version",
|
||||||
updateCallbackFunc: func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) {
|
updateCallbackFunc: func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) {
|
||||||
|
Reference in New Issue
Block a user