Move first few integration tests to use dedicated namespaces

This commit is contained in:
Wojciech Tyczynski
2016-06-23 14:53:41 +02:00
parent 08f17fef27
commit ac270b66b7
7 changed files with 106 additions and 175 deletions

View File

@@ -21,46 +21,33 @@ package integration
// This file tests use of the configMap API resource.
import (
"net/http"
"net/http/httptest"
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/client/restclient"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/master"
"k8s.io/kubernetes/test/integration/framework"
)
// TestConfigMap tests apiserver-side behavior of creation of ConfigMaps and pods that consume them.
func TestConfigMap(t *testing.T) {
// TODO: Limit the test to a single non-default namespace and clean this up at the end.
framework.DeleteAllEtcdKeys()
var m *master.Master
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
m.Handler.ServeHTTP(w, req)
}))
_, s := framework.RunAMaster(t)
defer s.Close()
masterConfig := framework.NewIntegrationTestMasterConfig()
m, err := master.New(masterConfig)
if err != nil {
t.Fatalf("Error in bringing up the master: %v", err)
}
client := client.NewOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}})
DoTestConfigMap(t, client)
ns := framework.CreateTestingNamespace("config-map", s, t)
defer framework.DeleteTestingNamespace(ns, s, t)
DoTestConfigMap(t, client, ns)
}
func DoTestConfigMap(t *testing.T, client *client.Client) {
ns := "ns"
func DoTestConfigMap(t *testing.T, client *client.Client, ns *api.Namespace) {
cfg := api.ConfigMap{
ObjectMeta: api.ObjectMeta{
Name: "configmap",
Namespace: ns,
Namespace: ns.Name,
},
Data: map[string]string{
"data-1": "value-1",
@@ -76,7 +63,8 @@ func DoTestConfigMap(t *testing.T, client *client.Client) {
pod := &api.Pod{
ObjectMeta: api.ObjectMeta{
Name: "XXX",
Name: "XXX",
Namespace: ns.Name,
},
Spec: api.PodSpec{
Containers: []api.Container{
@@ -123,10 +111,10 @@ func DoTestConfigMap(t *testing.T, client *client.Client) {
}
pod.ObjectMeta.Name = "uses-configmap"
if _, err := client.Pods(ns).Create(pod); err != nil {
if _, err := client.Pods(ns.Name).Create(pod); err != nil {
t.Errorf("Failed to create pod: %v", err)
}
defer deletePodOrErrorf(t, client, ns, pod.Name)
defer deletePodOrErrorf(t, client, ns.Name, pod.Name)
}
func deleteConfigMapOrErrorf(t *testing.T, c *client.Client, ns, name string) {