mirror of
https://github.com/rancher/steve.git
synced 2025-09-07 10:21:33 +00:00
changed error message and added missing name only test
This commit is contained in:
@@ -40,7 +40,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
watchTimeoutEnv = "CATTLE_WATCH_TIMEOUT_SECONDS"
|
watchTimeoutEnv = "CATTLE_WATCH_TIMEOUT_SECONDS"
|
||||||
errNamespaceRequired = "metadata.namespace or apiOp.namespace are required"
|
errNamespaceRequired = "metadata.namespace is required"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@@ -1,20 +1,19 @@
|
|||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/rancher/wrangler/v3/pkg/schemas/validation"
|
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
|
||||||
schema2 "k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
"k8s.io/client-go/dynamic"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
schema2 "k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
|
"k8s.io/client-go/dynamic"
|
||||||
|
|
||||||
|
"github.com/rancher/wrangler/v3/pkg/schemas/validation"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rancher/apiserver/pkg/types"
|
|
||||||
"github.com/rancher/steve/pkg/client"
|
|
||||||
"github.com/rancher/wrangler/v3/pkg/schemas"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
@@ -26,6 +25,11 @@ import (
|
|||||||
"k8s.io/client-go/dynamic/fake"
|
"k8s.io/client-go/dynamic/fake"
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
clientgotesting "k8s.io/client-go/testing"
|
clientgotesting "k8s.io/client-go/testing"
|
||||||
|
|
||||||
|
"github.com/rancher/apiserver/pkg/types"
|
||||||
|
"github.com/rancher/wrangler/v3/pkg/schemas"
|
||||||
|
|
||||||
|
"github.com/rancher/steve/pkg/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
var c *watch.FakeWatcher
|
var c *watch.FakeWatcher
|
||||||
@@ -244,6 +248,53 @@ func TestCreate(t *testing.T) {
|
|||||||
err: nil,
|
err: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "missing name",
|
||||||
|
input: input{
|
||||||
|
apiOp: &types.APIRequest{
|
||||||
|
Schema: &types.APISchema{
|
||||||
|
Schema: &schemas.Schema{
|
||||||
|
ID: "testing",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Request: &http.Request{URL: &url.URL{}},
|
||||||
|
},
|
||||||
|
schema: &types.APISchema{
|
||||||
|
Schema: &schemas.Schema{
|
||||||
|
ID: "testing",
|
||||||
|
Attributes: map[string]interface{}{
|
||||||
|
"version": "v1",
|
||||||
|
"kind": "Secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
params: types.APIObject{
|
||||||
|
Object: map[string]interface{}{
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"kind": "Secret",
|
||||||
|
"metadata": map[string]interface{}{
|
||||||
|
"namespace": "testing-ns",
|
||||||
|
"generateName": "testing-gen-name",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
createReactorFunc: func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) {
|
||||||
|
return false, ret, nil
|
||||||
|
},
|
||||||
|
expected: expected{
|
||||||
|
value: &unstructured.Unstructured{Object: map[string]interface{}{
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"kind": "Secret",
|
||||||
|
"metadata": map[string]interface{}{
|
||||||
|
"generateName": "testing-gen-name",
|
||||||
|
"namespace": "testing-ns",
|
||||||
|
},
|
||||||
|
}},
|
||||||
|
warning: []types.Warning{},
|
||||||
|
err: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "missing name / generateName",
|
name: "missing name / generateName",
|
||||||
input: input{
|
input: input{
|
||||||
|
Reference in New Issue
Block a user