Skip to content

Commit

Permalink
move integration tests into individual pacakges
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Danese <mikedanese@google.com>
  • Loading branch information
mikedanese committed Jul 7, 2016
1 parent 2da247f commit f3de21b
Show file tree
Hide file tree
Showing 21 changed files with 167 additions and 150 deletions.
11 changes: 10 additions & 1 deletion hack/test-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ KUBE_INTEGRATION_TEST_MAX_CONCURRENCY=${KUBE_INTEGRATION_TEST_MAX_CONCURRENCY:-"
LOG_LEVEL=${LOG_LEVEL:-2}
KUBE_TEST_ARGS=${KUBE_TEST_ARGS:-}

kube::test::find_integration_test_dirs() {
(
cd ${KUBE_ROOT}
find test/integration -name '*_test.go' -print0 \
| xargs -0n1 dirname \
| sort -u
)
}

cleanup() {
kube::log::status "Cleaning up etcd"
kube::etcd::cleanup
Expand All @@ -58,7 +67,7 @@ runTests() {
KUBE_RACE="" \
KUBE_TIMEOUT="${KUBE_TIMEOUT}" \
KUBE_TEST_API_VERSIONS="$1" \
"${KUBE_ROOT}/hack/test-go.sh" test/integration
"${KUBE_ROOT}/hack/test-go.sh" $(kube::test::find_integration_test_dirs)

# Run the watch cache tests
# KUBE_TEST_ARGS doesn't mean anything to the watch cache test.
Expand Down
204 changes: 96 additions & 108 deletions test/integration/auth_test.go → test/integration/auth/auth_test.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration
package auth

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration
package client

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration
package client

import (
"reflect"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration
package configmap

// This file tests use of the configMap API resource.

Expand All @@ -27,6 +27,7 @@ import (
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/client/restclient"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/test/integration"
"k8s.io/kubernetes/test/integration/framework"
)

Expand Down Expand Up @@ -114,7 +115,7 @@ func DoTestConfigMap(t *testing.T, client *client.Client, ns *api.Namespace) {
if _, err := client.Pods(ns.Name).Create(pod); err != nil {
t.Errorf("Failed to create pod: %v", err)
}
defer deletePodOrErrorf(t, client, ns.Name, pod.Name)
defer integration.DeletePodOrErrorf(t, client, ns.Name, pod.Name)
}

func deleteConfigMapOrErrorf(t *testing.T, c *client.Client, ns, name string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration
package garbagecollector

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration
package kubectl

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration
package master

import (
"strconv"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration
package master

import (
"flag"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration
package master

import (
"bytes"
Expand All @@ -36,6 +36,7 @@ import (
"k8s.io/kubernetes/pkg/client/restclient"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/test/integration"
"k8s.io/kubernetes/test/integration/framework"
)

Expand Down Expand Up @@ -127,9 +128,9 @@ func TestAutoscalingGroupBackwardCompatibility(t *testing.T) {
expectedStatusCodes map[int]bool
expectedVersion string
}{
{"POST", autoscalingPath("horizontalpodautoscalers", api.NamespaceDefault, ""), hpaV1, code201, ""},
{"GET", autoscalingPath("horizontalpodautoscalers", api.NamespaceDefault, ""), "", code200, testapi.Autoscaling.GroupVersion().String()},
{"GET", extensionsPath("horizontalpodautoscalers", api.NamespaceDefault, ""), "", code200, testapi.Extensions.GroupVersion().String()},
{"POST", autoscalingPath("horizontalpodautoscalers", api.NamespaceDefault, ""), hpaV1, integration.Code201, ""},
{"GET", autoscalingPath("horizontalpodautoscalers", api.NamespaceDefault, ""), "", integration.Code200, testapi.Autoscaling.GroupVersion().String()},
{"GET", extensionsPath("horizontalpodautoscalers", api.NamespaceDefault, ""), "", integration.Code200, testapi.Extensions.GroupVersion().String()},
}

for _, r := range requests {
Expand Down Expand Up @@ -271,15 +272,15 @@ func TestBatchGroupBackwardCompatibility(t *testing.T) {
expectedVersion string
}{
// Post a v1 and get back both as v1beta1 and as v1.
{"POST", batchPath("jobs", api.NamespaceDefault, ""), jobV1, code201, ""},
{"GET", batchPath("jobs", api.NamespaceDefault, "pi"), "", code200, testapi.Batch.GroupVersion().String()},
{"GET", extensionsPath("jobs", api.NamespaceDefault, "pi"), "", code200, testapi.Extensions.GroupVersion().String()},
{"DELETE", batchPath("jobs", api.NamespaceDefault, "pi"), "", code200, testapi.Default.GroupVersion().String()}, // status response
{"POST", batchPath("jobs", api.NamespaceDefault, ""), jobV1, integration.Code201, ""},
{"GET", batchPath("jobs", api.NamespaceDefault, "pi"), "", integration.Code200, testapi.Batch.GroupVersion().String()},
{"GET", extensionsPath("jobs", api.NamespaceDefault, "pi"), "", integration.Code200, testapi.Extensions.GroupVersion().String()},
{"DELETE", batchPath("jobs", api.NamespaceDefault, "pi"), "", integration.Code200, testapi.Default.GroupVersion().String()}, // status response
// Post a v1beta1 and get back both as v1beta1 and as v1.
{"POST", extensionsPath("jobs", api.NamespaceDefault, ""), jobV1beta1, code201, ""},
{"GET", batchPath("jobs", api.NamespaceDefault, "pi"), "", code200, testapi.Batch.GroupVersion().String()},
{"GET", extensionsPath("jobs", api.NamespaceDefault, "pi"), "", code200, testapi.Extensions.GroupVersion().String()},
{"DELETE", extensionsPath("jobs", api.NamespaceDefault, "pi"), "", code200, testapi.Default.GroupVersion().String()}, //status response
{"POST", extensionsPath("jobs", api.NamespaceDefault, ""), jobV1beta1, integration.Code201, ""},
{"GET", batchPath("jobs", api.NamespaceDefault, "pi"), "", integration.Code200, testapi.Batch.GroupVersion().String()},
{"GET", extensionsPath("jobs", api.NamespaceDefault, "pi"), "", integration.Code200, testapi.Extensions.GroupVersion().String()},
{"DELETE", extensionsPath("jobs", api.NamespaceDefault, "pi"), "", integration.Code200, testapi.Default.GroupVersion().String()}, //status response
}

for _, r := range requests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration
package metrics

import (
"bufio"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration
package openshift

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration
package persistentvolumes

import (
"fmt"
Expand All @@ -27,8 +27,6 @@ import (
"testing"
"time"

"github.com/golang/glog"

"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/testapi"
Expand All @@ -41,11 +39,14 @@ import (
"k8s.io/kubernetes/pkg/volume"
volumetest "k8s.io/kubernetes/pkg/volume/testing"
"k8s.io/kubernetes/pkg/watch"
"k8s.io/kubernetes/test/integration"
"k8s.io/kubernetes/test/integration/framework"

"github.com/golang/glog"
)

func init() {
requireEtcd()
integration.RequireEtcd()
}

// Several tests in this file are configurable by environment variables:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration
package pods

import (
"fmt"
Expand All @@ -26,6 +26,7 @@ import (
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/client/restclient"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/test/integration"
"k8s.io/kubernetes/test/integration/framework"
)

Expand Down Expand Up @@ -142,7 +143,7 @@ func TestPodUpdateActiveDeadlineSeconds(t *testing.T) {
t.Errorf("%v: unexpected allowed update to pod", tc.name)
}

deletePodOrErrorf(t, client, ns.Name, pod.Name)
integration.DeletePodOrErrorf(t, client, ns.Name, pod.Name)
}
}

Expand Down Expand Up @@ -177,5 +178,5 @@ func TestPodReadOnlyFilesystem(t *testing.T) {
t.Errorf("Failed to create pod: %v", err)
}

deletePodOrErrorf(t, client, ns.Name, pod.Name)
integration.DeletePodOrErrorf(t, client, ns.Name, pod.Name)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration
package quota

import (
"fmt"
Expand All @@ -40,11 +40,12 @@ import (
quotainstall "k8s.io/kubernetes/pkg/quota/install"
"k8s.io/kubernetes/pkg/watch"
"k8s.io/kubernetes/plugin/pkg/admission/resourcequota"
"k8s.io/kubernetes/test/integration"
"k8s.io/kubernetes/test/integration/framework"
)

func init() {
requireEtcd()
integration.RequireEtcd()
}

// 1.2 code gets:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration
package scheduler

// This file tests scheduler extender.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration
package scheduler

// This file tests the scheduler.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration
package secrets

// This file tests use of the secrets API resource.

Expand All @@ -27,6 +27,7 @@ import (
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/client/restclient"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/test/integration"
"k8s.io/kubernetes/test/integration/framework"
)

Expand Down Expand Up @@ -105,14 +106,14 @@ func DoTestSecrets(t *testing.T, client *client.Client, ns *api.Namespace) {
if _, err := client.Pods(ns.Name).Create(pod); err != nil {
t.Errorf("Failed to create pod: %v", err)
}
defer deletePodOrErrorf(t, client, ns.Name, pod.Name)
defer integration.DeletePodOrErrorf(t, client, ns.Name, pod.Name)

// Create a pod that consumes non-existent secret.
pod.ObjectMeta.Name = "uses-non-existent-secret"
if _, err := client.Pods(ns.Name).Create(pod); err != nil {
t.Errorf("Failed to create pod: %v", err)
}
defer deletePodOrErrorf(t, client, ns.Name, pod.Name)
defer integration.DeletePodOrErrorf(t, client, ns.Name, pod.Name)
// This pod may fail to run, but we don't currently prevent this, and this
// test can't check whether the kubelet actually pulls the secret.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package integration
package serviceaccount

// This file tests authentication and (soon) authorization of HTTP requests to a master object.
// It does not use the client in pkg/client/... because authentication and authorization needs
Expand Down Expand Up @@ -47,6 +47,7 @@ import (
"k8s.io/kubernetes/pkg/util/wait"
serviceaccountadmission "k8s.io/kubernetes/plugin/pkg/admission/serviceaccount"
"k8s.io/kubernetes/plugin/pkg/auth/authenticator/request/union"
"k8s.io/kubernetes/test/integration"
"k8s.io/kubernetes/test/integration/framework"
)

Expand All @@ -59,7 +60,7 @@ const (
)

func init() {
requireEtcd()
integration.RequireEtcd()
}

func TestServiceAccountAutoCreate(t *testing.T) {
Expand Down
17 changes: 15 additions & 2 deletions test/integration/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func newEtcdClient() etcd.Client {
return client
}

func requireEtcd() {
func RequireEtcd() {
if _, err := etcd.NewKeysAPI(newEtcdClient()).Get(context.TODO(), "/", nil); err != nil {
glog.Fatalf("unable to connect to etcd for integration testing: %v", err)
}
Expand All @@ -51,8 +51,21 @@ func withEtcdKey(f func(string)) {
f(prefix)
}

func deletePodOrErrorf(t *testing.T, c *client.Client, ns, name string) {
func DeletePodOrErrorf(t *testing.T, c *client.Client, ns, name string) {
if err := c.Pods(ns).Delete(name, nil); err != nil {
t.Errorf("unable to delete pod %v: %v", name, err)
}
}

// Requests to try. Each one should be forbidden or not forbidden
// depending on the authentication and authorization setup of the master.
var Code200 = map[int]bool{200: true}
var Code201 = map[int]bool{201: true}
var Code400 = map[int]bool{400: true}
var Code403 = map[int]bool{403: true}
var Code404 = map[int]bool{404: true}
var Code405 = map[int]bool{405: true}
var Code409 = map[int]bool{409: true}
var Code422 = map[int]bool{422: true}
var Code500 = map[int]bool{500: true}
var Code503 = map[int]bool{503: true}

0 comments on commit f3de21b

Please sign in to comment.