Expand test coverage in master, kubectl/cmd/util, pkg/registry/resourcequota, and api/rest.
This commit is contained in:
@@ -17,10 +17,12 @@ limitations under the License.
|
||||
package rest
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
||||
func TestCheckGeneratedNameError(t *testing.T) {
|
||||
@@ -39,3 +41,75 @@ func TestCheckGeneratedNameError(t *testing.T) {
|
||||
t.Errorf("expected try again later error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBeforeCreate(t *testing.T) {
|
||||
failures := []runtime.Object{
|
||||
&api.Service{},
|
||||
&api.Service{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
Namespace: "#$%%invalid",
|
||||
},
|
||||
},
|
||||
&api.Service{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "##&*(&invalid",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range failures {
|
||||
ctx := api.NewDefaultContext()
|
||||
err := BeforeCreate(Services, ctx, test)
|
||||
if err == nil {
|
||||
t.Errorf("unexpected non-error for %v", test)
|
||||
}
|
||||
}
|
||||
|
||||
obj := &api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
Selector: map[string]string{"name": "foo"},
|
||||
Template: &api.PodTemplateSpec{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"name": "foo",
|
||||
},
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Name: "foo",
|
||||
Image: "foo",
|
||||
ImagePullPolicy: api.PullAlways,
|
||||
},
|
||||
},
|
||||
RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}},
|
||||
DNSPolicy: api.DNSDefault,
|
||||
},
|
||||
},
|
||||
},
|
||||
Status: api.ReplicationControllerStatus{
|
||||
Replicas: 3,
|
||||
},
|
||||
}
|
||||
ctx := api.NewDefaultContext()
|
||||
err := BeforeCreate(ReplicationControllers, ctx, obj)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(obj.Status, api.ReplicationControllerStatus{}) {
|
||||
t.Errorf("status was not cleared as expected.")
|
||||
}
|
||||
if obj.Name != "foo" || obj.Namespace != api.NamespaceDefault {
|
||||
t.Errorf("unexpected object metadata: %v", obj.ObjectMeta)
|
||||
}
|
||||
|
||||
obj.Spec.Replicas = -1
|
||||
if err := BeforeCreate(ReplicationControllers, ctx, obj); err == nil {
|
||||
t.Errorf("unexpected non-error for invalid replication controller.")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user