Commit 9fc79e9d authored by Chao Xu's avatar Chao Xu

refactor testapi and test scripts to prepare for multiple API groups.

parent 49702f90
...@@ -38,6 +38,7 @@ import ( ...@@ -38,6 +38,7 @@ import (
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
apierrors "k8s.io/kubernetes/pkg/api/errors" apierrors "k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/latest" "k8s.io/kubernetes/pkg/api/latest"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/apiserver" "k8s.io/kubernetes/pkg/apiserver"
client "k8s.io/kubernetes/pkg/client/unversioned" client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/record" "k8s.io/kubernetes/pkg/client/unversioned/record"
...@@ -69,8 +70,6 @@ import ( ...@@ -69,8 +70,6 @@ import (
var ( var (
fakeDocker1, fakeDocker2 dockertools.FakeDockerClient fakeDocker1, fakeDocker2 dockertools.FakeDockerClient
// API version that should be used by the client to talk to the server.
apiVersion string
// Limit the number of concurrent tests. // Limit the number of concurrent tests.
maxConcurrency int maxConcurrency int
) )
...@@ -93,7 +92,7 @@ func (h *delegateHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { ...@@ -93,7 +92,7 @@ func (h *delegateHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
} }
func startComponents(firstManifestURL, secondManifestURL, apiVersion string) (string, string) { func startComponents(firstManifestURL, secondManifestURL string) (string, string) {
// Setup // Setup
servers := []string{} servers := []string{}
glog.Infof("Creating etcd client pointing to %v", servers) glog.Infof("Creating etcd client pointing to %v", servers)
...@@ -126,13 +125,17 @@ func startComponents(firstManifestURL, secondManifestURL, apiVersion string) (st ...@@ -126,13 +125,17 @@ func startComponents(firstManifestURL, secondManifestURL, apiVersion string) (st
glog.Fatalf("Failed to connect to etcd") glog.Fatalf("Failed to connect to etcd")
} }
cl := client.NewOrDie(&client.Config{Host: apiServer.URL, Version: apiVersion}) cl := client.NewOrDie(&client.Config{Host: apiServer.URL, Version: testapi.Default.Version()})
etcdStorage, err := master.NewEtcdStorage(etcdClient, latest.InterfacesFor, latest.Version, etcdtest.PathPrefix()) // TODO: caesarxuchao: hacky way to specify version of Experimental client.
// We will fix this by supporting multiple group versions in Config
cl.ExperimentalClient = client.NewExperimentalOrDie(&client.Config{Host: apiServer.URL, Version: testapi.Experimental.Version()})
etcdStorage, err := master.NewEtcdStorage(etcdClient, latest.InterfacesFor, testapi.Default.Version(), etcdtest.PathPrefix())
if err != nil { if err != nil {
glog.Fatalf("Unable to get etcd storage: %v", err) glog.Fatalf("Unable to get etcd storage: %v", err)
} }
expEtcdStorage, err := master.NewEtcdStorage(etcdClient, explatest.InterfacesFor, explatest.Version, etcdtest.PathPrefix()) expEtcdStorage, err := master.NewEtcdStorage(etcdClient, explatest.InterfacesFor, testapi.Experimental.Version(), etcdtest.PathPrefix())
if err != nil { if err != nil {
glog.Fatalf("Unable to get etcd storage for experimental: %v", err) glog.Fatalf("Unable to get etcd storage for experimental: %v", err)
} }
...@@ -891,7 +894,6 @@ func runSchedulerNoPhantomPodsTest(client *client.Client) { ...@@ -891,7 +894,6 @@ func runSchedulerNoPhantomPodsTest(client *client.Client) {
type testFunc func(*client.Client) type testFunc func(*client.Client)
func addFlags(fs *pflag.FlagSet) { func addFlags(fs *pflag.FlagSet) {
fs.StringVar(&apiVersion, "api-version", latest.Version, "API version that should be used by the client for communicating with the server")
fs.IntVar( fs.IntVar(
&maxConcurrency, "max-concurrency", -1, "Maximum number of tests to be run simultaneously. Unlimited if set to negative.") &maxConcurrency, "max-concurrency", -1, "Maximum number of tests to be run simultaneously. Unlimited if set to negative.")
} }
...@@ -911,18 +913,21 @@ func main() { ...@@ -911,18 +913,21 @@ func main() {
glog.Fatalf("This test has timed out.") glog.Fatalf("This test has timed out.")
}() }()
glog.Infof("Running tests for APIVersion: %s", apiVersion) glog.Infof("Running tests for APIVersion: %s", os.Getenv("KUBE_TEST_API"))
firstManifestURL := ServeCachedManifestFile(testPodSpecFile) firstManifestURL := ServeCachedManifestFile(testPodSpecFile)
secondManifestURL := ServeCachedManifestFile(testPodSpecFile) secondManifestURL := ServeCachedManifestFile(testPodSpecFile)
apiServerURL, _ := startComponents(firstManifestURL, secondManifestURL, apiVersion) apiServerURL, _ := startComponents(firstManifestURL, secondManifestURL)
// Ok. we're good to go. // Ok. we're good to go.
glog.Infof("API Server started on %s", apiServerURL) glog.Infof("API Server started on %s", apiServerURL)
// Wait for the synchronization threads to come up. // Wait for the synchronization threads to come up.
time.Sleep(time.Second * 10) time.Sleep(time.Second * 10)
kubeClient := client.NewOrDie(&client.Config{Host: apiServerURL, Version: apiVersion}) kubeClient := client.NewOrDie(&client.Config{Host: apiServerURL, Version: testapi.Default.Version()})
// TODO: caesarxuchao: hacky way to specify version of Experimental client.
// We will fix this by supporting multiple group versions in Config
kubeClient.ExperimentalClient = client.NewExperimentalOrDie(&client.Config{Host: apiServerURL, Version: testapi.Experimental.Version()})
// Run tests in parallel // Run tests in parallel
testFuncs := []testFunc{ testFuncs := []testFunc{
......
...@@ -318,7 +318,7 @@ func TestExecutorLaunchAndKillTask(t *testing.T) { ...@@ -318,7 +318,7 @@ func TestExecutorLaunchAndKillTask(t *testing.T) {
Updates: updates, Updates: updates,
APIClient: client.NewOrDie(&client.Config{ APIClient: client.NewOrDie(&client.Config{
Host: testApiServer.server.URL, Host: testApiServer.server.URL,
Version: testapi.Version(), Version: testapi.Default.Version(),
}), }),
Kubelet: &fakeKubelet{ Kubelet: &fakeKubelet{
Kubelet: &kubelet.Kubelet{}, Kubelet: &kubelet.Kubelet{},
...@@ -355,7 +355,7 @@ func TestExecutorLaunchAndKillTask(t *testing.T) { ...@@ -355,7 +355,7 @@ func TestExecutorLaunchAndKillTask(t *testing.T) {
assert.Equal(t, nil, err, "must be able to create a task from a pod") assert.Equal(t, nil, err, "must be able to create a task from a pod")
taskInfo := podTask.BuildTaskInfo() taskInfo := podTask.BuildTaskInfo()
data, err := testapi.Codec().Encode(pod) data, err := testapi.Default.Codec().Encode(pod)
assert.Equal(t, nil, err, "must be able to encode a pod's spec data") assert.Equal(t, nil, err, "must be able to encode a pod's spec data")
taskInfo.Data = data taskInfo.Data = data
var statusUpdateCalls sync.WaitGroup var statusUpdateCalls sync.WaitGroup
...@@ -484,7 +484,7 @@ func TestExecutorStaticPods(t *testing.T) { ...@@ -484,7 +484,7 @@ func TestExecutorStaticPods(t *testing.T) {
Updates: make(chan interface{}, 1), // allow kube-executor source to proceed past init Updates: make(chan interface{}, 1), // allow kube-executor source to proceed past init
APIClient: client.NewOrDie(&client.Config{ APIClient: client.NewOrDie(&client.Config{
Host: testApiServer.server.URL, Host: testApiServer.server.URL,
Version: testapi.Version(), Version: testapi.Default.Version(),
}), }),
Kubelet: &kubelet.Kubelet{}, Kubelet: &kubelet.Kubelet{},
PodStatusFunc: func(kl KubeletInterface, pod *api.Pod) (*api.PodStatus, error) { PodStatusFunc: func(kl KubeletInterface, pod *api.Pod) (*api.PodStatus, error) {
...@@ -565,7 +565,7 @@ func TestExecutorFrameworkMessage(t *testing.T) { ...@@ -565,7 +565,7 @@ func TestExecutorFrameworkMessage(t *testing.T) {
Updates: make(chan interface{}, 1024), Updates: make(chan interface{}, 1024),
APIClient: client.NewOrDie(&client.Config{ APIClient: client.NewOrDie(&client.Config{
Host: testApiServer.server.URL, Host: testApiServer.server.URL,
Version: testapi.Version(), Version: testapi.Default.Version(),
}), }),
Kubelet: &fakeKubelet{ Kubelet: &fakeKubelet{
Kubelet: &kubelet.Kubelet{}, Kubelet: &kubelet.Kubelet{},
...@@ -602,7 +602,7 @@ func TestExecutorFrameworkMessage(t *testing.T) { ...@@ -602,7 +602,7 @@ func TestExecutorFrameworkMessage(t *testing.T) {
*pod, &mesosproto.ExecutorInfo{}) *pod, &mesosproto.ExecutorInfo{})
taskInfo := podTask.BuildTaskInfo() taskInfo := podTask.BuildTaskInfo()
data, _ := testapi.Codec().Encode(pod) data, _ := testapi.Default.Codec().Encode(pod)
taskInfo.Data = data taskInfo.Data = data
mockDriver.On( mockDriver.On(
...@@ -660,11 +660,11 @@ func TestExecutorFrameworkMessage(t *testing.T) { ...@@ -660,11 +660,11 @@ func TestExecutorFrameworkMessage(t *testing.T) {
func NewTestPod(i int) *api.Pod { func NewTestPod(i int) *api.Pod {
name := fmt.Sprintf("pod%d", i) name := fmt.Sprintf("pod%d", i)
return &api.Pod{ return &api.Pod{
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()}, TypeMeta: api.TypeMeta{APIVersion: testapi.Default.Version()},
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Name: name, Name: name,
Namespace: api.NamespaceDefault, Namespace: api.NamespaceDefault,
SelfLink: testapi.SelfLink("pods", string(i)), SelfLink: testapi.Default.SelfLink("pods", string(i)),
}, },
Spec: api.PodSpec{ Spec: api.PodSpec{
Containers: []api.Container{ Containers: []api.Container{
...@@ -710,7 +710,7 @@ func NewTestServer(t *testing.T, namespace string, pods *api.PodList) *TestServe ...@@ -710,7 +710,7 @@ func NewTestServer(t *testing.T, namespace string, pods *api.PodList) *TestServe
} }
mux := http.NewServeMux() mux := http.NewServeMux()
mux.HandleFunc(testapi.ResourcePath("bindings", namespace, ""), func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc(testapi.Default.ResourcePath("bindings", namespace, ""), func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
}) })
......
...@@ -61,13 +61,13 @@ func NewTestServer(t *testing.T, namespace string, mockPodListWatch *MockPodsLis ...@@ -61,13 +61,13 @@ func NewTestServer(t *testing.T, namespace string, mockPodListWatch *MockPodsLis
} }
mux := http.NewServeMux() mux := http.NewServeMux()
mux.HandleFunc(testapi.ResourcePath("pods", namespace, ""), func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc(testapi.Default.ResourcePath("pods", namespace, ""), func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
pods := mockPodListWatch.Pods() pods := mockPodListWatch.Pods()
w.Write([]byte(runtime.EncodeOrDie(testapi.Codec(), &pods))) w.Write([]byte(runtime.EncodeOrDie(testapi.Default.Codec(), &pods)))
}) })
podsPrefix := testapi.ResourcePath("pods", namespace, "") + "/" podsPrefix := testapi.Default.ResourcePath("pods", namespace, "") + "/"
mux.HandleFunc(podsPrefix, func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc(podsPrefix, func(w http.ResponseWriter, r *http.Request) {
name := r.URL.Path[len(podsPrefix):] name := r.URL.Path[len(podsPrefix):]
...@@ -79,13 +79,13 @@ func NewTestServer(t *testing.T, namespace string, mockPodListWatch *MockPodsLis ...@@ -79,13 +79,13 @@ func NewTestServer(t *testing.T, namespace string, mockPodListWatch *MockPodsLis
p := mockPodListWatch.GetPod(name) p := mockPodListWatch.GetPod(name)
if p != nil { if p != nil {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
w.Write([]byte(runtime.EncodeOrDie(testapi.Codec(), p))) w.Write([]byte(runtime.EncodeOrDie(testapi.Default.Codec(), p)))
return return
} }
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
}) })
mux.HandleFunc(testapi.ResourcePath("events", namespace, ""), func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc(testapi.Default.ResourcePath("events", namespace, ""), func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
}) })
...@@ -196,7 +196,7 @@ func NewTestPod() (*api.Pod, int) { ...@@ -196,7 +196,7 @@ func NewTestPod() (*api.Pod, int) {
currentPodNum = currentPodNum + 1 currentPodNum = currentPodNum + 1
name := fmt.Sprintf("pod%d", currentPodNum) name := fmt.Sprintf("pod%d", currentPodNum)
return &api.Pod{ return &api.Pod{
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()}, TypeMeta: api.TypeMeta{APIVersion: testapi.Default.Version()},
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Name: name, Name: name,
Namespace: api.NamespaceDefault, Namespace: api.NamespaceDefault,
...@@ -398,7 +398,7 @@ func TestPlugin_LifeCycle(t *testing.T) { ...@@ -398,7 +398,7 @@ func TestPlugin_LifeCycle(t *testing.T) {
podtask.NewDefaultProcurement(mresource.DefaultDefaultContainerCPULimit, mresource.DefaultDefaultContainerMemLimit)) podtask.NewDefaultProcurement(mresource.DefaultDefaultContainerCPULimit, mresource.DefaultDefaultContainerMemLimit))
testScheduler := New(Config{ testScheduler := New(Config{
Executor: executor, Executor: executor,
Client: client.NewOrDie(&client.Config{Host: testApiServer.server.URL, Version: testapi.Version()}), Client: client.NewOrDie(&client.Config{Host: testApiServer.server.URL, Version: testapi.Default.Version()}),
Scheduler: NewFCFSPodScheduler(as), Scheduler: NewFCFSPodScheduler(as),
Schedcfg: *schedcfg.CreateDefaultConfig(), Schedcfg: *schedcfg.CreateDefaultConfig(),
}) })
......
...@@ -52,8 +52,13 @@ KUBE_COVERPROCS=${KUBE_COVERPROCS:-4} ...@@ -52,8 +52,13 @@ KUBE_COVERPROCS=${KUBE_COVERPROCS:-4}
KUBE_RACE=${KUBE_RACE:-} # use KUBE_RACE="-race" to enable race testing KUBE_RACE=${KUBE_RACE:-} # use KUBE_RACE="-race" to enable race testing
# Set to the goveralls binary path to report coverage results to Coveralls.io. # Set to the goveralls binary path to report coverage results to Coveralls.io.
KUBE_GOVERALLS_BIN=${KUBE_GOVERALLS_BIN:-} KUBE_GOVERALLS_BIN=${KUBE_GOVERALLS_BIN:-}
# Comma separated list of API Versions that should be tested. # Lists of API Versions of each groups that should be tested, groups are
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1"} # separated by comma, lists are separated by semicolon. e.g.,
# "v1,compute/v1alpha1,experimental/v1alpha2;v1,compute/v2,experimental/v1alpha3"
# TODO: It's going to be:
# KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,experimental/v1alpha1"}
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,experimental/v1"}
# once we have multiple group supports
# Run tests with the standard (registry) and a custom etcd prefix # Run tests with the standard (registry) and a custom etcd prefix
# (kubernetes.io/registry). # (kubernetes.io/registry).
KUBE_TEST_ETCD_PREFIXES=${KUBE_TEST_ETCD_PREFIXES:-"registry,kubernetes.io/registry"} KUBE_TEST_ETCD_PREFIXES=${KUBE_TEST_ETCD_PREFIXES:-"registry,kubernetes.io/registry"}
...@@ -131,7 +136,8 @@ junitFilenamePrefix() { ...@@ -131,7 +136,8 @@ junitFilenamePrefix() {
return return
fi fi
mkdir -p "${KUBE_JUNIT_REPORT_DIR}" mkdir -p "${KUBE_JUNIT_REPORT_DIR}"
echo "${KUBE_JUNIT_REPORT_DIR}/junit_${KUBE_API_VERSION}_$(kube::util::sortable_date)" local KUBE_TEST_API_NO_SLASH=echo "${KUBE_TEST_API//\//-}"
echo "${KUBE_JUNIT_REPORT_DIR}/junit_${KUBE_TEST_API_NO_SLASH}_$(kube::util::sortable_date)"
} }
produceJUnitXMLReport() { produceJUnitXMLReport() {
...@@ -205,7 +211,7 @@ runTests() { ...@@ -205,7 +211,7 @@ runTests() {
fi fi
# Create coverage report directories. # Create coverage report directories.
cover_report_dir="/tmp/k8s_coverage/${KUBE_API_VERSION}/$(kube::util::sortable_date)" cover_report_dir="/tmp/k8s_coverage/${KUBE_TEST_API}/$(kube::util::sortable_date)"
cover_profile="coverage.out" # Name for each individual coverage profile cover_profile="coverage.out" # Name for each individual coverage profile
kube::log::status "Saving coverage output in '${cover_report_dir}'" kube::log::status "Saving coverage output in '${cover_report_dir}'"
mkdir -p "${@+${@/#/${cover_report_dir}/}}" mkdir -p "${@+${@/#/${cover_report_dir}/}}"
...@@ -266,7 +272,7 @@ reportCoverageToCoveralls() { ...@@ -266,7 +272,7 @@ reportCoverageToCoveralls() {
} }
# Convert the CSVs to arrays. # Convert the CSVs to arrays.
IFS=',' read -a apiVersions <<< "${KUBE_TEST_API_VERSIONS}" IFS=';' read -a apiVersions <<< "${KUBE_TEST_API_VERSIONS}"
IFS=',' read -a etcdPrefixes <<< "${KUBE_TEST_ETCD_PREFIXES}" IFS=',' read -a etcdPrefixes <<< "${KUBE_TEST_ETCD_PREFIXES}"
apiVersionsCount=${#apiVersions[@]} apiVersionsCount=${#apiVersions[@]}
etcdPrefixesCount=${#etcdPrefixes[@]} etcdPrefixesCount=${#etcdPrefixes[@]}
...@@ -274,7 +280,10 @@ for (( i=0, j=0; ; )); do ...@@ -274,7 +280,10 @@ for (( i=0, j=0; ; )); do
apiVersion=${apiVersions[i]} apiVersion=${apiVersions[i]}
etcdPrefix=${etcdPrefixes[j]} etcdPrefix=${etcdPrefixes[j]}
echo "Running tests for APIVersion: $apiVersion with etcdPrefix: $etcdPrefix" echo "Running tests for APIVersion: $apiVersion with etcdPrefix: $etcdPrefix"
KUBE_API_VERSION="${apiVersion}" KUBE_API_VERSIONS="v1" ETCD_PREFIX=${etcdPrefix} runTests "$@" # KUBE_TEST_API sets the version of each group to be tested. KUBE_API_VERSIONS
# register the groups/versions as supported by k8s. So KUBE_API_VERSIONS
# needs to be the superset of KUBE_TEST_API.
KUBE_TEST_API="${apiVersion}" KUBE_API_VERSIONS="v1" ETCD_PREFIX=${etcdPrefix} runTests "$@"
i=${i}+1 i=${i}+1
j=${j}+1 j=${j}+1
if [[ i -eq ${apiVersionsCount} ]] && [[ j -eq ${etcdPrefixesCount} ]]; then if [[ i -eq ${apiVersionsCount} ]] && [[ j -eq ${etcdPrefixesCount} ]]; then
......
...@@ -24,8 +24,12 @@ set -o pipefail ...@@ -24,8 +24,12 @@ set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/hack/lib/init.sh" source "${KUBE_ROOT}/hack/lib/init.sh"
# Comma separated list of API Versions that should be tested. # Lists of API Versions of each groups that should be tested, groups are
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1"} # separated by comma, lists are separated by semicolon. e.g.,
# "v1,compute/v1alpha1,experimental/v1alpha2;v1,compute/v2,experimental/v1alpha3"
# TODO: It's going to be:
# KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,experimental/v1alpha1"}
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,experimental/v1"}
KUBE_INTEGRATION_TEST_MAX_CONCURRENCY=${KUBE_INTEGRATION_TEST_MAX_CONCURRENCY:-"-1"} KUBE_INTEGRATION_TEST_MAX_CONCURRENCY=${KUBE_INTEGRATION_TEST_MAX_CONCURRENCY:-"-1"}
LOG_LEVEL=${LOG_LEVEL:-2} LOG_LEVEL=${LOG_LEVEL:-2}
...@@ -48,8 +52,8 @@ runTests() { ...@@ -48,8 +52,8 @@ runTests() {
kube::log::status "Running integration test scenario" kube::log::status "Running integration test scenario"
KUBE_API_VERSIONS="v1" "${KUBE_OUTPUT_HOSTBIN}/integration" --v=${LOG_LEVEL} --api-version="$1" \ KUBE_API_VERSIONS="v1" KUBE_TEST_API_VERSIONS="$1" "${KUBE_OUTPUT_HOSTBIN}/integration" --v=${LOG_LEVEL} \
--max-concurrency="${KUBE_INTEGRATION_TEST_MAX_CONCURRENCY}" --max-concurrency="${KUBE_INTEGRATION_TEST_MAX_CONCURRENCY}"
cleanup cleanup
} }
...@@ -60,7 +64,7 @@ KUBE_API_VERSIONS="v1" "${KUBE_ROOT}/hack/build-go.sh" "$@" cmd/integration ...@@ -60,7 +64,7 @@ KUBE_API_VERSIONS="v1" "${KUBE_ROOT}/hack/build-go.sh" "$@" cmd/integration
trap cleanup EXIT trap cleanup EXIT
# Convert the CSV to an array of API versions to test # Convert the CSV to an array of API versions to test
IFS=',' read -a apiVersions <<< "${KUBE_TEST_API_VERSIONS}" IFS=';' read -a apiVersions <<< "${KUBE_TEST_API_VERSIONS}"
for apiVersion in "${apiVersions[@]}"; do for apiVersion in "${apiVersions[@]}"; do
runTests "${apiVersion}" runTests "${apiVersion}"
done done
...@@ -37,7 +37,7 @@ func BenchmarkPodConversion(b *testing.B) { ...@@ -37,7 +37,7 @@ func BenchmarkPodConversion(b *testing.B) {
scheme := api.Scheme.Raw() scheme := api.Scheme.Raw()
var result *api.Pod var result *api.Pod
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
versionedObj, err := scheme.ConvertToVersion(&pod, testapi.Version()) versionedObj, err := scheme.ConvertToVersion(&pod, testapi.Default.Version())
if err != nil { if err != nil {
b.Fatalf("Conversion error: %v", err) b.Fatalf("Conversion error: %v", err)
} }
...@@ -65,7 +65,7 @@ func BenchmarkNodeConversion(b *testing.B) { ...@@ -65,7 +65,7 @@ func BenchmarkNodeConversion(b *testing.B) {
scheme := api.Scheme.Raw() scheme := api.Scheme.Raw()
var result *api.Node var result *api.Node
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
versionedObj, err := scheme.ConvertToVersion(&node, testapi.Version()) versionedObj, err := scheme.ConvertToVersion(&node, testapi.Default.Version())
if err != nil { if err != nil {
b.Fatalf("Conversion error: %v", err) b.Fatalf("Conversion error: %v", err)
} }
...@@ -93,7 +93,7 @@ func BenchmarkReplicationControllerConversion(b *testing.B) { ...@@ -93,7 +93,7 @@ func BenchmarkReplicationControllerConversion(b *testing.B) {
scheme := api.Scheme.Raw() scheme := api.Scheme.Raw()
var result *api.ReplicationController var result *api.ReplicationController
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
versionedObj, err := scheme.ConvertToVersion(&replicationController, testapi.Version()) versionedObj, err := scheme.ConvertToVersion(&replicationController, testapi.Default.Version())
if err != nil { if err != nil {
b.Fatalf("Conversion error: %v", err) b.Fatalf("Conversion error: %v", err)
} }
......
...@@ -28,7 +28,7 @@ import ( ...@@ -28,7 +28,7 @@ import (
func TestDeepCopyApiObjects(t *testing.T) { func TestDeepCopyApiObjects(t *testing.T) {
for i := 0; i < *fuzzIters; i++ { for i := 0; i < *fuzzIters; i++ {
for _, version := range []string{"", testapi.Version()} { for _, version := range []string{"", testapi.Default.Version()} {
f := apitesting.FuzzerFor(t, version, rand.NewSource(rand.Int63())) f := apitesting.FuzzerFor(t, version, rand.NewSource(rand.Int63()))
for kind := range api.Scheme.KnownTypes(version) { for kind := range api.Scheme.KnownTypes(version) {
item, err := api.Scheme.New(version, kind) item, err := api.Scheme.New(version, kind)
......
...@@ -90,10 +90,10 @@ func roundTripSame(t *testing.T, item runtime.Object, except ...string) { ...@@ -90,10 +90,10 @@ func roundTripSame(t *testing.T, item runtime.Object, except ...string) {
set := util.NewStringSet(except...) set := util.NewStringSet(except...)
seed := rand.Int63() seed := rand.Int63()
fuzzInternalObject(t, "", item, seed) fuzzInternalObject(t, "", item, seed)
version := testapi.Version() version := testapi.Default.Version()
if !set.Has(version) { if !set.Has(version) {
fuzzInternalObject(t, version, item, seed) fuzzInternalObject(t, version, item, seed)
roundTrip(t, testapi.Codec(), item) roundTrip(t, testapi.Default.Codec(), item)
} }
} }
......
...@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and ...@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
// Package testapi provides a helper for retrieving the KUBE_API_VERSION environment variable. // Package testapi provides a helper for retrieving the KUBE_TEST_API environment variable.
package testapi package testapi
import ( import (
...@@ -24,63 +24,161 @@ import ( ...@@ -24,63 +24,161 @@ import (
"k8s.io/kubernetes/pkg/api/latest" "k8s.io/kubernetes/pkg/api/latest"
"k8s.io/kubernetes/pkg/api/meta" "k8s.io/kubernetes/pkg/api/meta"
apiutil "k8s.io/kubernetes/pkg/api/util"
explatest "k8s.io/kubernetes/pkg/expapi/latest"
"k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/runtime"
) )
// Version returns the API version to test against, as set by the KUBE_API_VERSION env var. var (
func Version() string { Groups = make(map[string]TestGroup)
version := os.Getenv("KUBE_API_VERSION") Default TestGroup
if version == "" { Experimental TestGroup
version = latest.Version )
type TestGroup struct {
// Name of the group
Group string
// Version of the group Group under test
VersionUnderTest string
// Group and Version. In most cases equals to Group + "/" + VersionUnverTest
GroupVersionUnderTest string
}
func init() {
kubeTestAPI := os.Getenv("KUBE_TEST_API")
if kubeTestAPI != "" {
testGroupVersions := strings.Split(kubeTestAPI, ",")
for _, groupVersion := range testGroupVersions {
// TODO: caesarxuchao: the apiutil package is hacky, it will be replaced
// by a following PR.
Groups[apiutil.GetGroup(groupVersion)] =
TestGroup{apiutil.GetGroup(groupVersion), apiutil.GetVersion(groupVersion), groupVersion}
}
} }
return version
// TODO: caesarxuchao: we need a central place to store all available API
// groups and their metadata.
if _, ok := Groups[""]; !ok {
// TODO: The second latest.Version will be latest.GroupVersion after we
// have multiple group support
Groups[""] = TestGroup{"", latest.Version, latest.Version}
}
if _, ok := Groups["experimental"]; !ok {
Groups["experimental"] = TestGroup{"experimental", explatest.Version, explatest.Version}
}
Default = Groups[""]
Experimental = Groups["experimental"]
}
// Version returns the API version to test against, as set by the KUBE_TEST_API env var.
func (g TestGroup) Version() string {
return g.VersionUnderTest
}
// GroupAndVersion returns the API version to test against for a group, as set
// by the KUBE_TEST_API env var.
// Return value is in the form of "group/version".
func (g TestGroup) GroupAndVersion() string {
return g.GroupVersionUnderTest
} }
// Codec returns the codec for the API version to test against, as set by the // Codec returns the codec for the API version to test against, as set by the
// KUBE_API_VERSION env var. // KUBE_TEST_API env var.
func Codec() runtime.Codec { func (g TestGroup) Codec() runtime.Codec {
interfaces, err := latest.InterfacesFor(Version()) // TODO: caesarxuchao: Restructure the body once we have a central `latest`.
if err != nil { if g.Group == "" {
panic(err) interfaces, err := latest.InterfacesFor(g.VersionUnderTest)
if err != nil {
panic(err)
}
return interfaces.Codec
} }
return interfaces.Codec if g.Group == "experimental" {
interfaces, err := explatest.InterfacesFor(g.VersionUnderTest)
if err != nil {
panic(err)
}
return interfaces.Codec
}
panic(fmt.Errorf("cannot test group %s", g.Group))
} }
// Converter returns the api.Scheme for the API version to test against, as set by the // Converter returns the api.Scheme for the API version to test against, as set by the
// KUBE_API_VERSION env var. // KUBE_TEST_API env var.
func Converter() runtime.ObjectConvertor { func (g TestGroup) Converter() runtime.ObjectConvertor {
interfaces, err := latest.InterfacesFor(Version()) // TODO: caesarxuchao: Restructure the body once we have a central `latest`.
if err != nil { if g.Group == "" {
panic(err) interfaces, err := latest.InterfacesFor(g.VersionUnderTest)
if err != nil {
panic(err)
}
return interfaces.ObjectConvertor
}
if g.Group == "experimental" {
interfaces, err := explatest.InterfacesFor(g.VersionUnderTest)
if err != nil {
panic(err)
}
return interfaces.ObjectConvertor
} }
return interfaces.ObjectConvertor panic(fmt.Errorf("cannot test group %s", g.Group))
} }
// MetadataAccessor returns the MetadataAccessor for the API version to test against, // MetadataAccessor returns the MetadataAccessor for the API version to test against,
// as set by the KUBE_API_VERSION env var. // as set by the KUBE_TEST_API env var.
func MetadataAccessor() meta.MetadataAccessor { func (g TestGroup) MetadataAccessor() meta.MetadataAccessor {
interfaces, err := latest.InterfacesFor(Version()) // TODO: caesarxuchao: Restructure the body once we have a central `latest`.
if err != nil { if g.Group == "" {
panic(err) interfaces, err := latest.InterfacesFor(g.VersionUnderTest)
if err != nil {
panic(err)
}
return interfaces.MetadataAccessor
}
if g.Group == "experimental" {
interfaces, err := explatest.InterfacesFor(g.VersionUnderTest)
if err != nil {
panic(err)
}
return interfaces.MetadataAccessor
} }
return interfaces.MetadataAccessor panic(fmt.Errorf("cannot test group %s", g.Group))
} }
// SelfLink returns a self link that will appear to be for the version Version(). // SelfLink returns a self link that will appear to be for the version Version().
// 'resource' should be the resource path, e.g. "pods" for the Pod type. 'name' should be // 'resource' should be the resource path, e.g. "pods" for the Pod type. 'name' should be
// empty for lists. // empty for lists.
func SelfLink(resource, name string) string { func (g TestGroup) SelfLink(resource, name string) string {
if name == "" { if g.Group == "" {
return fmt.Sprintf("/api/%s/%s", Version(), resource) if name == "" {
return fmt.Sprintf("/api/%s/%s", g.Version(), resource)
}
return fmt.Sprintf("/api/%s/%s/%s", g.Version(), resource, name)
} else {
// TODO: will need a /apis prefix once we have proper multi-group
// support
if name == "" {
return fmt.Sprintf("/%s/%s/%s", g.Group, g.Version(), resource)
}
return fmt.Sprintf("/%s/%s/%s/%s", g.Group, g.Version(), resource, name)
} }
return fmt.Sprintf("/api/%s/%s/%s", Version(), resource, name)
} }
// Returns the appropriate path for the given prefix (watch, proxy, redirect, etc), resource, namespace and name. // Returns the appropriate path for the given prefix (watch, proxy, redirect, etc), resource, namespace and name.
// For ex, this is of the form: // For ex, this is of the form:
// /api/v1/watch/namespaces/foo/pods/pod0 for v1. // /api/v1/watch/namespaces/foo/pods/pod0 for v1.
func ResourcePathWithPrefix(prefix, resource, namespace, name string) string { func (g TestGroup) ResourcePathWithPrefix(prefix, resource, namespace, name string) string {
path := "/api/" + Version() var path string
if len(g.Group) == 0 {
path = "/api/" + g.Version()
} else {
// TODO: switch back once we have proper multiple group support
// path = "/apis/" + g.Group + "/" + Version(group...)
path = "/" + g.Group + "/" + g.Version()
}
if prefix != "" { if prefix != "" {
path = path + "/" + prefix path = path + "/" + prefix
} }
...@@ -101,6 +199,6 @@ func ResourcePathWithPrefix(prefix, resource, namespace, name string) string { ...@@ -101,6 +199,6 @@ func ResourcePathWithPrefix(prefix, resource, namespace, name string) string {
// Returns the appropriate path for the given resource, namespace and name. // Returns the appropriate path for the given resource, namespace and name.
// For example, this is of the form: // For example, this is of the form:
// /api/v1/namespaces/foo/pods/pod0 for v1. // /api/v1/namespaces/foo/pods/pod0 for v1.
func ResourcePath(resource, namespace, name string) string { func (g TestGroup) ResourcePath(resource, namespace, name string) string {
return ResourcePathWithPrefix("", resource, namespace, name) return g.ResourcePathWithPrefix("", resource, namespace, name)
} }
...@@ -28,14 +28,14 @@ func TestResourcePathWithPrefix(t *testing.T) { ...@@ -28,14 +28,14 @@ func TestResourcePathWithPrefix(t *testing.T) {
name string name string
expected string expected string
}{ }{
{"prefix", "resource", "mynamespace", "myresource", "/api/" + Version() + "/prefix/namespaces/mynamespace/resource/myresource"}, {"prefix", "resource", "mynamespace", "myresource", "/api/" + Default.Version() + "/prefix/namespaces/mynamespace/resource/myresource"},
{"prefix", "resource", "", "myresource", "/api/" + Version() + "/prefix/resource/myresource"}, {"prefix", "resource", "", "myresource", "/api/" + Default.Version() + "/prefix/resource/myresource"},
{"prefix", "resource", "mynamespace", "", "/api/" + Version() + "/prefix/namespaces/mynamespace/resource"}, {"prefix", "resource", "mynamespace", "", "/api/" + Default.Version() + "/prefix/namespaces/mynamespace/resource"},
{"prefix", "resource", "", "", "/api/" + Version() + "/prefix/resource"}, {"prefix", "resource", "", "", "/api/" + Default.Version() + "/prefix/resource"},
{"", "resource", "mynamespace", "myresource", "/api/" + Version() + "/namespaces/mynamespace/resource/myresource"}, {"", "resource", "mynamespace", "myresource", "/api/" + Default.Version() + "/namespaces/mynamespace/resource/myresource"},
} }
for _, item := range testCases { for _, item := range testCases {
if actual := ResourcePathWithPrefix(item.prefix, item.resource, item.namespace, item.name); actual != item.expected { if actual := Default.ResourcePathWithPrefix(item.prefix, item.resource, item.namespace, item.name); actual != item.expected {
t.Errorf("Expected: %s, got: %s for prefix: %s, resource: %s, namespace: %s and name: %s", item.expected, actual, item.prefix, item.resource, item.namespace, item.name) t.Errorf("Expected: %s, got: %s for prefix: %s, resource: %s, namespace: %s and name: %s", item.expected, actual, item.prefix, item.resource, item.namespace, item.name)
} }
} }
...@@ -48,13 +48,13 @@ func TestResourcePath(t *testing.T) { ...@@ -48,13 +48,13 @@ func TestResourcePath(t *testing.T) {
name string name string
expected string expected string
}{ }{
{"resource", "mynamespace", "myresource", "/api/" + Version() + "/namespaces/mynamespace/resource/myresource"}, {"resource", "mynamespace", "myresource", "/api/" + Default.Version() + "/namespaces/mynamespace/resource/myresource"},
{"resource", "", "myresource", "/api/" + Version() + "/resource/myresource"}, {"resource", "", "myresource", "/api/" + Default.Version() + "/resource/myresource"},
{"resource", "mynamespace", "", "/api/" + Version() + "/namespaces/mynamespace/resource"}, {"resource", "mynamespace", "", "/api/" + Default.Version() + "/namespaces/mynamespace/resource"},
{"resource", "", "", "/api/" + Version() + "/resource"}, {"resource", "", "", "/api/" + Default.Version() + "/resource"},
} }
for _, item := range testCases { for _, item := range testCases {
if actual := ResourcePath(item.resource, item.namespace, item.name); actual != item.expected { if actual := Default.ResourcePath(item.resource, item.namespace, item.name); actual != item.expected {
t.Errorf("Expected: %s, got: %s for resource: %s, namespace: %s and name: %s", item.expected, actual, item.resource, item.namespace, item.name) t.Errorf("Expected: %s, got: %s for resource: %s, namespace: %s and name: %s", item.expected, actual, item.resource, item.namespace, item.name)
} }
} }
......
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// TODO: This GetVersion/GetGroup arrangement is temporary and will be replaced
// with a GroupAndVersion type.
package util
import "strings"
func GetVersion(groupVersion string) string {
s := strings.Split(groupVersion, "/")
if len(s) != 2 {
// e.g. return "v1" for groupVersion="v1"
return s[len(s)-1]
}
return s[1]
}
func GetGroup(groupVersion string) string {
s := strings.Split(groupVersion, "/")
if len(s) == 1 {
// e.g. return "" for groupVersion="v1"
return ""
}
return s[0]
}
/*
Copyright 2014 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package util
import "testing"
func TestGetVersion(t *testing.T) {
testCases := []struct {
groupVersion string
output string
}{
{
"v1",
"v1",
},
{
"experimental/v1alpha1",
"v1alpha1",
},
}
for _, test := range testCases {
actual := GetVersion(test.groupVersion)
if test.output != actual {
t.Errorf("expect version: %s, got: %s\n", test.output, actual)
}
}
}
func TestGetGroup(t *testing.T) {
testCases := []struct {
groupVersion string
output string
}{
{
"v1",
"",
},
{
"experimental/v1alpha1",
"experimental",
},
}
for _, test := range testCases {
actual := GetGroup(test.groupVersion)
if test.output != actual {
t.Errorf("expect version: %s, got: %s\n", test.output, actual)
}
}
}
...@@ -28,7 +28,7 @@ import ( ...@@ -28,7 +28,7 @@ import (
) )
func readPod(filename string) (string, error) { func readPod(filename string) (string, error) {
data, err := ioutil.ReadFile("testdata/" + testapi.Version() + "/" + filename) data, err := ioutil.ReadFile("testdata/" + testapi.Default.Version() + "/" + filename)
if err != nil { if err != nil {
return "", err return "", err
} }
...@@ -36,7 +36,7 @@ func readPod(filename string) (string, error) { ...@@ -36,7 +36,7 @@ func readPod(filename string) (string, error) {
} }
func loadSchemaForTest() (Schema, error) { func loadSchemaForTest() (Schema, error) {
pathToSwaggerSpec := "../../../api/swagger-spec/" + testapi.Version() + ".json" pathToSwaggerSpec := "../../../api/swagger-spec/" + testapi.Default.Version() + ".json"
data, err := ioutil.ReadFile(pathToSwaggerSpec) data, err := ioutil.ReadFile(pathToSwaggerSpec)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -71,7 +71,7 @@ func TestValidateOk(t *testing.T) { ...@@ -71,7 +71,7 @@ func TestValidateOk(t *testing.T) {
for _, test := range tests { for _, test := range tests {
testObj := test.obj testObj := test.obj
apiObjectFuzzer.Fuzz(testObj) apiObjectFuzzer.Fuzz(testObj)
data, err := testapi.Codec().Encode(testObj) data, err := testapi.Default.Codec().Encode(testObj)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
......
...@@ -638,7 +638,7 @@ func TestValidateEnv(t *testing.T) { ...@@ -638,7 +638,7 @@ func TestValidateEnv(t *testing.T) {
Name: "abc", Name: "abc",
ValueFrom: &api.EnvVarSource{ ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{ FieldRef: &api.ObjectFieldSelector{
APIVersion: testapi.Version(), APIVersion: testapi.Default.Version(),
FieldPath: "metadata.name", FieldPath: "metadata.name",
}, },
}, },
...@@ -670,7 +670,7 @@ func TestValidateEnv(t *testing.T) { ...@@ -670,7 +670,7 @@ func TestValidateEnv(t *testing.T) {
Value: "foo", Value: "foo",
ValueFrom: &api.EnvVarSource{ ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{ FieldRef: &api.ObjectFieldSelector{
APIVersion: testapi.Version(), APIVersion: testapi.Default.Version(),
FieldPath: "metadata.name", FieldPath: "metadata.name",
}, },
}, },
...@@ -683,7 +683,7 @@ func TestValidateEnv(t *testing.T) { ...@@ -683,7 +683,7 @@ func TestValidateEnv(t *testing.T) {
Name: "abc", Name: "abc",
ValueFrom: &api.EnvVarSource{ ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{ FieldRef: &api.ObjectFieldSelector{
APIVersion: testapi.Version(), APIVersion: testapi.Default.Version(),
}, },
}, },
}}, }},
...@@ -708,7 +708,7 @@ func TestValidateEnv(t *testing.T) { ...@@ -708,7 +708,7 @@ func TestValidateEnv(t *testing.T) {
ValueFrom: &api.EnvVarSource{ ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{ FieldRef: &api.ObjectFieldSelector{
FieldPath: "metadata.whoops", FieldPath: "metadata.whoops",
APIVersion: testapi.Version(), APIVersion: testapi.Default.Version(),
}, },
}, },
}}, }},
...@@ -747,7 +747,7 @@ func TestValidateEnv(t *testing.T) { ...@@ -747,7 +747,7 @@ func TestValidateEnv(t *testing.T) {
ValueFrom: &api.EnvVarSource{ ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{ FieldRef: &api.ObjectFieldSelector{
FieldPath: "status.phase", FieldPath: "status.phase",
APIVersion: testapi.Version(), APIVersion: testapi.Default.Version(),
}, },
}, },
}}, }},
......
...@@ -52,11 +52,11 @@ func expectHTTP(url string, code int, t *testing.T) { ...@@ -52,11 +52,11 @@ func expectHTTP(url string, code int, t *testing.T) {
} }
func getPath(resource, namespace, name string) string { func getPath(resource, namespace, name string) string {
return testapi.ResourcePath(resource, namespace, name) return testapi.Default.ResourcePath(resource, namespace, name)
} }
func pathWithPrefix(prefix, resource, namespace, name string) string { func pathWithPrefix(prefix, resource, namespace, name string) string {
return testapi.ResourcePathWithPrefix(prefix, resource, namespace, name) return testapi.Default.ResourcePathWithPrefix(prefix, resource, namespace, name)
} }
func TestMaxInFlight(t *testing.T) { func TestMaxInFlight(t *testing.T) {
...@@ -231,15 +231,15 @@ func TestGetAPIRequestInfo(t *testing.T) { ...@@ -231,15 +231,15 @@ func TestGetAPIRequestInfo(t *testing.T) {
{"GET", "/watch/namespaces/other/pods", "watch", "", "other", "pods", "", "Pod", "", []string{"pods"}}, {"GET", "/watch/namespaces/other/pods", "watch", "", "other", "pods", "", "Pod", "", []string{"pods"}},
// fully-qualified paths // fully-qualified paths
{"GET", getPath("pods", "other", ""), "list", testapi.Version(), "other", "pods", "", "Pod", "", []string{"pods"}}, {"GET", getPath("pods", "other", ""), "list", testapi.Default.Version(), "other", "pods", "", "Pod", "", []string{"pods"}},
{"GET", getPath("pods", "other", "foo"), "get", testapi.Version(), "other", "pods", "", "Pod", "foo", []string{"pods", "foo"}}, {"GET", getPath("pods", "other", "foo"), "get", testapi.Default.Version(), "other", "pods", "", "Pod", "foo", []string{"pods", "foo"}},
{"GET", getPath("pods", "", ""), "list", testapi.Version(), api.NamespaceAll, "pods", "", "Pod", "", []string{"pods"}}, {"GET", getPath("pods", "", ""), "list", testapi.Default.Version(), api.NamespaceAll, "pods", "", "Pod", "", []string{"pods"}},
{"POST", getPath("pods", "", ""), "create", testapi.Version(), api.NamespaceAll, "pods", "", "Pod", "", []string{"pods"}}, {"POST", getPath("pods", "", ""), "create", testapi.Default.Version(), api.NamespaceAll, "pods", "", "Pod", "", []string{"pods"}},
{"GET", getPath("pods", "", "foo"), "get", testapi.Version(), api.NamespaceAll, "pods", "", "Pod", "foo", []string{"pods", "foo"}}, {"GET", getPath("pods", "", "foo"), "get", testapi.Default.Version(), api.NamespaceAll, "pods", "", "Pod", "foo", []string{"pods", "foo"}},
{"GET", pathWithPrefix("proxy", "pods", "", "foo"), "proxy", testapi.Version(), api.NamespaceAll, "pods", "", "Pod", "foo", []string{"pods", "foo"}}, {"GET", pathWithPrefix("proxy", "pods", "", "foo"), "proxy", testapi.Default.Version(), api.NamespaceAll, "pods", "", "Pod", "foo", []string{"pods", "foo"}},
{"GET", pathWithPrefix("watch", "pods", "", ""), "watch", testapi.Version(), api.NamespaceAll, "pods", "", "Pod", "", []string{"pods"}}, {"GET", pathWithPrefix("watch", "pods", "", ""), "watch", testapi.Default.Version(), api.NamespaceAll, "pods", "", "Pod", "", []string{"pods"}},
{"GET", pathWithPrefix("redirect", "pods", "", ""), "redirect", testapi.Version(), api.NamespaceAll, "pods", "", "Pod", "", []string{"pods"}}, {"GET", pathWithPrefix("redirect", "pods", "", ""), "redirect", testapi.Default.Version(), api.NamespaceAll, "pods", "", "Pod", "", []string{"pods"}},
{"GET", pathWithPrefix("watch", "pods", "other", ""), "watch", testapi.Version(), "other", "pods", "", "Pod", "", []string{"pods"}}, {"GET", pathWithPrefix("watch", "pods", "other", ""), "watch", testapi.Default.Version(), "other", "pods", "", "Pod", "", []string{"pods"}},
// subresource identification // subresource identification
{"GET", "/namespaces/other/pods/foo/status", "get", "", "other", "pods", "status", "Pod", "foo", []string{"pods", "foo", "status"}}, {"GET", "/namespaces/other/pods/foo/status", "get", "", "other", "pods", "status", "Pod", "foo", []string{"pods", "foo", "status"}},
......
...@@ -54,7 +54,7 @@ func buildLocation(resourcePath string, query url.Values) string { ...@@ -54,7 +54,7 @@ func buildLocation(resourcePath string, query url.Values) string {
} }
func TestListWatchesCanList(t *testing.T) { func TestListWatchesCanList(t *testing.T) {
fieldSelectorQueryParamName := api.FieldSelectorQueryParam(testapi.Version()) fieldSelectorQueryParamName := api.FieldSelectorQueryParam(testapi.Default.Version())
table := []struct { table := []struct {
location string location string
resource string resource string
...@@ -63,7 +63,7 @@ func TestListWatchesCanList(t *testing.T) { ...@@ -63,7 +63,7 @@ func TestListWatchesCanList(t *testing.T) {
}{ }{
// Minion // Minion
{ {
location: testapi.ResourcePath("minions", api.NamespaceAll, ""), location: testapi.Default.ResourcePath("minions", api.NamespaceAll, ""),
resource: "minions", resource: "minions",
namespace: api.NamespaceAll, namespace: api.NamespaceAll,
fieldSelector: parseSelectorOrDie(""), fieldSelector: parseSelectorOrDie(""),
...@@ -71,7 +71,7 @@ func TestListWatchesCanList(t *testing.T) { ...@@ -71,7 +71,7 @@ func TestListWatchesCanList(t *testing.T) {
// pod with "assigned" field selector. // pod with "assigned" field selector.
{ {
location: buildLocation( location: buildLocation(
testapi.ResourcePath("pods", api.NamespaceAll, ""), testapi.Default.ResourcePath("pods", api.NamespaceAll, ""),
buildQueryValues(url.Values{fieldSelectorQueryParamName: []string{"spec.host="}})), buildQueryValues(url.Values{fieldSelectorQueryParamName: []string{"spec.host="}})),
resource: "pods", resource: "pods",
namespace: api.NamespaceAll, namespace: api.NamespaceAll,
...@@ -80,7 +80,7 @@ func TestListWatchesCanList(t *testing.T) { ...@@ -80,7 +80,7 @@ func TestListWatchesCanList(t *testing.T) {
// pod in namespace "foo" // pod in namespace "foo"
{ {
location: buildLocation( location: buildLocation(
testapi.ResourcePath("pods", "foo", ""), testapi.Default.ResourcePath("pods", "foo", ""),
buildQueryValues(url.Values{fieldSelectorQueryParamName: []string{"spec.host="}})), buildQueryValues(url.Values{fieldSelectorQueryParamName: []string{"spec.host="}})),
resource: "pods", resource: "pods",
namespace: "foo", namespace: "foo",
...@@ -95,7 +95,7 @@ func TestListWatchesCanList(t *testing.T) { ...@@ -95,7 +95,7 @@ func TestListWatchesCanList(t *testing.T) {
} }
server := httptest.NewServer(&handler) server := httptest.NewServer(&handler)
defer server.Close() defer server.Close()
client := client.NewOrDie(&client.Config{Host: server.URL, Version: testapi.Version()}) client := client.NewOrDie(&client.Config{Host: server.URL, Version: testapi.Default.Version()})
lw := NewListWatchFromClient(client, item.resource, item.namespace, item.fieldSelector) lw := NewListWatchFromClient(client, item.resource, item.namespace, item.fieldSelector)
// This test merely tests that the correct request is made. // This test merely tests that the correct request is made.
lw.List() lw.List()
...@@ -104,7 +104,7 @@ func TestListWatchesCanList(t *testing.T) { ...@@ -104,7 +104,7 @@ func TestListWatchesCanList(t *testing.T) {
} }
func TestListWatchesCanWatch(t *testing.T) { func TestListWatchesCanWatch(t *testing.T) {
fieldSelectorQueryParamName := api.FieldSelectorQueryParam(testapi.Version()) fieldSelectorQueryParamName := api.FieldSelectorQueryParam(testapi.Default.Version())
table := []struct { table := []struct {
rv string rv string
location string location string
...@@ -115,7 +115,7 @@ func TestListWatchesCanWatch(t *testing.T) { ...@@ -115,7 +115,7 @@ func TestListWatchesCanWatch(t *testing.T) {
// Minion // Minion
{ {
location: buildLocation( location: buildLocation(
testapi.ResourcePathWithPrefix("watch", "minions", api.NamespaceAll, ""), testapi.Default.ResourcePathWithPrefix("watch", "minions", api.NamespaceAll, ""),
buildQueryValues(url.Values{"resourceVersion": []string{""}})), buildQueryValues(url.Values{"resourceVersion": []string{""}})),
rv: "", rv: "",
resource: "minions", resource: "minions",
...@@ -124,7 +124,7 @@ func TestListWatchesCanWatch(t *testing.T) { ...@@ -124,7 +124,7 @@ func TestListWatchesCanWatch(t *testing.T) {
}, },
{ {
location: buildLocation( location: buildLocation(
testapi.ResourcePathWithPrefix("watch", "minions", api.NamespaceAll, ""), testapi.Default.ResourcePathWithPrefix("watch", "minions", api.NamespaceAll, ""),
buildQueryValues(url.Values{"resourceVersion": []string{"42"}})), buildQueryValues(url.Values{"resourceVersion": []string{"42"}})),
rv: "42", rv: "42",
resource: "minions", resource: "minions",
...@@ -134,7 +134,7 @@ func TestListWatchesCanWatch(t *testing.T) { ...@@ -134,7 +134,7 @@ func TestListWatchesCanWatch(t *testing.T) {
// pod with "assigned" field selector. // pod with "assigned" field selector.
{ {
location: buildLocation( location: buildLocation(
testapi.ResourcePathWithPrefix("watch", "pods", api.NamespaceAll, ""), testapi.Default.ResourcePathWithPrefix("watch", "pods", api.NamespaceAll, ""),
buildQueryValues(url.Values{fieldSelectorQueryParamName: []string{"spec.host="}, "resourceVersion": []string{"0"}})), buildQueryValues(url.Values{fieldSelectorQueryParamName: []string{"spec.host="}, "resourceVersion": []string{"0"}})),
rv: "0", rv: "0",
resource: "pods", resource: "pods",
...@@ -144,7 +144,7 @@ func TestListWatchesCanWatch(t *testing.T) { ...@@ -144,7 +144,7 @@ func TestListWatchesCanWatch(t *testing.T) {
// pod with namespace foo and assigned field selector // pod with namespace foo and assigned field selector
{ {
location: buildLocation( location: buildLocation(
testapi.ResourcePathWithPrefix("watch", "pods", "foo", ""), testapi.Default.ResourcePathWithPrefix("watch", "pods", "foo", ""),
buildQueryValues(url.Values{fieldSelectorQueryParamName: []string{"spec.host="}, "resourceVersion": []string{"0"}})), buildQueryValues(url.Values{fieldSelectorQueryParamName: []string{"spec.host="}, "resourceVersion": []string{"0"}})),
rv: "0", rv: "0",
resource: "pods", resource: "pods",
...@@ -161,7 +161,7 @@ func TestListWatchesCanWatch(t *testing.T) { ...@@ -161,7 +161,7 @@ func TestListWatchesCanWatch(t *testing.T) {
} }
server := httptest.NewServer(&handler) server := httptest.NewServer(&handler)
defer server.Close() defer server.Close()
client := client.NewOrDie(&client.Config{Host: server.URL, Version: testapi.Version()}) client := client.NewOrDie(&client.Config{Host: server.URL, Version: testapi.Default.Version()})
lw := NewListWatchFromClient(client, item.resource, item.namespace, item.fieldSelector) lw := NewListWatchFromClient(client, item.resource, item.namespace, item.fieldSelector)
// This test merely tests that the correct request is made. // This test merely tests that the correct request is made.
lw.Watch(item.rv) lw.Watch(item.rv)
......
...@@ -68,23 +68,34 @@ type testClient struct { ...@@ -68,23 +68,34 @@ type testClient struct {
QueryValidator map[string]func(string, string) bool QueryValidator map[string]func(string, string) bool
} }
func (c *testClient) Setup() *testClient { func (c *testClient) Setup(t *testing.T) *testClient {
c.handler = &util.FakeHandler{ c.handler = &util.FakeHandler{
StatusCode: c.Response.StatusCode, StatusCode: c.Response.StatusCode,
} }
if responseBody := body(c.Response.Body, c.Response.RawBody); responseBody != nil { if responseBody := body(t, c.Response.Body, c.Response.RawBody); responseBody != nil {
c.handler.ResponseBody = *responseBody c.handler.ResponseBody = *responseBody
} }
c.server = httptest.NewServer(c.handler) c.server = httptest.NewServer(c.handler)
if c.Client == nil { if c.Client == nil {
version := c.Version version := c.Version
if len(version) == 0 { if len(version) == 0 {
version = testapi.Version() version = testapi.Default.Version()
} }
c.Client = NewOrDie(&Config{ c.Client = NewOrDie(&Config{
Host: c.server.URL, Host: c.server.URL,
Version: version, Version: version,
}) })
// TODO: caesarxuchao: hacky way to specify version of Experimental client.
// We will fix this by supporting multiple group versions in Config
version = c.Version
if len(version) == 0 {
version = testapi.Experimental.Version()
}
c.ExperimentalClient = NewExperimentalOrDie(&Config{
Host: c.server.URL,
Version: version,
})
} }
c.QueryValidator = map[string]func(string, string) bool{} c.QueryValidator = map[string]func(string, string) bool{}
return c return c
...@@ -124,7 +135,7 @@ func (c *testClient) ValidateCommon(t *testing.T, err error) { ...@@ -124,7 +135,7 @@ func (c *testClient) ValidateCommon(t *testing.T, err error) {
return return
} }
requestBody := body(c.Request.Body, c.Request.RawBody) requestBody := body(t, c.Request.Body, c.Request.RawBody)
actualQuery := c.handler.RequestReceived.URL.Query() actualQuery := c.handler.RequestReceived.URL.Query()
t.Logf("got query: %v", actualQuery) t.Logf("got query: %v", actualQuery)
t.Logf("path: %v", c.Request.Path) t.Logf("path: %v", c.Request.Path)
...@@ -136,9 +147,9 @@ func (c *testClient) ValidateCommon(t *testing.T, err error) { ...@@ -136,9 +147,9 @@ func (c *testClient) ValidateCommon(t *testing.T, err error) {
validator, ok := c.QueryValidator[key] validator, ok := c.QueryValidator[key]
if !ok { if !ok {
switch key { switch key {
case api.LabelSelectorQueryParam(testapi.Version()): case api.LabelSelectorQueryParam(testapi.Default.Version()):
validator = validateLabels validator = validateLabels
case api.FieldSelectorQueryParam(testapi.Version()): case api.FieldSelectorQueryParam(testapi.Default.Version()):
validator = validateFields validator = validateFields
default: default:
validator = func(a, b string) bool { return a == b } validator = func(a, b string) bool { return a == b }
...@@ -200,9 +211,30 @@ func validateFields(a, b string) bool { ...@@ -200,9 +211,30 @@ func validateFields(a, b string) bool {
return sA.String() == sB.String() return sA.String() == sB.String()
} }
func body(obj runtime.Object, raw *string) *string { func body(t *testing.T, obj runtime.Object, raw *string) *string {
if obj != nil { if obj != nil {
bs, _ := testapi.Codec().Encode(obj) _, kind, err := api.Scheme.ObjectVersionAndKind(obj)
if err != nil {
t.Errorf("unexpected encoding error: %v", err)
}
// TODO: caesarxuchao: we should detect which group an object belongs to
// by using the version returned by Schem.ObjectVersionAndKind() once we
// split the schemes for internal objects.
// TODO: caesarxuchao: we should add a map from kind to group in Scheme.
var bs []byte
if api.Scheme.Recognizes(testapi.Default.GroupAndVersion(), kind) {
bs, err = testapi.Default.Codec().Encode(obj)
if err != nil {
t.Errorf("unexpected encoding error: %v", err)
}
} else if api.Scheme.Recognizes(testapi.Experimental.GroupAndVersion(), kind) {
bs, err = testapi.Experimental.Codec().Encode(obj)
if err != nil {
t.Errorf("unexpected encoding error: %v", err)
}
} else {
t.Errorf("unexpected kind: %v", kind)
}
body := string(bs) body := string(bs)
return &body return &body
} }
......
...@@ -20,8 +20,8 @@ import ( ...@@ -20,8 +20,8 @@ import (
"testing" "testing"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/expapi" "k8s.io/kubernetes/pkg/expapi"
"k8s.io/kubernetes/pkg/expapi/testapi"
"k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/labels"
) )
...@@ -34,7 +34,7 @@ func TestListDaemons(t *testing.T) { ...@@ -34,7 +34,7 @@ func TestListDaemons(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath(getDCResourceName(), ns, ""), Path: testapi.Experimental.ResourcePath(getDCResourceName(), ns, ""),
}, },
Response: Response{StatusCode: 200, Response: Response{StatusCode: 200,
Body: &expapi.DaemonList{ Body: &expapi.DaemonList{
...@@ -55,7 +55,7 @@ func TestListDaemons(t *testing.T) { ...@@ -55,7 +55,7 @@ func TestListDaemons(t *testing.T) {
}, },
}, },
} }
receivedControllerList, err := c.Setup().Experimental().Daemons(ns).List(labels.Everything()) receivedControllerList, err := c.Setup(t).Experimental().Daemons(ns).List(labels.Everything())
c.Validate(t, receivedControllerList, err) c.Validate(t, receivedControllerList, err)
} }
...@@ -63,7 +63,7 @@ func TestListDaemons(t *testing.T) { ...@@ -63,7 +63,7 @@ func TestListDaemons(t *testing.T) {
func TestGetDaemon(t *testing.T) { func TestGetDaemon(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{ c := &testClient{
Request: testRequest{Method: "GET", Path: testapi.ResourcePath(getDCResourceName(), ns, "foo"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "GET", Path: testapi.Experimental.ResourcePath(getDCResourceName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{ Response: Response{
StatusCode: 200, StatusCode: 200,
Body: &expapi.Daemon{ Body: &expapi.Daemon{
...@@ -80,14 +80,14 @@ func TestGetDaemon(t *testing.T) { ...@@ -80,14 +80,14 @@ func TestGetDaemon(t *testing.T) {
}, },
}, },
} }
receivedController, err := c.Setup().Experimental().Daemons(ns).Get("foo") receivedController, err := c.Setup(t).Experimental().Daemons(ns).Get("foo")
c.Validate(t, receivedController, err) c.Validate(t, receivedController, err)
} }
func TestGetDaemonWithNoName(t *testing.T) { func TestGetDaemonWithNoName(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{Error: true} c := &testClient{Error: true}
receivedPod, err := c.Setup().Experimental().Daemons(ns).Get("") receivedPod, err := c.Setup(t).Experimental().Daemons(ns).Get("")
if (err != nil) && (err.Error() != nameRequiredError) { if (err != nil) && (err.Error() != nameRequiredError) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err) t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
} }
...@@ -101,7 +101,7 @@ func TestUpdateDaemon(t *testing.T) { ...@@ -101,7 +101,7 @@ func TestUpdateDaemon(t *testing.T) {
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"}, ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"},
} }
c := &testClient{ c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath(getDCResourceName(), ns, "foo"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "PUT", Path: testapi.Experimental.ResourcePath(getDCResourceName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{ Response: Response{
StatusCode: 200, StatusCode: 200,
Body: &expapi.Daemon{ Body: &expapi.Daemon{
...@@ -118,17 +118,17 @@ func TestUpdateDaemon(t *testing.T) { ...@@ -118,17 +118,17 @@ func TestUpdateDaemon(t *testing.T) {
}, },
}, },
} }
receivedController, err := c.Setup().Experimental().Daemons(ns).Update(requestController) receivedController, err := c.Setup(t).Experimental().Daemons(ns).Update(requestController)
c.Validate(t, receivedController, err) c.Validate(t, receivedController, err)
} }
func TestDeleteDaemon(t *testing.T) { func TestDeleteDaemon(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{ c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.ResourcePath(getDCResourceName(), ns, "foo"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "DELETE", Path: testapi.Experimental.ResourcePath(getDCResourceName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
err := c.Setup().Experimental().Daemons(ns).Delete("foo") err := c.Setup(t).Experimental().Daemons(ns).Delete("foo")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -138,7 +138,7 @@ func TestCreateDaemon(t *testing.T) { ...@@ -138,7 +138,7 @@ func TestCreateDaemon(t *testing.T) {
ObjectMeta: api.ObjectMeta{Name: "foo"}, ObjectMeta: api.ObjectMeta{Name: "foo"},
} }
c := &testClient{ c := &testClient{
Request: testRequest{Method: "POST", Path: testapi.ResourcePath(getDCResourceName(), ns, ""), Body: requestController, Query: buildQueryValues(nil)}, Request: testRequest{Method: "POST", Path: testapi.Experimental.ResourcePath(getDCResourceName(), ns, ""), Body: requestController, Query: buildQueryValues(nil)},
Response: Response{ Response: Response{
StatusCode: 200, StatusCode: 200,
Body: &expapi.Daemon{ Body: &expapi.Daemon{
...@@ -155,6 +155,6 @@ func TestCreateDaemon(t *testing.T) { ...@@ -155,6 +155,6 @@ func TestCreateDaemon(t *testing.T) {
}, },
}, },
} }
receivedController, err := c.Setup().Experimental().Daemons(ns).Create(requestController) receivedController, err := c.Setup(t).Experimental().Daemons(ns).Create(requestController)
c.Validate(t, receivedController, err) c.Validate(t, receivedController, err)
} }
...@@ -21,8 +21,8 @@ import ( ...@@ -21,8 +21,8 @@ import (
"testing" "testing"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/expapi" "k8s.io/kubernetes/pkg/expapi"
"k8s.io/kubernetes/pkg/expapi/testapi"
"k8s.io/kubernetes/pkg/fields" "k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/labels"
) )
...@@ -42,14 +42,14 @@ func TestDeploymentCreate(t *testing.T) { ...@@ -42,14 +42,14 @@ func TestDeploymentCreate(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "POST", Method: "POST",
Path: testapi.ResourcePath(getDeploymentsResoureName(), ns, ""), Path: testapi.Experimental.ResourcePath(getDeploymentsResoureName(), ns, ""),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: &deployment, Body: &deployment,
}, },
Response: Response{StatusCode: 200, Body: &deployment}, Response: Response{StatusCode: 200, Body: &deployment},
} }
response, err := c.Setup().Deployments(ns).Create(&deployment) response, err := c.Setup(t).Deployments(ns).Create(&deployment)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
...@@ -67,14 +67,14 @@ func TestDeploymentGet(t *testing.T) { ...@@ -67,14 +67,14 @@ func TestDeploymentGet(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath(getDeploymentsResoureName(), ns, "abc"), Path: testapi.Experimental.ResourcePath(getDeploymentsResoureName(), ns, "abc"),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: nil, Body: nil,
}, },
Response: Response{StatusCode: 200, Body: deployment}, Response: Response{StatusCode: 200, Body: deployment},
} }
response, err := c.Setup().Deployments(ns).Get("abc") response, err := c.Setup(t).Deployments(ns).Get("abc")
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -93,13 +93,13 @@ func TestDeploymentList(t *testing.T) { ...@@ -93,13 +93,13 @@ func TestDeploymentList(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath(getDeploymentsResoureName(), ns, ""), Path: testapi.Experimental.ResourcePath(getDeploymentsResoureName(), ns, ""),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: nil, Body: nil,
}, },
Response: Response{StatusCode: 200, Body: deploymentList}, Response: Response{StatusCode: 200, Body: deploymentList},
} }
response, err := c.Setup().Deployments(ns).List(labels.Everything(), fields.Everything()) response, err := c.Setup(t).Deployments(ns).List(labels.Everything(), fields.Everything())
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -115,12 +115,12 @@ func TestDeploymentUpdate(t *testing.T) { ...@@ -115,12 +115,12 @@ func TestDeploymentUpdate(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "PUT", Method: "PUT",
Path: testapi.ResourcePath(getDeploymentsResoureName(), ns, "abc"), Path: testapi.Experimental.ResourcePath(getDeploymentsResoureName(), ns, "abc"),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
}, },
Response: Response{StatusCode: 200, Body: deployment}, Response: Response{StatusCode: 200, Body: deployment},
} }
response, err := c.Setup().Deployments(ns).Update(deployment) response, err := c.Setup(t).Deployments(ns).Update(deployment)
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -129,12 +129,12 @@ func TestDeploymentDelete(t *testing.T) { ...@@ -129,12 +129,12 @@ func TestDeploymentDelete(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "DELETE", Method: "DELETE",
Path: testapi.ResourcePath(getDeploymentsResoureName(), ns, "foo"), Path: testapi.Experimental.ResourcePath(getDeploymentsResoureName(), ns, "foo"),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
}, },
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
err := c.Setup().Deployments(ns).Delete("foo", nil) err := c.Setup(t).Deployments(ns).Delete("foo", nil)
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -142,11 +142,11 @@ func TestDeploymentWatch(t *testing.T) { ...@@ -142,11 +142,11 @@ func TestDeploymentWatch(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePathWithPrefix("watch", getDeploymentsResoureName(), "", ""), Path: testapi.Experimental.ResourcePathWithPrefix("watch", getDeploymentsResoureName(), "", ""),
Query: url.Values{"resourceVersion": []string{}}, Query: url.Values{"resourceVersion": []string{}},
}, },
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
_, err := c.Setup().Deployments(api.NamespaceAll).Watch(labels.Everything(), fields.Everything(), "") _, err := c.Setup(t).Deployments(api.NamespaceAll).Watch(labels.Everything(), fields.Everything(), "")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -27,7 +27,7 @@ import ( ...@@ -27,7 +27,7 @@ import (
func TestListEndpoints(t *testing.T) { func TestListEndpoints(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{ c := &testClient{
Request: testRequest{Method: "GET", Path: testapi.ResourcePath("endpoints", ns, ""), Query: buildQueryValues(nil)}, Request: testRequest{Method: "GET", Path: testapi.Default.ResourcePath("endpoints", ns, ""), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Response: Response{StatusCode: 200,
Body: &api.EndpointsList{ Body: &api.EndpointsList{
Items: []api.Endpoints{ Items: []api.Endpoints{
...@@ -42,24 +42,24 @@ func TestListEndpoints(t *testing.T) { ...@@ -42,24 +42,24 @@ func TestListEndpoints(t *testing.T) {
}, },
}, },
} }
receivedEndpointsList, err := c.Setup().Endpoints(ns).List(labels.Everything()) receivedEndpointsList, err := c.Setup(t).Endpoints(ns).List(labels.Everything())
c.Validate(t, receivedEndpointsList, err) c.Validate(t, receivedEndpointsList, err)
} }
func TestGetEndpoints(t *testing.T) { func TestGetEndpoints(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{ c := &testClient{
Request: testRequest{Method: "GET", Path: testapi.ResourcePath("endpoints", ns, "endpoint-1"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "GET", Path: testapi.Default.ResourcePath("endpoints", ns, "endpoint-1"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: &api.Endpoints{ObjectMeta: api.ObjectMeta{Name: "endpoint-1"}}}, Response: Response{StatusCode: 200, Body: &api.Endpoints{ObjectMeta: api.ObjectMeta{Name: "endpoint-1"}}},
} }
response, err := c.Setup().Endpoints(ns).Get("endpoint-1") response, err := c.Setup(t).Endpoints(ns).Get("endpoint-1")
c.Validate(t, response, err) c.Validate(t, response, err)
} }
func TestGetEndpointWithNoName(t *testing.T) { func TestGetEndpointWithNoName(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{Error: true} c := &testClient{Error: true}
receivedPod, err := c.Setup().Endpoints(ns).Get("") receivedPod, err := c.Setup(t).Endpoints(ns).Get("")
if (err != nil) && (err.Error() != nameRequiredError) { if (err != nil) && (err.Error() != nameRequiredError) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err) t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
} }
......
...@@ -32,24 +32,24 @@ func TestEventSearch(t *testing.T) { ...@@ -32,24 +32,24 @@ func TestEventSearch(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath("events", "baz", ""), Path: testapi.Default.ResourcePath("events", "baz", ""),
Query: url.Values{ Query: url.Values{
api.FieldSelectorQueryParam(testapi.Version()): []string{ api.FieldSelectorQueryParam(testapi.Default.Version()): []string{
getInvolvedObjectNameFieldLabel(testapi.Version()) + "=foo,", getInvolvedObjectNameFieldLabel(testapi.Default.Version()) + "=foo,",
"involvedObject.namespace=baz,", "involvedObject.namespace=baz,",
"involvedObject.kind=Pod", "involvedObject.kind=Pod",
}, },
api.LabelSelectorQueryParam(testapi.Version()): []string{}, api.LabelSelectorQueryParam(testapi.Default.Version()): []string{},
}, },
}, },
Response: Response{StatusCode: 200, Body: &api.EventList{}}, Response: Response{StatusCode: 200, Body: &api.EventList{}},
} }
eventList, err := c.Setup().Events("baz").Search( eventList, err := c.Setup(t).Events("baz").Search(
&api.Pod{ &api.Pod{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Name: "foo", Name: "foo",
Namespace: "baz", Namespace: "baz",
SelfLink: testapi.SelfLink("pods", ""), SelfLink: testapi.Default.SelfLink("pods", ""),
}, },
}, },
) )
...@@ -78,13 +78,13 @@ func TestEventCreate(t *testing.T) { ...@@ -78,13 +78,13 @@ func TestEventCreate(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "POST", Method: "POST",
Path: testapi.ResourcePath("events", api.NamespaceDefault, ""), Path: testapi.Default.ResourcePath("events", api.NamespaceDefault, ""),
Body: event, Body: event,
}, },
Response: Response{StatusCode: 200, Body: event}, Response: Response{StatusCode: 200, Body: event},
} }
response, err := c.Setup().Events(api.NamespaceDefault).Create(event) response, err := c.Setup(t).Events(api.NamespaceDefault).Create(event)
if err != nil { if err != nil {
t.Fatalf("%v should be nil.", err) t.Fatalf("%v should be nil.", err)
...@@ -117,13 +117,13 @@ func TestEventGet(t *testing.T) { ...@@ -117,13 +117,13 @@ func TestEventGet(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath("events", "other", "1"), Path: testapi.Default.ResourcePath("events", "other", "1"),
Body: nil, Body: nil,
}, },
Response: Response{StatusCode: 200, Body: event}, Response: Response{StatusCode: 200, Body: event},
} }
response, err := c.Setup().Events("other").Get("1") response, err := c.Setup(t).Events("other").Get("1")
if err != nil { if err != nil {
t.Fatalf("%v should be nil.", err) t.Fatalf("%v should be nil.", err)
...@@ -158,12 +158,12 @@ func TestEventList(t *testing.T) { ...@@ -158,12 +158,12 @@ func TestEventList(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath("events", ns, ""), Path: testapi.Default.ResourcePath("events", ns, ""),
Body: nil, Body: nil,
}, },
Response: Response{StatusCode: 200, Body: eventList}, Response: Response{StatusCode: 200, Body: eventList},
} }
response, err := c.Setup().Events(ns).List(labels.Everything(), response, err := c.Setup(t).Events(ns).List(labels.Everything(),
fields.Everything()) fields.Everything())
if err != nil { if err != nil {
...@@ -186,10 +186,10 @@ func TestEventDelete(t *testing.T) { ...@@ -186,10 +186,10 @@ func TestEventDelete(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "DELETE", Method: "DELETE",
Path: testapi.ResourcePath("events", ns, "foo"), Path: testapi.Default.ResourcePath("events", ns, "foo"),
}, },
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
err := c.Setup().Events(ns).Delete("foo") err := c.Setup(t).Events(ns).Delete("foo")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -41,23 +41,23 @@ type FakeRESTClient struct { ...@@ -41,23 +41,23 @@ type FakeRESTClient struct {
} }
func (c *FakeRESTClient) Get() *Request { func (c *FakeRESTClient) Get() *Request {
return NewRequest(c, "GET", &url.URL{Host: "localhost"}, testapi.Version(), c.Codec) return NewRequest(c, "GET", &url.URL{Host: "localhost"}, testapi.Default.Version(), c.Codec)
} }
func (c *FakeRESTClient) Put() *Request { func (c *FakeRESTClient) Put() *Request {
return NewRequest(c, "PUT", &url.URL{Host: "localhost"}, testapi.Version(), c.Codec) return NewRequest(c, "PUT", &url.URL{Host: "localhost"}, testapi.Default.Version(), c.Codec)
} }
func (c *FakeRESTClient) Patch(_ api.PatchType) *Request { func (c *FakeRESTClient) Patch(_ api.PatchType) *Request {
return NewRequest(c, "PATCH", &url.URL{Host: "localhost"}, testapi.Version(), c.Codec) return NewRequest(c, "PATCH", &url.URL{Host: "localhost"}, testapi.Default.Version(), c.Codec)
} }
func (c *FakeRESTClient) Post() *Request { func (c *FakeRESTClient) Post() *Request {
return NewRequest(c, "POST", &url.URL{Host: "localhost"}, testapi.Version(), c.Codec) return NewRequest(c, "POST", &url.URL{Host: "localhost"}, testapi.Default.Version(), c.Codec)
} }
func (c *FakeRESTClient) Delete() *Request { func (c *FakeRESTClient) Delete() *Request {
return NewRequest(c, "DELETE", &url.URL{Host: "localhost"}, testapi.Version(), c.Codec) return NewRequest(c, "DELETE", &url.URL{Host: "localhost"}, testapi.Default.Version(), c.Codec)
} }
func (c *FakeRESTClient) Do(req *http.Request) (*http.Response, error) { func (c *FakeRESTClient) Do(req *http.Request) (*http.Response, error) {
......
...@@ -401,40 +401,40 @@ func TestNegotiateVersion(t *testing.T) { ...@@ -401,40 +401,40 @@ func TestNegotiateVersion(t *testing.T) {
name: "server supports client default", name: "server supports client default",
version: "version1", version: "version1",
config: &Config{}, config: &Config{},
serverVersions: []string{"version1", testapi.Version()}, serverVersions: []string{"version1", testapi.Default.Version()},
clientVersions: []string{"version1", testapi.Version()}, clientVersions: []string{"version1", testapi.Default.Version()},
expectedVersion: "version1", expectedVersion: "version1",
expectErr: false, expectErr: false,
}, },
{ {
name: "server falls back to client supported", name: "server falls back to client supported",
version: testapi.Version(), version: testapi.Default.Version(),
config: &Config{}, config: &Config{},
serverVersions: []string{"version1"}, serverVersions: []string{"version1"},
clientVersions: []string{"version1", testapi.Version()}, clientVersions: []string{"version1", testapi.Default.Version()},
expectedVersion: "version1", expectedVersion: "version1",
expectErr: false, expectErr: false,
}, },
{ {
name: "explicit version supported", name: "explicit version supported",
version: "", version: "",
config: &Config{Version: testapi.Version()}, config: &Config{Version: testapi.Default.Version()},
serverVersions: []string{"version1", testapi.Version()}, serverVersions: []string{"version1", testapi.Default.Version()},
clientVersions: []string{"version1", testapi.Version()}, clientVersions: []string{"version1", testapi.Default.Version()},
expectedVersion: testapi.Version(), expectedVersion: testapi.Default.Version(),
expectErr: false, expectErr: false,
}, },
{ {
name: "explicit version not supported", name: "explicit version not supported",
version: "", version: "",
config: &Config{Version: testapi.Version()}, config: &Config{Version: testapi.Default.Version()},
serverVersions: []string{"version1"}, serverVersions: []string{"version1"},
clientVersions: []string{"version1", testapi.Version()}, clientVersions: []string{"version1", testapi.Default.Version()},
expectedVersion: "", expectedVersion: "",
expectErr: true, expectErr: true,
}, },
} }
codec := testapi.Codec() codec := testapi.Default.Codec()
for _, test := range tests { for _, test := range tests {
fakeClient := &FakeRESTClient{ fakeClient := &FakeRESTClient{
......
...@@ -21,8 +21,8 @@ import ( ...@@ -21,8 +21,8 @@ import (
"testing" "testing"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/expapi" "k8s.io/kubernetes/pkg/expapi"
"k8s.io/kubernetes/pkg/expapi/testapi"
"k8s.io/kubernetes/pkg/fields" "k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/labels"
) )
...@@ -42,14 +42,14 @@ func TestHorizontalPodAutoscalerCreate(t *testing.T) { ...@@ -42,14 +42,14 @@ func TestHorizontalPodAutoscalerCreate(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "POST", Method: "POST",
Path: testapi.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, ""), Path: testapi.Experimental.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, ""),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: &horizontalPodAutoscaler, Body: &horizontalPodAutoscaler,
}, },
Response: Response{StatusCode: 200, Body: &horizontalPodAutoscaler}, Response: Response{StatusCode: 200, Body: &horizontalPodAutoscaler},
} }
response, err := c.Setup().Experimental().HorizontalPodAutoscalers(ns).Create(&horizontalPodAutoscaler) response, err := c.Setup(t).Experimental().HorizontalPodAutoscalers(ns).Create(&horizontalPodAutoscaler)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
...@@ -67,14 +67,14 @@ func TestHorizontalPodAutoscalerGet(t *testing.T) { ...@@ -67,14 +67,14 @@ func TestHorizontalPodAutoscalerGet(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, "abc"), Path: testapi.Experimental.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, "abc"),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: nil, Body: nil,
}, },
Response: Response{StatusCode: 200, Body: horizontalPodAutoscaler}, Response: Response{StatusCode: 200, Body: horizontalPodAutoscaler},
} }
response, err := c.Setup().Experimental().HorizontalPodAutoscalers(ns).Get("abc") response, err := c.Setup(t).Experimental().HorizontalPodAutoscalers(ns).Get("abc")
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -93,13 +93,13 @@ func TestHorizontalPodAutoscalerList(t *testing.T) { ...@@ -93,13 +93,13 @@ func TestHorizontalPodAutoscalerList(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, ""), Path: testapi.Experimental.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, ""),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: nil, Body: nil,
}, },
Response: Response{StatusCode: 200, Body: horizontalPodAutoscalerList}, Response: Response{StatusCode: 200, Body: horizontalPodAutoscalerList},
} }
response, err := c.Setup().Experimental().HorizontalPodAutoscalers(ns).List(labels.Everything(), fields.Everything()) response, err := c.Setup(t).Experimental().HorizontalPodAutoscalers(ns).List(labels.Everything(), fields.Everything())
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -113,20 +113,20 @@ func TestHorizontalPodAutoscalerUpdate(t *testing.T) { ...@@ -113,20 +113,20 @@ func TestHorizontalPodAutoscalerUpdate(t *testing.T) {
}, },
} }
c := &testClient{ c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, "abc"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "PUT", Path: testapi.Experimental.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, "abc"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: horizontalPodAutoscaler}, Response: Response{StatusCode: 200, Body: horizontalPodAutoscaler},
} }
response, err := c.Setup().Experimental().HorizontalPodAutoscalers(ns).Update(horizontalPodAutoscaler) response, err := c.Setup(t).Experimental().HorizontalPodAutoscalers(ns).Update(horizontalPodAutoscaler)
c.Validate(t, response, err) c.Validate(t, response, err)
} }
func TestHorizontalPodAutoscalerDelete(t *testing.T) { func TestHorizontalPodAutoscalerDelete(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{ c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, "foo"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "DELETE", Path: testapi.Experimental.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
err := c.Setup().Experimental().HorizontalPodAutoscalers(ns).Delete("foo", nil) err := c.Setup(t).Experimental().HorizontalPodAutoscalers(ns).Delete("foo", nil)
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -134,10 +134,10 @@ func TestHorizontalPodAutoscalerWatch(t *testing.T) { ...@@ -134,10 +134,10 @@ func TestHorizontalPodAutoscalerWatch(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePathWithPrefix("watch", getHorizontalPodAutoscalersResoureName(), "", ""), Path: testapi.Experimental.ResourcePathWithPrefix("watch", getHorizontalPodAutoscalersResoureName(), "", ""),
Query: url.Values{"resourceVersion": []string{}}}, Query: url.Values{"resourceVersion": []string{}}},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
_, err := c.Setup().Experimental().HorizontalPodAutoscalers(api.NamespaceAll).Watch(labels.Everything(), fields.Everything(), "") _, err := c.Setup(t).Experimental().HorizontalPodAutoscalers(api.NamespaceAll).Watch(labels.Everything(), fields.Everything(), "")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -56,14 +56,14 @@ func TestLimitRangeCreate(t *testing.T) { ...@@ -56,14 +56,14 @@ func TestLimitRangeCreate(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "POST", Method: "POST",
Path: testapi.ResourcePath(getLimitRangesResourceName(), ns, ""), Path: testapi.Default.ResourcePath(getLimitRangesResourceName(), ns, ""),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: limitRange, Body: limitRange,
}, },
Response: Response{StatusCode: 200, Body: limitRange}, Response: Response{StatusCode: 200, Body: limitRange},
} }
response, err := c.Setup().LimitRanges(ns).Create(limitRange) response, err := c.Setup(t).LimitRanges(ns).Create(limitRange)
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -92,14 +92,14 @@ func TestLimitRangeGet(t *testing.T) { ...@@ -92,14 +92,14 @@ func TestLimitRangeGet(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath(getLimitRangesResourceName(), ns, "abc"), Path: testapi.Default.ResourcePath(getLimitRangesResourceName(), ns, "abc"),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: nil, Body: nil,
}, },
Response: Response{StatusCode: 200, Body: limitRange}, Response: Response{StatusCode: 200, Body: limitRange},
} }
response, err := c.Setup().LimitRanges(ns).Get("abc") response, err := c.Setup(t).LimitRanges(ns).Get("abc")
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -116,13 +116,13 @@ func TestLimitRangeList(t *testing.T) { ...@@ -116,13 +116,13 @@ func TestLimitRangeList(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath(getLimitRangesResourceName(), ns, ""), Path: testapi.Default.ResourcePath(getLimitRangesResourceName(), ns, ""),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: nil, Body: nil,
}, },
Response: Response{StatusCode: 200, Body: limitRangeList}, Response: Response{StatusCode: 200, Body: limitRangeList},
} }
response, err := c.Setup().LimitRanges(ns).List(labels.Everything()) response, err := c.Setup(t).LimitRanges(ns).List(labels.Everything())
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -150,10 +150,10 @@ func TestLimitRangeUpdate(t *testing.T) { ...@@ -150,10 +150,10 @@ func TestLimitRangeUpdate(t *testing.T) {
}, },
} }
c := &testClient{ c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath(getLimitRangesResourceName(), ns, "abc"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath(getLimitRangesResourceName(), ns, "abc"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: limitRange}, Response: Response{StatusCode: 200, Body: limitRange},
} }
response, err := c.Setup().LimitRanges(ns).Update(limitRange) response, err := c.Setup(t).LimitRanges(ns).Update(limitRange)
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -180,10 +180,10 @@ func TestInvalidLimitRangeUpdate(t *testing.T) { ...@@ -180,10 +180,10 @@ func TestInvalidLimitRangeUpdate(t *testing.T) {
}, },
} }
c := &testClient{ c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath(getLimitRangesResourceName(), ns, "abc"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath(getLimitRangesResourceName(), ns, "abc"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: limitRange}, Response: Response{StatusCode: 200, Body: limitRange},
} }
_, err := c.Setup().LimitRanges(ns).Update(limitRange) _, err := c.Setup(t).LimitRanges(ns).Update(limitRange)
if err == nil { if err == nil {
t.Errorf("Expected an error due to missing ResourceVersion") t.Errorf("Expected an error due to missing ResourceVersion")
} }
...@@ -192,10 +192,10 @@ func TestInvalidLimitRangeUpdate(t *testing.T) { ...@@ -192,10 +192,10 @@ func TestInvalidLimitRangeUpdate(t *testing.T) {
func TestLimitRangeDelete(t *testing.T) { func TestLimitRangeDelete(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{ c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.ResourcePath(getLimitRangesResourceName(), ns, "foo"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath(getLimitRangesResourceName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
err := c.Setup().LimitRanges(ns).Delete("foo") err := c.Setup(t).LimitRanges(ns).Delete("foo")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -203,10 +203,10 @@ func TestLimitRangeWatch(t *testing.T) { ...@@ -203,10 +203,10 @@ func TestLimitRangeWatch(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePathWithPrefix("watch", getLimitRangesResourceName(), "", ""), Path: testapi.Default.ResourcePathWithPrefix("watch", getLimitRangesResourceName(), "", ""),
Query: url.Values{"resourceVersion": []string{}}}, Query: url.Values{"resourceVersion": []string{}}},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
_, err := c.Setup().LimitRanges(api.NamespaceAll).Watch(labels.Everything(), fields.Everything(), "") _, err := c.Setup(t).LimitRanges(api.NamespaceAll).Watch(labels.Everything(), fields.Everything(), "")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -34,14 +34,14 @@ func TestNamespaceCreate(t *testing.T) { ...@@ -34,14 +34,14 @@ func TestNamespaceCreate(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "POST", Method: "POST",
Path: testapi.ResourcePath("namespaces", "", ""), Path: testapi.Default.ResourcePath("namespaces", "", ""),
Body: namespace, Body: namespace,
}, },
Response: Response{StatusCode: 200, Body: namespace}, Response: Response{StatusCode: 200, Body: namespace},
} }
// from the source ns, provision a new global namespace "foo" // from the source ns, provision a new global namespace "foo"
response, err := c.Setup().Namespaces().Create(namespace) response, err := c.Setup(t).Namespaces().Create(namespace)
if err != nil { if err != nil {
t.Errorf("%#v should be nil.", err) t.Errorf("%#v should be nil.", err)
...@@ -59,13 +59,13 @@ func TestNamespaceGet(t *testing.T) { ...@@ -59,13 +59,13 @@ func TestNamespaceGet(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath("namespaces", "", "foo"), Path: testapi.Default.ResourcePath("namespaces", "", "foo"),
Body: nil, Body: nil,
}, },
Response: Response{StatusCode: 200, Body: namespace}, Response: Response{StatusCode: 200, Body: namespace},
} }
response, err := c.Setup().Namespaces().Get("foo") response, err := c.Setup(t).Namespaces().Get("foo")
if err != nil { if err != nil {
t.Errorf("%#v should be nil.", err) t.Errorf("%#v should be nil.", err)
...@@ -87,12 +87,12 @@ func TestNamespaceList(t *testing.T) { ...@@ -87,12 +87,12 @@ func TestNamespaceList(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath("namespaces", "", ""), Path: testapi.Default.ResourcePath("namespaces", "", ""),
Body: nil, Body: nil,
}, },
Response: Response{StatusCode: 200, Body: namespaceList}, Response: Response{StatusCode: 200, Body: namespaceList},
} }
response, err := c.Setup().Namespaces().List(labels.Everything(), fields.Everything()) response, err := c.Setup(t).Namespaces().List(labels.Everything(), fields.Everything())
if err != nil { if err != nil {
t.Errorf("%#v should be nil.", err) t.Errorf("%#v should be nil.", err)
...@@ -125,10 +125,10 @@ func TestNamespaceUpdate(t *testing.T) { ...@@ -125,10 +125,10 @@ func TestNamespaceUpdate(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "PUT", Method: "PUT",
Path: testapi.ResourcePath("namespaces", "", "foo")}, Path: testapi.Default.ResourcePath("namespaces", "", "foo")},
Response: Response{StatusCode: 200, Body: requestNamespace}, Response: Response{StatusCode: 200, Body: requestNamespace},
} }
receivedNamespace, err := c.Setup().Namespaces().Update(requestNamespace) receivedNamespace, err := c.Setup(t).Namespaces().Update(requestNamespace)
c.Validate(t, receivedNamespace, err) c.Validate(t, receivedNamespace, err)
} }
...@@ -149,20 +149,20 @@ func TestNamespaceFinalize(t *testing.T) { ...@@ -149,20 +149,20 @@ func TestNamespaceFinalize(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "PUT", Method: "PUT",
Path: testapi.ResourcePath("namespaces", "", "foo") + "/finalize", Path: testapi.Default.ResourcePath("namespaces", "", "foo") + "/finalize",
}, },
Response: Response{StatusCode: 200, Body: requestNamespace}, Response: Response{StatusCode: 200, Body: requestNamespace},
} }
receivedNamespace, err := c.Setup().Namespaces().Finalize(requestNamespace) receivedNamespace, err := c.Setup(t).Namespaces().Finalize(requestNamespace)
c.Validate(t, receivedNamespace, err) c.Validate(t, receivedNamespace, err)
} }
func TestNamespaceDelete(t *testing.T) { func TestNamespaceDelete(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.ResourcePath("namespaces", "", "foo")}, Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath("namespaces", "", "foo")},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
err := c.Setup().Namespaces().Delete("foo") err := c.Setup(t).Namespaces().Delete("foo")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -170,10 +170,10 @@ func TestNamespaceWatch(t *testing.T) { ...@@ -170,10 +170,10 @@ func TestNamespaceWatch(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePathWithPrefix("watch", "namespaces", "", ""), Path: testapi.Default.ResourcePathWithPrefix("watch", "namespaces", "", ""),
Query: url.Values{"resourceVersion": []string{}}}, Query: url.Values{"resourceVersion": []string{}}},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
_, err := c.Setup().Namespaces().Watch(labels.Everything(), fields.Everything(), "") _, err := c.Setup(t).Namespaces().Watch(labels.Everything(), fields.Everything(), "")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -35,20 +35,20 @@ func TestListMinions(t *testing.T) { ...@@ -35,20 +35,20 @@ func TestListMinions(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath(getNodesResourceName(), "", ""), Path: testapi.Default.ResourcePath(getNodesResourceName(), "", ""),
}, },
Response: Response{StatusCode: 200, Body: &api.NodeList{ListMeta: api.ListMeta{ResourceVersion: "1"}}}, Response: Response{StatusCode: 200, Body: &api.NodeList{ListMeta: api.ListMeta{ResourceVersion: "1"}}},
} }
response, err := c.Setup().Nodes().List(labels.Everything(), fields.Everything()) response, err := c.Setup(t).Nodes().List(labels.Everything(), fields.Everything())
c.Validate(t, response, err) c.Validate(t, response, err)
} }
func TestListMinionsLabels(t *testing.T) { func TestListMinionsLabels(t *testing.T) {
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Version()) labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Default.Version())
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath(getNodesResourceName(), "", ""), Path: testapi.Default.ResourcePath(getNodesResourceName(), "", ""),
Query: buildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})}, Query: buildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
Response: Response{ Response: Response{
StatusCode: 200, StatusCode: 200,
...@@ -66,7 +66,7 @@ func TestListMinionsLabels(t *testing.T) { ...@@ -66,7 +66,7 @@ func TestListMinionsLabels(t *testing.T) {
}, },
}, },
} }
c.Setup() c.Setup(t)
c.QueryValidator[labelSelectorQueryParamName] = validateLabels c.QueryValidator[labelSelectorQueryParamName] = validateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector() selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
receivedNodeList, err := c.Nodes().List(selector, fields.Everything()) receivedNodeList, err := c.Nodes().List(selector, fields.Everything())
...@@ -77,17 +77,17 @@ func TestGetMinion(t *testing.T) { ...@@ -77,17 +77,17 @@ func TestGetMinion(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath(getNodesResourceName(), "", "1"), Path: testapi.Default.ResourcePath(getNodesResourceName(), "", "1"),
}, },
Response: Response{StatusCode: 200, Body: &api.Node{ObjectMeta: api.ObjectMeta{Name: "minion-1"}}}, Response: Response{StatusCode: 200, Body: &api.Node{ObjectMeta: api.ObjectMeta{Name: "minion-1"}}},
} }
response, err := c.Setup().Nodes().Get("1") response, err := c.Setup(t).Nodes().Get("1")
c.Validate(t, response, err) c.Validate(t, response, err)
} }
func TestGetMinionWithNoName(t *testing.T) { func TestGetMinionWithNoName(t *testing.T) {
c := &testClient{Error: true} c := &testClient{Error: true}
receivedNode, err := c.Setup().Nodes().Get("") receivedNode, err := c.Setup(t).Nodes().Get("")
if (err != nil) && (err.Error() != nameRequiredError) { if (err != nil) && (err.Error() != nameRequiredError) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err) t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
} }
...@@ -113,14 +113,14 @@ func TestCreateMinion(t *testing.T) { ...@@ -113,14 +113,14 @@ func TestCreateMinion(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "POST", Method: "POST",
Path: testapi.ResourcePath(getNodesResourceName(), "", ""), Path: testapi.Default.ResourcePath(getNodesResourceName(), "", ""),
Body: requestMinion}, Body: requestMinion},
Response: Response{ Response: Response{
StatusCode: 200, StatusCode: 200,
Body: requestMinion, Body: requestMinion,
}, },
} }
receivedMinion, err := c.Setup().Nodes().Create(requestMinion) receivedMinion, err := c.Setup(t).Nodes().Create(requestMinion)
c.Validate(t, receivedMinion, err) c.Validate(t, receivedMinion, err)
} }
...@@ -128,11 +128,11 @@ func TestDeleteMinion(t *testing.T) { ...@@ -128,11 +128,11 @@ func TestDeleteMinion(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "DELETE", Method: "DELETE",
Path: testapi.ResourcePath(getNodesResourceName(), "", "foo"), Path: testapi.Default.ResourcePath(getNodesResourceName(), "", "foo"),
}, },
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
err := c.Setup().Nodes().Delete("foo") err := c.Setup(t).Nodes().Delete("foo")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -155,10 +155,10 @@ func TestUpdateMinion(t *testing.T) { ...@@ -155,10 +155,10 @@ func TestUpdateMinion(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "PUT", Method: "PUT",
Path: testapi.ResourcePath(getNodesResourceName(), "", "foo"), Path: testapi.Default.ResourcePath(getNodesResourceName(), "", "foo"),
}, },
Response: Response{StatusCode: 200, Body: requestMinion}, Response: Response{StatusCode: 200, Body: requestMinion},
} }
response, err := c.Setup().Nodes().Update(requestMinion) response, err := c.Setup(t).Nodes().Update(requestMinion)
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -49,14 +49,14 @@ func TestPersistentVolumeCreate(t *testing.T) { ...@@ -49,14 +49,14 @@ func TestPersistentVolumeCreate(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "POST", Method: "POST",
Path: testapi.ResourcePath(getPersistentVolumesResoureName(), "", ""), Path: testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", ""),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: pv, Body: pv,
}, },
Response: Response{StatusCode: 200, Body: pv}, Response: Response{StatusCode: 200, Body: pv},
} }
response, err := c.Setup().PersistentVolumes().Create(pv) response, err := c.Setup(t).PersistentVolumes().Create(pv)
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -78,14 +78,14 @@ func TestPersistentVolumeGet(t *testing.T) { ...@@ -78,14 +78,14 @@ func TestPersistentVolumeGet(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath(getPersistentVolumesResoureName(), "", "abc"), Path: testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", "abc"),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: nil, Body: nil,
}, },
Response: Response{StatusCode: 200, Body: persistentVolume}, Response: Response{StatusCode: 200, Body: persistentVolume},
} }
response, err := c.Setup().PersistentVolumes().Get("abc") response, err := c.Setup(t).PersistentVolumes().Get("abc")
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -100,13 +100,13 @@ func TestPersistentVolumeList(t *testing.T) { ...@@ -100,13 +100,13 @@ func TestPersistentVolumeList(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath(getPersistentVolumesResoureName(), "", ""), Path: testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", ""),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: nil, Body: nil,
}, },
Response: Response{StatusCode: 200, Body: persistentVolumeList}, Response: Response{StatusCode: 200, Body: persistentVolumeList},
} }
response, err := c.Setup().PersistentVolumes().List(labels.Everything(), fields.Everything()) response, err := c.Setup(t).PersistentVolumes().List(labels.Everything(), fields.Everything())
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -126,10 +126,10 @@ func TestPersistentVolumeUpdate(t *testing.T) { ...@@ -126,10 +126,10 @@ func TestPersistentVolumeUpdate(t *testing.T) {
}, },
} }
c := &testClient{ c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath(getPersistentVolumesResoureName(), "", "abc"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", "abc"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: persistentVolume}, Response: Response{StatusCode: 200, Body: persistentVolume},
} }
response, err := c.Setup().PersistentVolumes().Update(persistentVolume) response, err := c.Setup(t).PersistentVolumes().Update(persistentVolume)
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -155,20 +155,20 @@ func TestPersistentVolumeStatusUpdate(t *testing.T) { ...@@ -155,20 +155,20 @@ func TestPersistentVolumeStatusUpdate(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "PUT", Method: "PUT",
Path: testapi.ResourcePath(getPersistentVolumesResoureName(), "", "abc") + "/status", Path: testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", "abc") + "/status",
Query: buildQueryValues(nil)}, Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: persistentVolume}, Response: Response{StatusCode: 200, Body: persistentVolume},
} }
response, err := c.Setup().PersistentVolumes().UpdateStatus(persistentVolume) response, err := c.Setup(t).PersistentVolumes().UpdateStatus(persistentVolume)
c.Validate(t, response, err) c.Validate(t, response, err)
} }
func TestPersistentVolumeDelete(t *testing.T) { func TestPersistentVolumeDelete(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.ResourcePath(getPersistentVolumesResoureName(), "", "foo"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
err := c.Setup().PersistentVolumes().Delete("foo") err := c.Setup(t).PersistentVolumes().Delete("foo")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -176,10 +176,10 @@ func TestPersistentVolumeWatch(t *testing.T) { ...@@ -176,10 +176,10 @@ func TestPersistentVolumeWatch(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePathWithPrefix("watch", getPersistentVolumesResoureName(), "", ""), Path: testapi.Default.ResourcePathWithPrefix("watch", getPersistentVolumesResoureName(), "", ""),
Query: url.Values{"resourceVersion": []string{}}}, Query: url.Values{"resourceVersion": []string{}}},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
_, err := c.Setup().PersistentVolumes().Watch(labels.Everything(), fields.Everything(), "") _, err := c.Setup(t).PersistentVolumes().Watch(labels.Everything(), fields.Everything(), "")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -53,14 +53,14 @@ func TestPersistentVolumeClaimCreate(t *testing.T) { ...@@ -53,14 +53,14 @@ func TestPersistentVolumeClaimCreate(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "POST", Method: "POST",
Path: testapi.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, ""), Path: testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, ""),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: pv, Body: pv,
}, },
Response: Response{StatusCode: 200, Body: pv}, Response: Response{StatusCode: 200, Body: pv},
} }
response, err := c.Setup().PersistentVolumeClaims(ns).Create(pv) response, err := c.Setup(t).PersistentVolumeClaims(ns).Create(pv)
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -86,14 +86,14 @@ func TestPersistentVolumeClaimGet(t *testing.T) { ...@@ -86,14 +86,14 @@ func TestPersistentVolumeClaimGet(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "abc"), Path: testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "abc"),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: nil, Body: nil,
}, },
Response: Response{StatusCode: 200, Body: persistentVolumeClaim}, Response: Response{StatusCode: 200, Body: persistentVolumeClaim},
} }
response, err := c.Setup().PersistentVolumeClaims(ns).Get("abc") response, err := c.Setup(t).PersistentVolumeClaims(ns).Get("abc")
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -109,13 +109,13 @@ func TestPersistentVolumeClaimList(t *testing.T) { ...@@ -109,13 +109,13 @@ func TestPersistentVolumeClaimList(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, ""), Path: testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, ""),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: nil, Body: nil,
}, },
Response: Response{StatusCode: 200, Body: persistentVolumeList}, Response: Response{StatusCode: 200, Body: persistentVolumeList},
} }
response, err := c.Setup().PersistentVolumeClaims(ns).List(labels.Everything(), fields.Everything()) response, err := c.Setup(t).PersistentVolumeClaims(ns).List(labels.Everything(), fields.Everything())
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -139,10 +139,10 @@ func TestPersistentVolumeClaimUpdate(t *testing.T) { ...@@ -139,10 +139,10 @@ func TestPersistentVolumeClaimUpdate(t *testing.T) {
}, },
} }
c := &testClient{ c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "abc"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "abc"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: persistentVolumeClaim}, Response: Response{StatusCode: 200, Body: persistentVolumeClaim},
} }
response, err := c.Setup().PersistentVolumeClaims(ns).Update(persistentVolumeClaim) response, err := c.Setup(t).PersistentVolumeClaims(ns).Update(persistentVolumeClaim)
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -171,21 +171,21 @@ func TestPersistentVolumeClaimStatusUpdate(t *testing.T) { ...@@ -171,21 +171,21 @@ func TestPersistentVolumeClaimStatusUpdate(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "PUT", Method: "PUT",
Path: testapi.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "abc") + "/status", Path: testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "abc") + "/status",
Query: buildQueryValues(nil)}, Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: persistentVolumeClaim}, Response: Response{StatusCode: 200, Body: persistentVolumeClaim},
} }
response, err := c.Setup().PersistentVolumeClaims(ns).UpdateStatus(persistentVolumeClaim) response, err := c.Setup(t).PersistentVolumeClaims(ns).UpdateStatus(persistentVolumeClaim)
c.Validate(t, response, err) c.Validate(t, response, err)
} }
func TestPersistentVolumeClaimDelete(t *testing.T) { func TestPersistentVolumeClaimDelete(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{ c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "foo"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
err := c.Setup().PersistentVolumeClaims(ns).Delete("foo") err := c.Setup(t).PersistentVolumeClaims(ns).Delete("foo")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -193,10 +193,10 @@ func TestPersistentVolumeClaimWatch(t *testing.T) { ...@@ -193,10 +193,10 @@ func TestPersistentVolumeClaimWatch(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePathWithPrefix("watch", getPersistentVolumeClaimsResoureName(), "", ""), Path: testapi.Default.ResourcePathWithPrefix("watch", getPersistentVolumeClaimsResoureName(), "", ""),
Query: url.Values{"resourceVersion": []string{}}}, Query: url.Values{"resourceVersion": []string{}}},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
_, err := c.Setup().PersistentVolumeClaims(api.NamespaceAll).Watch(labels.Everything(), fields.Everything(), "") _, err := c.Setup(t).PersistentVolumeClaims(api.NamespaceAll).Watch(labels.Everything(), fields.Everything(), "")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -42,14 +42,14 @@ func TestPodTemplateCreate(t *testing.T) { ...@@ -42,14 +42,14 @@ func TestPodTemplateCreate(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "POST", Method: "POST",
Path: testapi.ResourcePath(getPodTemplatesResoureName(), ns, ""), Path: testapi.Default.ResourcePath(getPodTemplatesResoureName(), ns, ""),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: &podTemplate, Body: &podTemplate,
}, },
Response: Response{StatusCode: 200, Body: &podTemplate}, Response: Response{StatusCode: 200, Body: &podTemplate},
} }
response, err := c.Setup().PodTemplates(ns).Create(&podTemplate) response, err := c.Setup(t).PodTemplates(ns).Create(&podTemplate)
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -65,14 +65,14 @@ func TestPodTemplateGet(t *testing.T) { ...@@ -65,14 +65,14 @@ func TestPodTemplateGet(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath(getPodTemplatesResoureName(), ns, "abc"), Path: testapi.Default.ResourcePath(getPodTemplatesResoureName(), ns, "abc"),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: nil, Body: nil,
}, },
Response: Response{StatusCode: 200, Body: podTemplate}, Response: Response{StatusCode: 200, Body: podTemplate},
} }
response, err := c.Setup().PodTemplates(ns).Get("abc") response, err := c.Setup(t).PodTemplates(ns).Get("abc")
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -91,13 +91,13 @@ func TestPodTemplateList(t *testing.T) { ...@@ -91,13 +91,13 @@ func TestPodTemplateList(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath(getPodTemplatesResoureName(), ns, ""), Path: testapi.Default.ResourcePath(getPodTemplatesResoureName(), ns, ""),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: nil, Body: nil,
}, },
Response: Response{StatusCode: 200, Body: podTemplateList}, Response: Response{StatusCode: 200, Body: podTemplateList},
} }
response, err := c.Setup().PodTemplates(ns).List(labels.Everything(), fields.Everything()) response, err := c.Setup(t).PodTemplates(ns).List(labels.Everything(), fields.Everything())
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -112,20 +112,20 @@ func TestPodTemplateUpdate(t *testing.T) { ...@@ -112,20 +112,20 @@ func TestPodTemplateUpdate(t *testing.T) {
Template: api.PodTemplateSpec{}, Template: api.PodTemplateSpec{},
} }
c := &testClient{ c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath(getPodTemplatesResoureName(), ns, "abc"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath(getPodTemplatesResoureName(), ns, "abc"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: podTemplate}, Response: Response{StatusCode: 200, Body: podTemplate},
} }
response, err := c.Setup().PodTemplates(ns).Update(podTemplate) response, err := c.Setup(t).PodTemplates(ns).Update(podTemplate)
c.Validate(t, response, err) c.Validate(t, response, err)
} }
func TestPodTemplateDelete(t *testing.T) { func TestPodTemplateDelete(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{ c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.ResourcePath(getPodTemplatesResoureName(), ns, "foo"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath(getPodTemplatesResoureName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
err := c.Setup().PodTemplates(ns).Delete("foo", nil) err := c.Setup(t).PodTemplates(ns).Delete("foo", nil)
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -133,10 +133,10 @@ func TestPodTemplateWatch(t *testing.T) { ...@@ -133,10 +133,10 @@ func TestPodTemplateWatch(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePathWithPrefix("watch", getPodTemplatesResoureName(), "", ""), Path: testapi.Default.ResourcePathWithPrefix("watch", getPodTemplatesResoureName(), "", ""),
Query: url.Values{"resourceVersion": []string{}}}, Query: url.Values{"resourceVersion": []string{}}},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
_, err := c.Setup().PodTemplates(api.NamespaceAll).Watch(labels.Everything(), fields.Everything(), "") _, err := c.Setup(t).PodTemplates(api.NamespaceAll).Watch(labels.Everything(), fields.Everything(), "")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -29,17 +29,17 @@ import ( ...@@ -29,17 +29,17 @@ import (
func TestListEmptyPods(t *testing.T) { func TestListEmptyPods(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{ c := &testClient{
Request: testRequest{Method: "GET", Path: testapi.ResourcePath("pods", ns, ""), Query: buildQueryValues(nil)}, Request: testRequest{Method: "GET", Path: testapi.Default.ResourcePath("pods", ns, ""), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: &api.PodList{}}, Response: Response{StatusCode: 200, Body: &api.PodList{}},
} }
podList, err := c.Setup().Pods(ns).List(labels.Everything(), fields.Everything()) podList, err := c.Setup(t).Pods(ns).List(labels.Everything(), fields.Everything())
c.Validate(t, podList, err) c.Validate(t, podList, err)
} }
func TestListPods(t *testing.T) { func TestListPods(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{ c := &testClient{
Request: testRequest{Method: "GET", Path: testapi.ResourcePath("pods", ns, ""), Query: buildQueryValues(nil)}, Request: testRequest{Method: "GET", Path: testapi.Default.ResourcePath("pods", ns, ""), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Response: Response{StatusCode: 200,
Body: &api.PodList{ Body: &api.PodList{
Items: []api.Pod{ Items: []api.Pod{
...@@ -58,17 +58,17 @@ func TestListPods(t *testing.T) { ...@@ -58,17 +58,17 @@ func TestListPods(t *testing.T) {
}, },
}, },
} }
receivedPodList, err := c.Setup().Pods(ns).List(labels.Everything(), fields.Everything()) receivedPodList, err := c.Setup(t).Pods(ns).List(labels.Everything(), fields.Everything())
c.Validate(t, receivedPodList, err) c.Validate(t, receivedPodList, err)
} }
func TestListPodsLabels(t *testing.T) { func TestListPodsLabels(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Version()) labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Default.Version())
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath("pods", ns, ""), Path: testapi.Default.ResourcePath("pods", ns, ""),
Query: buildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})}, Query: buildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
Response: Response{ Response: Response{
StatusCode: 200, StatusCode: 200,
...@@ -89,7 +89,7 @@ func TestListPodsLabels(t *testing.T) { ...@@ -89,7 +89,7 @@ func TestListPodsLabels(t *testing.T) {
}, },
}, },
} }
c.Setup() c.Setup(t)
c.QueryValidator[labelSelectorQueryParamName] = validateLabels c.QueryValidator[labelSelectorQueryParamName] = validateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector() selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
receivedPodList, err := c.Pods(ns).List(selector, fields.Everything()) receivedPodList, err := c.Pods(ns).List(selector, fields.Everything())
...@@ -99,7 +99,7 @@ func TestListPodsLabels(t *testing.T) { ...@@ -99,7 +99,7 @@ func TestListPodsLabels(t *testing.T) {
func TestGetPod(t *testing.T) { func TestGetPod(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{ c := &testClient{
Request: testRequest{Method: "GET", Path: testapi.ResourcePath("pods", ns, "foo"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "GET", Path: testapi.Default.ResourcePath("pods", ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{ Response: Response{
StatusCode: 200, StatusCode: 200,
Body: &api.Pod{ Body: &api.Pod{
...@@ -115,14 +115,14 @@ func TestGetPod(t *testing.T) { ...@@ -115,14 +115,14 @@ func TestGetPod(t *testing.T) {
}, },
}, },
} }
receivedPod, err := c.Setup().Pods(ns).Get("foo") receivedPod, err := c.Setup(t).Pods(ns).Get("foo")
c.Validate(t, receivedPod, err) c.Validate(t, receivedPod, err)
} }
func TestGetPodWithNoName(t *testing.T) { func TestGetPodWithNoName(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{Error: true} c := &testClient{Error: true}
receivedPod, err := c.Setup().Pods(ns).Get("") receivedPod, err := c.Setup(t).Pods(ns).Get("")
if (err != nil) && (err.Error() != nameRequiredError) { if (err != nil) && (err.Error() != nameRequiredError) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err) t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
} }
...@@ -133,10 +133,10 @@ func TestGetPodWithNoName(t *testing.T) { ...@@ -133,10 +133,10 @@ func TestGetPodWithNoName(t *testing.T) {
func TestDeletePod(t *testing.T) { func TestDeletePod(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{ c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.ResourcePath("pods", ns, "foo"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath("pods", ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
err := c.Setup().Pods(ns).Delete("foo", nil) err := c.Setup(t).Pods(ns).Delete("foo", nil)
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -154,13 +154,13 @@ func TestCreatePod(t *testing.T) { ...@@ -154,13 +154,13 @@ func TestCreatePod(t *testing.T) {
}, },
} }
c := &testClient{ c := &testClient{
Request: testRequest{Method: "POST", Path: testapi.ResourcePath("pods", ns, ""), Query: buildQueryValues(nil), Body: requestPod}, Request: testRequest{Method: "POST", Path: testapi.Default.ResourcePath("pods", ns, ""), Query: buildQueryValues(nil), Body: requestPod},
Response: Response{ Response: Response{
StatusCode: 200, StatusCode: 200,
Body: requestPod, Body: requestPod,
}, },
} }
receivedPod, err := c.Setup().Pods(ns).Create(requestPod) receivedPod, err := c.Setup(t).Pods(ns).Create(requestPod)
c.Validate(t, receivedPod, err) c.Validate(t, receivedPod, err)
} }
...@@ -180,9 +180,9 @@ func TestUpdatePod(t *testing.T) { ...@@ -180,9 +180,9 @@ func TestUpdatePod(t *testing.T) {
}, },
} }
c := &testClient{ c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath("pods", ns, "foo"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath("pods", ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: requestPod}, Response: Response{StatusCode: 200, Body: requestPod},
} }
receivedPod, err := c.Setup().Pods(ns).Update(requestPod) receivedPod, err := c.Setup(t).Pods(ns).Update(requestPod)
c.Validate(t, receivedPod, err) c.Validate(t, receivedPod, err)
} }
...@@ -33,7 +33,7 @@ func TestListControllers(t *testing.T) { ...@@ -33,7 +33,7 @@ func TestListControllers(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath(getRCResourceName(), ns, ""), Path: testapi.Default.ResourcePath(getRCResourceName(), ns, ""),
}, },
Response: Response{StatusCode: 200, Response: Response{StatusCode: 200,
Body: &api.ReplicationControllerList{ Body: &api.ReplicationControllerList{
...@@ -55,7 +55,7 @@ func TestListControllers(t *testing.T) { ...@@ -55,7 +55,7 @@ func TestListControllers(t *testing.T) {
}, },
}, },
} }
receivedControllerList, err := c.Setup().ReplicationControllers(ns).List(labels.Everything()) receivedControllerList, err := c.Setup(t).ReplicationControllers(ns).List(labels.Everything())
c.Validate(t, receivedControllerList, err) c.Validate(t, receivedControllerList, err)
} }
...@@ -63,7 +63,7 @@ func TestListControllers(t *testing.T) { ...@@ -63,7 +63,7 @@ func TestListControllers(t *testing.T) {
func TestGetController(t *testing.T) { func TestGetController(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{ c := &testClient{
Request: testRequest{Method: "GET", Path: testapi.ResourcePath(getRCResourceName(), ns, "foo"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "GET", Path: testapi.Default.ResourcePath(getRCResourceName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{ Response: Response{
StatusCode: 200, StatusCode: 200,
Body: &api.ReplicationController{ Body: &api.ReplicationController{
...@@ -81,14 +81,14 @@ func TestGetController(t *testing.T) { ...@@ -81,14 +81,14 @@ func TestGetController(t *testing.T) {
}, },
}, },
} }
receivedController, err := c.Setup().ReplicationControllers(ns).Get("foo") receivedController, err := c.Setup(t).ReplicationControllers(ns).Get("foo")
c.Validate(t, receivedController, err) c.Validate(t, receivedController, err)
} }
func TestGetControllerWithNoName(t *testing.T) { func TestGetControllerWithNoName(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{Error: true} c := &testClient{Error: true}
receivedPod, err := c.Setup().ReplicationControllers(ns).Get("") receivedPod, err := c.Setup(t).ReplicationControllers(ns).Get("")
if (err != nil) && (err.Error() != nameRequiredError) { if (err != nil) && (err.Error() != nameRequiredError) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err) t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
} }
...@@ -102,7 +102,7 @@ func TestUpdateController(t *testing.T) { ...@@ -102,7 +102,7 @@ func TestUpdateController(t *testing.T) {
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"}, ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"},
} }
c := &testClient{ c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath(getRCResourceName(), ns, "foo"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath(getRCResourceName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{ Response: Response{
StatusCode: 200, StatusCode: 200,
Body: &api.ReplicationController{ Body: &api.ReplicationController{
...@@ -120,17 +120,17 @@ func TestUpdateController(t *testing.T) { ...@@ -120,17 +120,17 @@ func TestUpdateController(t *testing.T) {
}, },
}, },
} }
receivedController, err := c.Setup().ReplicationControllers(ns).Update(requestController) receivedController, err := c.Setup(t).ReplicationControllers(ns).Update(requestController)
c.Validate(t, receivedController, err) c.Validate(t, receivedController, err)
} }
func TestDeleteController(t *testing.T) { func TestDeleteController(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{ c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.ResourcePath(getRCResourceName(), ns, "foo"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath(getRCResourceName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
err := c.Setup().ReplicationControllers(ns).Delete("foo") err := c.Setup(t).ReplicationControllers(ns).Delete("foo")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -140,7 +140,7 @@ func TestCreateController(t *testing.T) { ...@@ -140,7 +140,7 @@ func TestCreateController(t *testing.T) {
ObjectMeta: api.ObjectMeta{Name: "foo"}, ObjectMeta: api.ObjectMeta{Name: "foo"},
} }
c := &testClient{ c := &testClient{
Request: testRequest{Method: "POST", Path: testapi.ResourcePath(getRCResourceName(), ns, ""), Body: requestController, Query: buildQueryValues(nil)}, Request: testRequest{Method: "POST", Path: testapi.Default.ResourcePath(getRCResourceName(), ns, ""), Body: requestController, Query: buildQueryValues(nil)},
Response: Response{ Response: Response{
StatusCode: 200, StatusCode: 200,
Body: &api.ReplicationController{ Body: &api.ReplicationController{
...@@ -158,6 +158,6 @@ func TestCreateController(t *testing.T) { ...@@ -158,6 +158,6 @@ func TestCreateController(t *testing.T) {
}, },
}, },
} }
receivedController, err := c.Setup().ReplicationControllers(ns).Create(requestController) receivedController, err := c.Setup(t).ReplicationControllers(ns).Create(requestController)
c.Validate(t, receivedController, err) c.Validate(t, receivedController, err)
} }
...@@ -52,14 +52,14 @@ func TestResourceQuotaCreate(t *testing.T) { ...@@ -52,14 +52,14 @@ func TestResourceQuotaCreate(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "POST", Method: "POST",
Path: testapi.ResourcePath(getResourceQuotasResoureName(), ns, ""), Path: testapi.Default.ResourcePath(getResourceQuotasResoureName(), ns, ""),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: resourceQuota, Body: resourceQuota,
}, },
Response: Response{StatusCode: 200, Body: resourceQuota}, Response: Response{StatusCode: 200, Body: resourceQuota},
} }
response, err := c.Setup().ResourceQuotas(ns).Create(resourceQuota) response, err := c.Setup(t).ResourceQuotas(ns).Create(resourceQuota)
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -84,14 +84,14 @@ func TestResourceQuotaGet(t *testing.T) { ...@@ -84,14 +84,14 @@ func TestResourceQuotaGet(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath(getResourceQuotasResoureName(), ns, "abc"), Path: testapi.Default.ResourcePath(getResourceQuotasResoureName(), ns, "abc"),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: nil, Body: nil,
}, },
Response: Response{StatusCode: 200, Body: resourceQuota}, Response: Response{StatusCode: 200, Body: resourceQuota},
} }
response, err := c.Setup().ResourceQuotas(ns).Get("abc") response, err := c.Setup(t).ResourceQuotas(ns).Get("abc")
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -108,13 +108,13 @@ func TestResourceQuotaList(t *testing.T) { ...@@ -108,13 +108,13 @@ func TestResourceQuotaList(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath(getResourceQuotasResoureName(), ns, ""), Path: testapi.Default.ResourcePath(getResourceQuotasResoureName(), ns, ""),
Query: buildQueryValues(nil), Query: buildQueryValues(nil),
Body: nil, Body: nil,
}, },
Response: Response{StatusCode: 200, Body: resourceQuotaList}, Response: Response{StatusCode: 200, Body: resourceQuotaList},
} }
response, err := c.Setup().ResourceQuotas(ns).List(labels.Everything()) response, err := c.Setup(t).ResourceQuotas(ns).List(labels.Everything())
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -138,10 +138,10 @@ func TestResourceQuotaUpdate(t *testing.T) { ...@@ -138,10 +138,10 @@ func TestResourceQuotaUpdate(t *testing.T) {
}, },
} }
c := &testClient{ c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath(getResourceQuotasResoureName(), ns, "abc"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath(getResourceQuotasResoureName(), ns, "abc"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: resourceQuota}, Response: Response{StatusCode: 200, Body: resourceQuota},
} }
response, err := c.Setup().ResourceQuotas(ns).Update(resourceQuota) response, err := c.Setup(t).ResourceQuotas(ns).Update(resourceQuota)
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -167,21 +167,21 @@ func TestResourceQuotaStatusUpdate(t *testing.T) { ...@@ -167,21 +167,21 @@ func TestResourceQuotaStatusUpdate(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "PUT", Method: "PUT",
Path: testapi.ResourcePath(getResourceQuotasResoureName(), ns, "abc") + "/status", Path: testapi.Default.ResourcePath(getResourceQuotasResoureName(), ns, "abc") + "/status",
Query: buildQueryValues(nil)}, Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: resourceQuota}, Response: Response{StatusCode: 200, Body: resourceQuota},
} }
response, err := c.Setup().ResourceQuotas(ns).UpdateStatus(resourceQuota) response, err := c.Setup(t).ResourceQuotas(ns).UpdateStatus(resourceQuota)
c.Validate(t, response, err) c.Validate(t, response, err)
} }
func TestResourceQuotaDelete(t *testing.T) { func TestResourceQuotaDelete(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{ c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.ResourcePath(getResourceQuotasResoureName(), ns, "foo"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath(getResourceQuotasResoureName(), ns, "foo"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
err := c.Setup().ResourceQuotas(ns).Delete("foo") err := c.Setup(t).ResourceQuotas(ns).Delete("foo")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -189,10 +189,10 @@ func TestResourceQuotaWatch(t *testing.T) { ...@@ -189,10 +189,10 @@ func TestResourceQuotaWatch(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePathWithPrefix("watch", getResourceQuotasResoureName(), "", ""), Path: testapi.Default.ResourcePathWithPrefix("watch", getResourceQuotasResoureName(), "", ""),
Query: url.Values{"resourceVersion": []string{}}}, Query: url.Values{"resourceVersion": []string{}}},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
_, err := c.Setup().ResourceQuotas(api.NamespaceAll).Watch(labels.Everything(), fields.Everything(), "") _, err := c.Setup(t).ResourceQuotas(api.NamespaceAll).Watch(labels.Everything(), fields.Everything(), "")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -35,8 +35,8 @@ func TestSetsCodec(t *testing.T) { ...@@ -35,8 +35,8 @@ func TestSetsCodec(t *testing.T) {
Prefix string Prefix string
Codec runtime.Codec Codec runtime.Codec
}{ }{
testapi.Version(): {false, "/api/" + testapi.Version() + "/", testapi.Codec()}, testapi.Default.Version(): {false, "/api/" + testapi.Default.Version() + "/", testapi.Default.Codec()},
"invalidVersion": {true, "", nil}, "invalidVersion": {true, "", nil},
} }
for version, expected := range testCases { for version, expected := range testCases {
client, err := New(&Config{Host: "127.0.0.1", Version: version}) client, err := New(&Config{Host: "127.0.0.1", Version: version})
...@@ -60,13 +60,13 @@ func TestSetsCodec(t *testing.T) { ...@@ -60,13 +60,13 @@ func TestSetsCodec(t *testing.T) {
} }
func TestRESTClientRequires(t *testing.T) { func TestRESTClientRequires(t *testing.T) {
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", Version: "", Codec: testapi.Codec()}); err == nil { if _, err := RESTClientFor(&Config{Host: "127.0.0.1", Version: "", Codec: testapi.Default.Codec()}); err == nil {
t.Errorf("unexpected non-error") t.Errorf("unexpected non-error")
} }
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", Version: testapi.Version()}); err == nil { if _, err := RESTClientFor(&Config{Host: "127.0.0.1", Version: testapi.Default.Version()}); err == nil {
t.Errorf("unexpected non-error") t.Errorf("unexpected non-error")
} }
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", Version: testapi.Version(), Codec: testapi.Codec()}); err != nil { if _, err := RESTClientFor(&Config{Host: "127.0.0.1", Version: testapi.Default.Version(), Codec: testapi.Default.Codec()}); err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
} }
...@@ -79,17 +79,17 @@ func TestValidatesHostParameter(t *testing.T) { ...@@ -79,17 +79,17 @@ func TestValidatesHostParameter(t *testing.T) {
URL string URL string
Err bool Err bool
}{ }{
{"127.0.0.1", "", "http://127.0.0.1/" + testapi.Version() + "/", false}, {"127.0.0.1", "", "http://127.0.0.1/" + testapi.Default.Version() + "/", false},
{"127.0.0.1:8080", "", "http://127.0.0.1:8080/" + testapi.Version() + "/", false}, {"127.0.0.1:8080", "", "http://127.0.0.1:8080/" + testapi.Default.Version() + "/", false},
{"foo.bar.com", "", "http://foo.bar.com/" + testapi.Version() + "/", false}, {"foo.bar.com", "", "http://foo.bar.com/" + testapi.Default.Version() + "/", false},
{"http://host/prefix", "", "http://host/prefix/" + testapi.Version() + "/", false}, {"http://host/prefix", "", "http://host/prefix/" + testapi.Default.Version() + "/", false},
{"http://host", "", "http://host/" + testapi.Version() + "/", false}, {"http://host", "", "http://host/" + testapi.Default.Version() + "/", false},
{"http://host", "/", "http://host/" + testapi.Version() + "/", false}, {"http://host", "/", "http://host/" + testapi.Default.Version() + "/", false},
{"http://host", "/other", "http://host/other/" + testapi.Version() + "/", false}, {"http://host", "/other", "http://host/other/" + testapi.Default.Version() + "/", false},
{"host/server", "", "", true}, {"host/server", "", "", true},
} }
for i, testCase := range testCases { for i, testCase := range testCases {
c, err := RESTClientFor(&Config{Host: testCase.Host, Prefix: testCase.Prefix, Version: testapi.Version(), Codec: testapi.Codec()}) c, err := RESTClientFor(&Config{Host: testCase.Host, Prefix: testCase.Prefix, Version: testapi.Default.Version(), Codec: testapi.Default.Codec()})
switch { switch {
case err == nil && testCase.Err: case err == nil && testCase.Err:
t.Errorf("expected error but was nil") t.Errorf("expected error but was nil")
...@@ -120,8 +120,8 @@ func TestDoRequestBearer(t *testing.T) { ...@@ -120,8 +120,8 @@ func TestDoRequestBearer(t *testing.T) {
request, _ := http.NewRequest("GET", testServer.URL, nil) request, _ := http.NewRequest("GET", testServer.URL, nil)
c, err := RESTClientFor(&Config{ c, err := RESTClientFor(&Config{
Host: testServer.URL, Host: testServer.URL,
Version: testapi.Version(), Version: testapi.Default.Version(),
Codec: testapi.Codec(), Codec: testapi.Default.Codec(),
BearerToken: "test", BearerToken: "test",
}) })
if err != nil { if err != nil {
...@@ -148,8 +148,8 @@ func TestDoRequestWithoutPassword(t *testing.T) { ...@@ -148,8 +148,8 @@ func TestDoRequestWithoutPassword(t *testing.T) {
defer testServer.Close() defer testServer.Close()
c, err := RESTClientFor(&Config{ c, err := RESTClientFor(&Config{
Host: testServer.URL, Host: testServer.URL,
Version: testapi.Version(), Version: testapi.Default.Version(),
Codec: testapi.Codec(), Codec: testapi.Default.Codec(),
Username: "test", Username: "test",
}) })
if err != nil { if err != nil {
...@@ -172,7 +172,7 @@ func TestDoRequestWithoutPassword(t *testing.T) { ...@@ -172,7 +172,7 @@ func TestDoRequestWithoutPassword(t *testing.T) {
if body != nil { if body != nil {
t.Errorf("Expected nil body, but saw: '%s'", string(body)) t.Errorf("Expected nil body, but saw: '%s'", string(body))
} }
fakeHandler.ValidateRequest(t, "/"+testapi.Version()+"/test", "GET", nil) fakeHandler.ValidateRequest(t, "/"+testapi.Default.Version()+"/test", "GET", nil)
} }
func TestDoRequestSuccess(t *testing.T) { func TestDoRequestSuccess(t *testing.T) {
...@@ -187,8 +187,8 @@ func TestDoRequestSuccess(t *testing.T) { ...@@ -187,8 +187,8 @@ func TestDoRequestSuccess(t *testing.T) {
defer testServer.Close() defer testServer.Close()
c, err := RESTClientFor(&Config{ c, err := RESTClientFor(&Config{
Host: testServer.URL, Host: testServer.URL,
Version: testapi.Version(), Version: testapi.Default.Version(),
Codec: testapi.Codec(), Codec: testapi.Default.Codec(),
Username: "user", Username: "user",
Password: "pass", Password: "pass",
}) })
...@@ -209,7 +209,7 @@ func TestDoRequestSuccess(t *testing.T) { ...@@ -209,7 +209,7 @@ func TestDoRequestSuccess(t *testing.T) {
if !reflect.DeepEqual(status, statusOut) { if !reflect.DeepEqual(status, statusOut) {
t.Errorf("Unexpected mis-match. Expected %#v. Saw %#v", status, statusOut) t.Errorf("Unexpected mis-match. Expected %#v. Saw %#v", status, statusOut)
} }
fakeHandler.ValidateRequest(t, "/"+testapi.Version()+"/test", "GET", nil) fakeHandler.ValidateRequest(t, "/"+testapi.Default.Version()+"/test", "GET", nil)
} }
func TestDoRequestFailed(t *testing.T) { func TestDoRequestFailed(t *testing.T) {
...@@ -230,8 +230,8 @@ func TestDoRequestFailed(t *testing.T) { ...@@ -230,8 +230,8 @@ func TestDoRequestFailed(t *testing.T) {
defer testServer.Close() defer testServer.Close()
c, err := RESTClientFor(&Config{ c, err := RESTClientFor(&Config{
Host: testServer.URL, Host: testServer.URL,
Version: testapi.Version(), Version: testapi.Default.Version(),
Codec: testapi.Codec(), Codec: testapi.Default.Codec(),
}) })
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
...@@ -262,8 +262,8 @@ func TestDoRequestCreated(t *testing.T) { ...@@ -262,8 +262,8 @@ func TestDoRequestCreated(t *testing.T) {
defer testServer.Close() defer testServer.Close()
c, err := RESTClientFor(&Config{ c, err := RESTClientFor(&Config{
Host: testServer.URL, Host: testServer.URL,
Version: testapi.Version(), Version: testapi.Default.Version(),
Codec: testapi.Codec(), Codec: testapi.Default.Codec(),
Username: "user", Username: "user",
Password: "pass", Password: "pass",
}) })
...@@ -285,5 +285,5 @@ func TestDoRequestCreated(t *testing.T) { ...@@ -285,5 +285,5 @@ func TestDoRequestCreated(t *testing.T) {
if !reflect.DeepEqual(status, statusOut) { if !reflect.DeepEqual(status, statusOut) {
t.Errorf("Unexpected mis-match. Expected %#v. Saw %#v", status, statusOut) t.Errorf("Unexpected mis-match. Expected %#v. Saw %#v", status, statusOut)
} }
fakeHandler.ValidateRequest(t, "/"+testapi.Version()+"/test", "GET", nil) fakeHandler.ValidateRequest(t, "/"+testapi.Default.Version()+"/test", "GET", nil)
} }
...@@ -30,7 +30,7 @@ func TestListServices(t *testing.T) { ...@@ -30,7 +30,7 @@ func TestListServices(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath("services", ns, ""), Path: testapi.Default.ResourcePath("services", ns, ""),
Query: buildQueryValues(nil)}, Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Response: Response{StatusCode: 200,
Body: &api.ServiceList{ Body: &api.ServiceList{
...@@ -53,18 +53,18 @@ func TestListServices(t *testing.T) { ...@@ -53,18 +53,18 @@ func TestListServices(t *testing.T) {
}, },
}, },
} }
receivedServiceList, err := c.Setup().Services(ns).List(labels.Everything()) receivedServiceList, err := c.Setup(t).Services(ns).List(labels.Everything())
t.Logf("received services: %v %#v", err, receivedServiceList) t.Logf("received services: %v %#v", err, receivedServiceList)
c.Validate(t, receivedServiceList, err) c.Validate(t, receivedServiceList, err)
} }
func TestListServicesLabels(t *testing.T) { func TestListServicesLabels(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Version()) labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Default.Version())
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath("services", ns, ""), Path: testapi.Default.ResourcePath("services", ns, ""),
Query: buildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})}, Query: buildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
Response: Response{StatusCode: 200, Response: Response{StatusCode: 200,
Body: &api.ServiceList{ Body: &api.ServiceList{
...@@ -87,7 +87,7 @@ func TestListServicesLabels(t *testing.T) { ...@@ -87,7 +87,7 @@ func TestListServicesLabels(t *testing.T) {
}, },
}, },
} }
c.Setup() c.Setup(t)
c.QueryValidator[labelSelectorQueryParamName] = validateLabels c.QueryValidator[labelSelectorQueryParamName] = validateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector() selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
receivedServiceList, err := c.Services(ns).List(selector) receivedServiceList, err := c.Services(ns).List(selector)
...@@ -99,18 +99,18 @@ func TestGetService(t *testing.T) { ...@@ -99,18 +99,18 @@ func TestGetService(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePath("services", ns, "1"), Path: testapi.Default.ResourcePath("services", ns, "1"),
Query: buildQueryValues(nil)}, Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}}, Response: Response{StatusCode: 200, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
} }
response, err := c.Setup().Services(ns).Get("1") response, err := c.Setup(t).Services(ns).Get("1")
c.Validate(t, response, err) c.Validate(t, response, err)
} }
func TestGetServiceWithNoName(t *testing.T) { func TestGetServiceWithNoName(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{Error: true} c := &testClient{Error: true}
receivedPod, err := c.Setup().Services(ns).Get("") receivedPod, err := c.Setup(t).Services(ns).Get("")
if (err != nil) && (err.Error() != nameRequiredError) { if (err != nil) && (err.Error() != nameRequiredError) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err) t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
} }
...@@ -123,12 +123,12 @@ func TestCreateService(t *testing.T) { ...@@ -123,12 +123,12 @@ func TestCreateService(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "POST", Method: "POST",
Path: testapi.ResourcePath("services", ns, ""), Path: testapi.Default.ResourcePath("services", ns, ""),
Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}},
Query: buildQueryValues(nil)}, Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}}, Response: Response{StatusCode: 200, Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}},
} }
response, err := c.Setup().Services(ns).Create(&api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}}) response, err := c.Setup(t).Services(ns).Create(&api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}})
c.Validate(t, response, err) c.Validate(t, response, err)
} }
...@@ -136,20 +136,20 @@ func TestUpdateService(t *testing.T) { ...@@ -136,20 +136,20 @@ func TestUpdateService(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
svc := &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1", ResourceVersion: "1"}} svc := &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1", ResourceVersion: "1"}}
c := &testClient{ c := &testClient{
Request: testRequest{Method: "PUT", Path: testapi.ResourcePath("services", ns, "service-1"), Body: svc, Query: buildQueryValues(nil)}, Request: testRequest{Method: "PUT", Path: testapi.Default.ResourcePath("services", ns, "service-1"), Body: svc, Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200, Body: svc}, Response: Response{StatusCode: 200, Body: svc},
} }
response, err := c.Setup().Services(ns).Update(svc) response, err := c.Setup(t).Services(ns).Update(svc)
c.Validate(t, response, err) c.Validate(t, response, err)
} }
func TestDeleteService(t *testing.T) { func TestDeleteService(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
c := &testClient{ c := &testClient{
Request: testRequest{Method: "DELETE", Path: testapi.ResourcePath("services", ns, "1"), Query: buildQueryValues(nil)}, Request: testRequest{Method: "DELETE", Path: testapi.Default.ResourcePath("services", ns, "1"), Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200}, Response: Response{StatusCode: 200},
} }
err := c.Setup().Services(ns).Delete("1") err := c.Setup(t).Services(ns).Delete("1")
c.Validate(t, nil, err) c.Validate(t, nil, err)
} }
...@@ -159,11 +159,11 @@ func TestServiceProxyGet(t *testing.T) { ...@@ -159,11 +159,11 @@ func TestServiceProxyGet(t *testing.T) {
c := &testClient{ c := &testClient{
Request: testRequest{ Request: testRequest{
Method: "GET", Method: "GET",
Path: testapi.ResourcePathWithPrefix("proxy", "services", ns, "service-1") + "/foo", Path: testapi.Default.ResourcePathWithPrefix("proxy", "services", ns, "service-1") + "/foo",
Query: buildQueryValues(url.Values{"param-name": []string{"param-value"}}), Query: buildQueryValues(url.Values{"param-name": []string{"param-value"}}),
}, },
Response: Response{StatusCode: 200, RawBody: &body}, Response: Response{StatusCode: 200, RawBody: &body},
} }
response, err := c.Setup().Services(ns).ProxyGet("service-1", "foo", map[string]string{"param-name": "param-value"}).DoRaw() response, err := c.Setup(t).Services(ns).ProxyGet("service-1", "foo", map[string]string{"param-name": "param-value"}).DoRaw()
c.ValidateRaw(t, response, err) c.ValidateRaw(t, response, err)
} }
...@@ -80,7 +80,7 @@ func makeTestServer(t *testing.T, responses map[string]*serverResponse) (*httpte ...@@ -80,7 +80,7 @@ func makeTestServer(t *testing.T, responses map[string]*serverResponse) (*httpte
mkHandler := func(url string, response serverResponse) *util.FakeHandler { mkHandler := func(url string, response serverResponse) *util.FakeHandler {
handler := util.FakeHandler{ handler := util.FakeHandler{
StatusCode: response.statusCode, StatusCode: response.statusCode,
ResponseBody: runtime.EncodeOrDie(testapi.Codec(), response.obj.(runtime.Object)), ResponseBody: runtime.EncodeOrDie(testapi.Experimental.Codec(), response.obj.(runtime.Object)),
} }
mux.Handle(url, &handler) mux.Handle(url, &handler)
glog.Infof("Will handle %s", url) glog.Infof("Will handle %s", url)
...@@ -176,8 +176,8 @@ func TestSyncEndpointsItemsPreserveNoSelector(t *testing.T) { ...@@ -176,8 +176,8 @@ func TestSyncEndpointsItemsPreserveNoSelector(t *testing.T) {
}) })
defer testServer.Close() defer testServer.Close()
kubeClient := client.NewOrDie(&client.Config{Host: testServer.URL, Version: testapi.Version()}) kubeClient := client.NewOrDie(&client.Config{Host: testServer.URL, Version: testapi.Experimental.Version()})
expClient := client.NewExperimentalOrDie(&client.Config{Host: testServer.URL, Version: testapi.Version()}) expClient := client.NewExperimentalOrDie(&client.Config{Host: testServer.URL, Version: testapi.Experimental.Version()})
fakeRC := fakeResourceConsumptionClient{metrics: map[api.ResourceName]expapi.ResourceConsumption{ fakeRC := fakeResourceConsumptionClient{metrics: map[api.ResourceName]expapi.ResourceConsumption{
api.ResourceCPU: {Resource: api.ResourceCPU, Quantity: resource.MustParse("650m")}, api.ResourceCPU: {Resource: api.ResourceCPU, Quantity: resource.MustParse("650m")},
......
...@@ -57,7 +57,7 @@ func makeTestServer(t *testing.T, responses map[string]*serverResponse) (*httpte ...@@ -57,7 +57,7 @@ func makeTestServer(t *testing.T, responses map[string]*serverResponse) (*httpte
mkHandler := func(url string, response serverResponse) *util.FakeHandler { mkHandler := func(url string, response serverResponse) *util.FakeHandler {
handler := util.FakeHandler{ handler := util.FakeHandler{
StatusCode: response.statusCode, StatusCode: response.statusCode,
ResponseBody: runtime.EncodeOrDie(testapi.Codec(), response.obj.(runtime.Object)), ResponseBody: runtime.EncodeOrDie(testapi.Experimental.Codec(), response.obj.(runtime.Object)),
} }
mux.Handle(url, &handler) mux.Handle(url, &handler)
glog.Infof("Will handle %s", url) glog.Infof("Will handle %s", url)
...@@ -119,7 +119,7 @@ func TestHeapsterResourceConsumptionGet(t *testing.T) { ...@@ -119,7 +119,7 @@ func TestHeapsterResourceConsumptionGet(t *testing.T) {
}) })
defer testServer.Close() defer testServer.Close()
kubeClient := client.NewOrDie(&client.Config{Host: testServer.URL, Version: testapi.Version()}) kubeClient := client.NewOrDie(&client.Config{Host: testServer.URL, Version: testapi.Experimental.Version()})
metricsClient := NewHeapsterMetricsClient(kubeClient) metricsClient := NewHeapsterMetricsClient(kubeClient)
......
...@@ -48,7 +48,7 @@ func NewFakeControllerExpectationsLookup(ttl time.Duration) (*ControllerExpectat ...@@ -48,7 +48,7 @@ func NewFakeControllerExpectationsLookup(ttl time.Duration) (*ControllerExpectat
func newReplicationController(replicas int) *api.ReplicationController { func newReplicationController(replicas int) *api.ReplicationController {
rc := &api.ReplicationController{ rc := &api.ReplicationController{
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()}, TypeMeta: api.TypeMeta{APIVersion: testapi.Default.Version()},
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
UID: util.NewUUID(), UID: util.NewUUID(),
Name: "foobar", Name: "foobar",
...@@ -181,14 +181,14 @@ func TestControllerExpectations(t *testing.T) { ...@@ -181,14 +181,14 @@ func TestControllerExpectations(t *testing.T) {
func TestCreateReplica(t *testing.T) { func TestCreateReplica(t *testing.T) {
ns := api.NamespaceDefault ns := api.NamespaceDefault
body := runtime.EncodeOrDie(testapi.Codec(), &api.Pod{ObjectMeta: api.ObjectMeta{Name: "empty_pod"}}) body := runtime.EncodeOrDie(testapi.Default.Codec(), &api.Pod{ObjectMeta: api.ObjectMeta{Name: "empty_pod"}})
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(body), ResponseBody: string(body),
} }
testServer := httptest.NewServer(&fakeHandler) testServer := httptest.NewServer(&fakeHandler)
defer testServer.Close() defer testServer.Close()
client := client.NewOrDie(&client.Config{Host: testServer.URL, Version: testapi.Version()}) client := client.NewOrDie(&client.Config{Host: testServer.URL, Version: testapi.Default.Version()})
podControl := RealPodControl{ podControl := RealPodControl{
KubeClient: client, KubeClient: client,
...@@ -207,7 +207,7 @@ func TestCreateReplica(t *testing.T) { ...@@ -207,7 +207,7 @@ func TestCreateReplica(t *testing.T) {
}, },
Spec: controllerSpec.Spec.Template.Spec, Spec: controllerSpec.Spec.Template.Spec,
} }
fakeHandler.ValidateRequest(t, testapi.ResourcePath("pods", api.NamespaceDefault, ""), "POST", nil) fakeHandler.ValidateRequest(t, testapi.Default.ResourcePath("pods", api.NamespaceDefault, ""), "POST", nil)
actualPod, err := client.Codec.Decode([]byte(fakeHandler.RequestBody)) actualPod, err := client.Codec.Decode([]byte(fakeHandler.RequestBody))
if err != nil { if err != nil {
t.Errorf("Unexpected error: %#v", err) t.Errorf("Unexpected error: %#v", err)
......
...@@ -36,11 +36,11 @@ type serverResponse struct { ...@@ -36,11 +36,11 @@ type serverResponse struct {
func makeTestServer(t *testing.T, namespace string, serviceAccountResponse serverResponse) (*httptest.Server, *util.FakeHandler) { func makeTestServer(t *testing.T, namespace string, serviceAccountResponse serverResponse) (*httptest.Server, *util.FakeHandler) {
fakeServiceAccountsHandler := util.FakeHandler{ fakeServiceAccountsHandler := util.FakeHandler{
StatusCode: serviceAccountResponse.statusCode, StatusCode: serviceAccountResponse.statusCode,
ResponseBody: runtime.EncodeOrDie(testapi.Codec(), serviceAccountResponse.obj.(runtime.Object)), ResponseBody: runtime.EncodeOrDie(testapi.Default.Codec(), serviceAccountResponse.obj.(runtime.Object)),
} }
mux := http.NewServeMux() mux := http.NewServeMux()
mux.Handle(testapi.ResourcePath("serviceAccounts", namespace, ""), &fakeServiceAccountsHandler) mux.Handle(testapi.Default.ResourcePath("serviceAccounts", namespace, ""), &fakeServiceAccountsHandler)
mux.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) { mux.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
t.Errorf("unexpected request: %v", req.RequestURI) t.Errorf("unexpected request: %v", req.RequestURI)
res.WriteHeader(http.StatusNotFound) res.WriteHeader(http.StatusNotFound)
......
...@@ -391,7 +391,7 @@ func TestAnnotateErrors(t *testing.T) { ...@@ -391,7 +391,7 @@ func TestAnnotateErrors(t *testing.T) {
f, tf, _ := NewAPIFactory() f, tf, _ := NewAPIFactory()
tf.Printer = &testPrinter{} tf.Printer = &testPrinter{}
tf.Namespace = "test" tf.Namespace = "test"
tf.ClientConfig = &client.Config{Version: testapi.Version()} tf.ClientConfig = &client.Config{Version: testapi.Default.Version()}
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdAnnotate(f, buf) cmd := NewCmdAnnotate(f, buf)
...@@ -447,7 +447,7 @@ func TestAnnotateObject(t *testing.T) { ...@@ -447,7 +447,7 @@ func TestAnnotateObject(t *testing.T) {
}), }),
} }
tf.Namespace = "test" tf.Namespace = "test"
tf.ClientConfig = &client.Config{Version: testapi.Version()} tf.ClientConfig = &client.Config{Version: testapi.Default.Version()}
options := &AnnotateOptions{} options := &AnnotateOptions{}
args := []string{"pods/foo", "a=b", "c-"} args := []string{"pods/foo", "a=b", "c-"}
...@@ -494,7 +494,7 @@ func TestAnnotateObjectFromFile(t *testing.T) { ...@@ -494,7 +494,7 @@ func TestAnnotateObjectFromFile(t *testing.T) {
}), }),
} }
tf.Namespace = "test" tf.Namespace = "test"
tf.ClientConfig = &client.Config{Version: testapi.Version()} tf.ClientConfig = &client.Config{Version: testapi.Default.Version()}
options := &AnnotateOptions{} options := &AnnotateOptions{}
options.filenames = []string{"../../../examples/cassandra/cassandra.yaml"} options.filenames = []string{"../../../examples/cassandra/cassandra.yaml"}
...@@ -544,7 +544,7 @@ func TestAnnotateMultipleObjects(t *testing.T) { ...@@ -544,7 +544,7 @@ func TestAnnotateMultipleObjects(t *testing.T) {
}), }),
} }
tf.Namespace = "test" tf.Namespace = "test"
tf.ClientConfig = &client.Config{Version: testapi.Version()} tf.ClientConfig = &client.Config{Version: testapi.Default.Version()}
options := &AnnotateOptions{} options := &AnnotateOptions{}
options.all = true options.all = true
......
...@@ -105,7 +105,7 @@ func TestPodAndContainerAttach(t *testing.T) { ...@@ -105,7 +105,7 @@ func TestPodAndContainerAttach(t *testing.T) {
} }
func TestAttach(t *testing.T) { func TestAttach(t *testing.T) {
version := testapi.Version() version := testapi.Default.Version()
tests := []struct { tests := []struct {
name, version, podPath, attachPath, container string name, version, podPath, attachPath, container string
pod *api.Pod pod *api.Pod
......
...@@ -79,10 +79,10 @@ func newExternalScheme() (*runtime.Scheme, meta.RESTMapper, runtime.Codec) { ...@@ -79,10 +79,10 @@ func newExternalScheme() (*runtime.Scheme, meta.RESTMapper, runtime.Codec) {
scheme.AddKnownTypeWithName("", "Type", &internalType{}) scheme.AddKnownTypeWithName("", "Type", &internalType{})
scheme.AddKnownTypeWithName("unlikelyversion", "Type", &externalType{}) scheme.AddKnownTypeWithName("unlikelyversion", "Type", &externalType{})
//This tests that kubectl will not confuse the external scheme with the internal scheme, even when they accidentally have versions of the same name. //This tests that kubectl will not confuse the external scheme with the internal scheme, even when they accidentally have versions of the same name.
scheme.AddKnownTypeWithName(testapi.Version(), "Type", &ExternalType2{}) scheme.AddKnownTypeWithName(testapi.Default.Version(), "Type", &ExternalType2{})
codec := runtime.CodecFor(scheme, "unlikelyversion") codec := runtime.CodecFor(scheme, "unlikelyversion")
validVersion := testapi.Version() validVersion := testapi.Default.Version()
mapper := meta.NewDefaultRESTMapper("apitest", []string{"unlikelyversion", validVersion}, func(version string) (*meta.VersionInterfaces, error) { mapper := meta.NewDefaultRESTMapper("apitest", []string{"unlikelyversion", validVersion}, func(version string) (*meta.VersionInterfaces, error) {
return &meta.VersionInterfaces{ return &meta.VersionInterfaces{
Codec: runtime.CodecFor(scheme, version), Codec: runtime.CodecFor(scheme, version),
...@@ -228,7 +228,7 @@ func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) { ...@@ -228,7 +228,7 @@ func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) {
generator, ok := generators[name] generator, ok := generators[name]
return generator, ok return generator, ok
}, },
}, t, testapi.Codec() }, t, testapi.Default.Codec()
} }
func objBody(codec runtime.Codec, obj runtime.Object) io.ReadCloser { func objBody(codec runtime.Codec, obj runtime.Object) io.ReadCloser {
...@@ -245,7 +245,7 @@ func stringBody(body string) io.ReadCloser { ...@@ -245,7 +245,7 @@ func stringBody(body string) io.ReadCloser {
//func TestClientVersions(t *testing.T) { //func TestClientVersions(t *testing.T) {
// f := cmdutil.NewFactory(nil) // f := cmdutil.NewFactory(nil)
// //
// version := testapi.Version() // version := testapi.Default.Version()
// mapping := &meta.RESTMapping{ // mapping := &meta.RESTMapping{
// APIVersion: version, // APIVersion: version,
// } // }
......
...@@ -577,13 +577,13 @@ func TestNewEmptyCluster(t *testing.T) { ...@@ -577,13 +577,13 @@ func TestNewEmptyCluster(t *testing.T) {
func TestAdditionalCluster(t *testing.T) { func TestAdditionalCluster(t *testing.T) {
expectedConfig := newRedFederalCowHammerConfig() expectedConfig := newRedFederalCowHammerConfig()
cluster := clientcmdapi.NewCluster() cluster := clientcmdapi.NewCluster()
cluster.APIVersion = testapi.Version() cluster.APIVersion = testapi.Default.Version()
cluster.CertificateAuthority = "/ca-location" cluster.CertificateAuthority = "/ca-location"
cluster.InsecureSkipTLSVerify = false cluster.InsecureSkipTLSVerify = false
cluster.Server = "serverlocation" cluster.Server = "serverlocation"
expectedConfig.Clusters["different-cluster"] = cluster expectedConfig.Clusters["different-cluster"] = cluster
test := configCommandTest{ test := configCommandTest{
args: []string{"set-cluster", "different-cluster", "--" + clientcmd.FlagAPIServer + "=serverlocation", "--" + clientcmd.FlagInsecure + "=false", "--" + clientcmd.FlagCAFile + "=/ca-location", "--" + clientcmd.FlagAPIVersion + "=" + testapi.Version()}, args: []string{"set-cluster", "different-cluster", "--" + clientcmd.FlagAPIServer + "=serverlocation", "--" + clientcmd.FlagInsecure + "=false", "--" + clientcmd.FlagCAFile + "=/ca-location", "--" + clientcmd.FlagAPIVersion + "=" + testapi.Default.Version()},
startingConfig: newRedFederalCowHammerConfig(), startingConfig: newRedFederalCowHammerConfig(),
expectedConfig: expectedConfig, expectedConfig: expectedConfig,
} }
......
...@@ -416,12 +416,12 @@ func TestDeleteMultipleSelector(t *testing.T) { ...@@ -416,12 +416,12 @@ func TestDeleteMultipleSelector(t *testing.T) {
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) { Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; { switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/pods" && m == "GET": case p == "/namespaces/test/pods" && m == "GET":
if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Version())) != "a=b" { if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Default.Version())) != "a=b" {
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req) t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
} }
return &http.Response{StatusCode: 200, Body: objBody(codec, pods)}, nil return &http.Response{StatusCode: 200, Body: objBody(codec, pods)}, nil
case p == "/namespaces/test/services" && m == "GET": case p == "/namespaces/test/services" && m == "GET":
if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Version())) != "a=b" { if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Default.Version())) != "a=b" {
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req) t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
} }
return &http.Response{StatusCode: 200, Body: objBody(codec, svc)}, nil return &http.Response{StatusCode: 200, Body: objBody(codec, svc)}, nil
......
...@@ -129,7 +129,7 @@ func TestPodAndContainer(t *testing.T) { ...@@ -129,7 +129,7 @@ func TestPodAndContainer(t *testing.T) {
} }
func TestExec(t *testing.T) { func TestExec(t *testing.T) {
version := testapi.Version() version := testapi.Default.Version()
tests := []struct { tests := []struct {
name, version, podPath, execPath, container string name, version, podPath, execPath, container string
pod *api.Pod pod *api.Pod
......
...@@ -176,14 +176,14 @@ func TestGetUnknownSchemaObjectListGeneric(t *testing.T) { ...@@ -176,14 +176,14 @@ func TestGetUnknownSchemaObjectListGeneric(t *testing.T) {
rcVersion: latest.Version, // see expected behavior 3b rcVersion: latest.Version, // see expected behavior 3b
}, },
"handles common version": { "handles common version": {
outputVersion: testapi.Version(), outputVersion: testapi.Default.Version(),
listVersion: testapi.Version(), listVersion: testapi.Default.Version(),
testtypeVersion: "unlikelyversion", testtypeVersion: "unlikelyversion",
rcVersion: testapi.Version(), rcVersion: testapi.Default.Version(),
}, },
} }
for k, test := range testCases { for k, test := range testCases {
apiCodec := runtime.CodecFor(api.Scheme, testapi.Version()) apiCodec := runtime.CodecFor(api.Scheme, testapi.Default.Version())
regularClient := &client.FakeRESTClient{ regularClient := &client.FakeRESTClient{
Codec: apiCodec, Codec: apiCodec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) { Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
...@@ -440,7 +440,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) { ...@@ -440,7 +440,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
}), }),
} }
tf.Namespace = "test" tf.Namespace = "test"
tf.ClientConfig = &client.Config{Version: testapi.Version()} tf.ClientConfig = &client.Config{Version: testapi.Default.Version()}
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdGet(f, buf) cmd := NewCmdGet(f, buf)
...@@ -488,7 +488,7 @@ func TestGetMultipleTypeObjectsWithSelector(t *testing.T) { ...@@ -488,7 +488,7 @@ func TestGetMultipleTypeObjectsWithSelector(t *testing.T) {
tf.Client = &client.FakeRESTClient{ tf.Client = &client.FakeRESTClient{
Codec: codec, Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) { Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Version())) != "a=b" { if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Default.Version())) != "a=b" {
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req) t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
} }
switch req.URL.Path { switch req.URL.Path {
...@@ -624,7 +624,7 @@ func TestWatchSelector(t *testing.T) { ...@@ -624,7 +624,7 @@ func TestWatchSelector(t *testing.T) {
tf.Client = &client.FakeRESTClient{ tf.Client = &client.FakeRESTClient{
Codec: codec, Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) { Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Version())) != "a=b" { if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Default.Version())) != "a=b" {
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req) t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
} }
switch req.URL.Path { switch req.URL.Path {
......
...@@ -300,7 +300,7 @@ func TestLabelErrors(t *testing.T) { ...@@ -300,7 +300,7 @@ func TestLabelErrors(t *testing.T) {
f, tf, _ := NewAPIFactory() f, tf, _ := NewAPIFactory()
tf.Printer = &testPrinter{} tf.Printer = &testPrinter{}
tf.Namespace = "test" tf.Namespace = "test"
tf.ClientConfig = &client.Config{Version: testapi.Version()} tf.ClientConfig = &client.Config{Version: testapi.Default.Version()}
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdLabel(f, buf) cmd := NewCmdLabel(f, buf)
...@@ -353,7 +353,7 @@ func TestLabelForResourceFromFile(t *testing.T) { ...@@ -353,7 +353,7 @@ func TestLabelForResourceFromFile(t *testing.T) {
}), }),
} }
tf.Namespace = "test" tf.Namespace = "test"
tf.ClientConfig = &client.Config{Version: testapi.Version()} tf.ClientConfig = &client.Config{Version: testapi.Default.Version()}
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdLabel(f, buf) cmd := NewCmdLabel(f, buf)
...@@ -402,7 +402,7 @@ func TestLabelMultipleObjects(t *testing.T) { ...@@ -402,7 +402,7 @@ func TestLabelMultipleObjects(t *testing.T) {
}), }),
} }
tf.Namespace = "test" tf.Namespace = "test"
tf.ClientConfig = &client.Config{Version: testapi.Version()} tf.ClientConfig = &client.Config{Version: testapi.Default.Version()}
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdLabel(f, buf) cmd := NewCmdLabel(f, buf)
......
...@@ -39,7 +39,7 @@ func (f *fakePortForwarder) ForwardPorts(req *client.Request, config *client.Con ...@@ -39,7 +39,7 @@ func (f *fakePortForwarder) ForwardPorts(req *client.Request, config *client.Con
} }
func TestPortForward(t *testing.T) { func TestPortForward(t *testing.T) {
version := testapi.Version() version := testapi.Default.Version()
tests := []struct { tests := []struct {
name, version, podPath, pfPath, container string name, version, podPath, pfPath, container string
...@@ -101,7 +101,7 @@ func TestPortForward(t *testing.T) { ...@@ -101,7 +101,7 @@ func TestPortForward(t *testing.T) {
} }
func TestPortForwardWithPFlag(t *testing.T) { func TestPortForwardWithPFlag(t *testing.T) {
version := testapi.Version() version := testapi.Default.Version()
tests := []struct { tests := []struct {
name, version, podPath, pfPath, container string name, version, podPath, pfPath, container string
......
...@@ -49,7 +49,7 @@ func TestMerge(t *testing.T) { ...@@ -49,7 +49,7 @@ func TestMerge(t *testing.T) {
Name: "foo", Name: "foo",
}, },
}, },
fragment: fmt.Sprintf(`{ "apiVersion": "%s" }`, testapi.Version()), fragment: fmt.Sprintf(`{ "apiVersion": "%s" }`, testapi.Default.Version()),
expected: &api.Pod{ expected: &api.Pod{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Name: "foo", Name: "foo",
...@@ -82,7 +82,7 @@ func TestMerge(t *testing.T) { ...@@ -82,7 +82,7 @@ func TestMerge(t *testing.T) {
}, },
}, },
}, },
fragment: fmt.Sprintf(`{ "apiVersion": "%s", "spec": { "containers": [ { "name": "c1", "image": "green-image" } ] } }`, testapi.Version()), fragment: fmt.Sprintf(`{ "apiVersion": "%s", "spec": { "containers": [ { "name": "c1", "image": "green-image" } ] } }`, testapi.Default.Version()),
expected: &api.Pod{ expected: &api.Pod{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Name: "foo", Name: "foo",
...@@ -108,7 +108,7 @@ func TestMerge(t *testing.T) { ...@@ -108,7 +108,7 @@ func TestMerge(t *testing.T) {
Name: "foo", Name: "foo",
}, },
}, },
fragment: fmt.Sprintf(`{ "apiVersion": "%s", "spec": { "volumes": [ {"name": "v1"}, {"name": "v2"} ] } }`, testapi.Version()), fragment: fmt.Sprintf(`{ "apiVersion": "%s", "spec": { "volumes": [ {"name": "v1"}, {"name": "v2"} ] } }`, testapi.Default.Version()),
expected: &api.Pod{ expected: &api.Pod{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Name: "foo", Name: "foo",
...@@ -148,7 +148,7 @@ func TestMerge(t *testing.T) { ...@@ -148,7 +148,7 @@ func TestMerge(t *testing.T) {
obj: &api.Service{ obj: &api.Service{
Spec: api.ServiceSpec{}, Spec: api.ServiceSpec{},
}, },
fragment: fmt.Sprintf(`{ "apiVersion": "%s", "spec": { "ports": [ { "port": 0 } ] } }`, testapi.Version()), fragment: fmt.Sprintf(`{ "apiVersion": "%s", "spec": { "ports": [ { "port": 0 } ] } }`, testapi.Default.Version()),
expected: &api.Service{ expected: &api.Service{
Spec: api.ServiceSpec{ Spec: api.ServiceSpec{
SessionAffinity: "None", SessionAffinity: "None",
...@@ -171,7 +171,7 @@ func TestMerge(t *testing.T) { ...@@ -171,7 +171,7 @@ func TestMerge(t *testing.T) {
}, },
}, },
}, },
fragment: fmt.Sprintf(`{ "apiVersion": "%s", "spec": { "selector": { "version": "v2" } } }`, testapi.Version()), fragment: fmt.Sprintf(`{ "apiVersion": "%s", "spec": { "selector": { "version": "v2" } } }`, testapi.Default.Version()),
expected: &api.Service{ expected: &api.Service{
Spec: api.ServiceSpec{ Spec: api.ServiceSpec{
SessionAffinity: "None", SessionAffinity: "None",
......
...@@ -512,7 +512,7 @@ func TestResourceByNameAndEmptySelector(t *testing.T) { ...@@ -512,7 +512,7 @@ func TestResourceByNameAndEmptySelector(t *testing.T) {
func TestSelector(t *testing.T) { func TestSelector(t *testing.T) {
pods, svc := testData() pods, svc := testData()
labelKey := api.LabelSelectorQueryParam(testapi.Version()) labelKey := api.LabelSelectorQueryParam(testapi.Default.Version())
b := NewBuilder(latest.RESTMapper, api.Scheme, fakeClientWith("", t, map[string]string{ b := NewBuilder(latest.RESTMapper, api.Scheme, fakeClientWith("", t, map[string]string{
"/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, pods), "/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, pods),
"/namespaces/test/services?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, svc), "/namespaces/test/services?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, svc),
...@@ -808,7 +808,7 @@ func TestSingularRootScopedObject(t *testing.T) { ...@@ -808,7 +808,7 @@ func TestSingularRootScopedObject(t *testing.T) {
func TestListObject(t *testing.T) { func TestListObject(t *testing.T) {
pods, _ := testData() pods, _ := testData()
labelKey := api.LabelSelectorQueryParam(testapi.Version()) labelKey := api.LabelSelectorQueryParam(testapi.Default.Version())
b := NewBuilder(latest.RESTMapper, api.Scheme, fakeClientWith("", t, map[string]string{ b := NewBuilder(latest.RESTMapper, api.Scheme, fakeClientWith("", t, map[string]string{
"/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, pods), "/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, pods),
})). })).
...@@ -841,7 +841,7 @@ func TestListObject(t *testing.T) { ...@@ -841,7 +841,7 @@ func TestListObject(t *testing.T) {
func TestListObjectWithDifferentVersions(t *testing.T) { func TestListObjectWithDifferentVersions(t *testing.T) {
pods, svc := testData() pods, svc := testData()
labelKey := api.LabelSelectorQueryParam(testapi.Version()) labelKey := api.LabelSelectorQueryParam(testapi.Default.Version())
obj, err := NewBuilder(latest.RESTMapper, api.Scheme, fakeClientWith("", t, map[string]string{ obj, err := NewBuilder(latest.RESTMapper, api.Scheme, fakeClientWith("", t, map[string]string{
"/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, pods), "/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, pods),
"/namespaces/test/services?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, svc), "/namespaces/test/services?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, svc),
......
...@@ -34,7 +34,7 @@ import ( ...@@ -34,7 +34,7 @@ import (
) )
func objBody(obj runtime.Object) io.ReadCloser { func objBody(obj runtime.Object) io.ReadCloser {
return ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(testapi.Codec(), obj)))) return ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(testapi.Default.Codec(), obj))))
} }
// splitPath returns the segments for a URL path. // splitPath returns the segments for a URL path.
...@@ -93,7 +93,7 @@ func TestHelperDelete(t *testing.T) { ...@@ -93,7 +93,7 @@ func TestHelperDelete(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
client := &client.FakeRESTClient{ client := &client.FakeRESTClient{
Codec: testapi.Codec(), Codec: testapi.Default.Codec(),
Resp: test.Resp, Resp: test.Resp,
Err: test.HttpErr, Err: test.HttpErr,
} }
...@@ -184,7 +184,7 @@ func TestHelperCreate(t *testing.T) { ...@@ -184,7 +184,7 @@ func TestHelperCreate(t *testing.T) {
} }
for i, test := range tests { for i, test := range tests {
client := &client.FakeRESTClient{ client := &client.FakeRESTClient{
Codec: testapi.Codec(), Codec: testapi.Default.Codec(),
Resp: test.Resp, Resp: test.Resp,
Err: test.HttpErr, Err: test.HttpErr,
} }
...@@ -193,13 +193,13 @@ func TestHelperCreate(t *testing.T) { ...@@ -193,13 +193,13 @@ func TestHelperCreate(t *testing.T) {
} }
modifier := &Helper{ modifier := &Helper{
RESTClient: client, RESTClient: client,
Codec: testapi.Codec(), Codec: testapi.Default.Codec(),
Versioner: testapi.MetadataAccessor(), Versioner: testapi.Default.MetadataAccessor(),
NamespaceScoped: true, NamespaceScoped: true,
} }
data := []byte{} data := []byte{}
if test.Object != nil { if test.Object != nil {
data = []byte(runtime.EncodeOrDie(testapi.Codec(), test.Object)) data = []byte(runtime.EncodeOrDie(testapi.Default.Codec(), test.Object))
} }
_, err := modifier.Create("bar", test.Modify, data) _, err := modifier.Create("bar", test.Modify, data)
if (err != nil) != test.Err { if (err != nil) != test.Err {
...@@ -218,7 +218,7 @@ func TestHelperCreate(t *testing.T) { ...@@ -218,7 +218,7 @@ func TestHelperCreate(t *testing.T) {
t.Logf("got body: %s", string(body)) t.Logf("got body: %s", string(body))
expect := []byte{} expect := []byte{}
if test.ExpectObject != nil { if test.ExpectObject != nil {
expect = []byte(runtime.EncodeOrDie(testapi.Codec(), test.ExpectObject)) expect = []byte(runtime.EncodeOrDie(testapi.Default.Codec(), test.ExpectObject))
} }
if !reflect.DeepEqual(expect, body) { if !reflect.DeepEqual(expect, body) {
t.Errorf("%d: unexpected body: %s", i, string(body)) t.Errorf("%d: unexpected body: %s", i, string(body))
...@@ -270,7 +270,7 @@ func TestHelperGet(t *testing.T) { ...@@ -270,7 +270,7 @@ func TestHelperGet(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
client := &client.FakeRESTClient{ client := &client.FakeRESTClient{
Codec: testapi.Codec(), Codec: testapi.Default.Codec(),
Resp: test.Resp, Resp: test.Resp,
Err: test.HttpErr, Err: test.HttpErr,
} }
...@@ -331,7 +331,7 @@ func TestHelperList(t *testing.T) { ...@@ -331,7 +331,7 @@ func TestHelperList(t *testing.T) {
t.Errorf("url doesn't contain name: %#v", req.URL) t.Errorf("url doesn't contain name: %#v", req.URL)
return false return false
} }
if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Version())) != labels.SelectorFromSet(labels.Set{"foo": "baz"}).String() { if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Default.Version())) != labels.SelectorFromSet(labels.Set{"foo": "baz"}).String() {
t.Errorf("url doesn't contain query parameters: %#v", req.URL) t.Errorf("url doesn't contain query parameters: %#v", req.URL)
return false return false
} }
...@@ -341,7 +341,7 @@ func TestHelperList(t *testing.T) { ...@@ -341,7 +341,7 @@ func TestHelperList(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
client := &client.FakeRESTClient{ client := &client.FakeRESTClient{
Codec: testapi.Codec(), Codec: testapi.Default.Codec(),
Resp: test.Resp, Resp: test.Resp,
Err: test.HttpErr, Err: test.HttpErr,
} }
...@@ -349,7 +349,7 @@ func TestHelperList(t *testing.T) { ...@@ -349,7 +349,7 @@ func TestHelperList(t *testing.T) {
RESTClient: client, RESTClient: client,
NamespaceScoped: true, NamespaceScoped: true,
} }
obj, err := modifier.List("bar", testapi.Version(), labels.SelectorFromSet(labels.Set{"foo": "baz"})) obj, err := modifier.List("bar", testapi.Default.Version(), labels.SelectorFromSet(labels.Set{"foo": "baz"}))
if (err != nil) != test.Err { if (err != nil) != test.Err {
t.Errorf("unexpected error: %t %v", test.Err, err) t.Errorf("unexpected error: %t %v", test.Err, err)
} }
...@@ -444,7 +444,7 @@ func TestHelperReplace(t *testing.T) { ...@@ -444,7 +444,7 @@ func TestHelperReplace(t *testing.T) {
} }
for i, test := range tests { for i, test := range tests {
client := &client.FakeRESTClient{ client := &client.FakeRESTClient{
Codec: testapi.Codec(), Codec: testapi.Default.Codec(),
Resp: test.Resp, Resp: test.Resp,
Err: test.HttpErr, Err: test.HttpErr,
} }
...@@ -453,13 +453,13 @@ func TestHelperReplace(t *testing.T) { ...@@ -453,13 +453,13 @@ func TestHelperReplace(t *testing.T) {
} }
modifier := &Helper{ modifier := &Helper{
RESTClient: client, RESTClient: client,
Codec: testapi.Codec(), Codec: testapi.Default.Codec(),
Versioner: testapi.MetadataAccessor(), Versioner: testapi.Default.MetadataAccessor(),
NamespaceScoped: true, NamespaceScoped: true,
} }
data := []byte{} data := []byte{}
if test.Object != nil { if test.Object != nil {
data = []byte(runtime.EncodeOrDie(testapi.Codec(), test.Object)) data = []byte(runtime.EncodeOrDie(testapi.Default.Codec(), test.Object))
} }
_, err := modifier.Replace("bar", "foo", test.Overwrite, data) _, err := modifier.Replace("bar", "foo", test.Overwrite, data)
if (err != nil) != test.Err { if (err != nil) != test.Err {
...@@ -478,7 +478,7 @@ func TestHelperReplace(t *testing.T) { ...@@ -478,7 +478,7 @@ func TestHelperReplace(t *testing.T) {
t.Logf("got body: %s", string(body)) t.Logf("got body: %s", string(body))
expect := []byte{} expect := []byte{}
if test.ExpectObject != nil { if test.ExpectObject != nil {
expect = []byte(runtime.EncodeOrDie(testapi.Codec(), test.ExpectObject)) expect = []byte(runtime.EncodeOrDie(testapi.Default.Codec(), test.ExpectObject))
} }
if !reflect.DeepEqual(expect, body) { if !reflect.DeepEqual(expect, body) {
t.Errorf("%d: unexpected body: %s", i, string(body)) t.Errorf("%d: unexpected body: %s", i, string(body))
......
...@@ -49,7 +49,7 @@ func (ts *testStruct) IsAnAPIObject() {} ...@@ -49,7 +49,7 @@ func (ts *testStruct) IsAnAPIObject() {}
func init() { func init() {
api.Scheme.AddKnownTypes("", &testStruct{}) api.Scheme.AddKnownTypes("", &testStruct{})
api.Scheme.AddKnownTypes(testapi.Version(), &testStruct{}) api.Scheme.AddKnownTypes(testapi.Default.Version(), &testStruct{})
} }
var testData = testStruct{ var testData = testStruct{
...@@ -72,7 +72,7 @@ func TestVersionedPrinter(t *testing.T) { ...@@ -72,7 +72,7 @@ func TestVersionedPrinter(t *testing.T) {
return nil return nil
}), }),
api.Scheme, api.Scheme,
testapi.Version(), testapi.Default.Version(),
) )
if err := p.PrintObj(original, nil); err != nil { if err := p.PrintObj(original, nil); err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
...@@ -110,7 +110,7 @@ func TestPrinter(t *testing.T) { ...@@ -110,7 +110,7 @@ func TestPrinter(t *testing.T) {
}, },
} }
emptyListTest := &api.PodList{} emptyListTest := &api.PodList{}
testapi, err := api.Scheme.ConvertToVersion(podTest, testapi.Version()) testapi, err := api.Scheme.ConvertToVersion(podTest, testapi.Default.Version())
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
...@@ -183,7 +183,7 @@ func testPrinter(t *testing.T, printer ResourcePrinter, unmarshalFunc func(data ...@@ -183,7 +183,7 @@ func testPrinter(t *testing.T, printer ResourcePrinter, unmarshalFunc func(data
} }
// Use real decode function to undo the versioning process. // Use real decode function to undo the versioning process.
poutput = testStruct{} poutput = testStruct{}
err = runtime.YAMLDecoder(testapi.Codec()).DecodeInto(buf.Bytes(), &poutput) err = runtime.YAMLDecoder(testapi.Default.Codec()).DecodeInto(buf.Bytes(), &poutput)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -204,7 +204,7 @@ func testPrinter(t *testing.T, printer ResourcePrinter, unmarshalFunc func(data ...@@ -204,7 +204,7 @@ func testPrinter(t *testing.T, printer ResourcePrinter, unmarshalFunc func(data
} }
// Use real decode function to undo the versioning process. // Use real decode function to undo the versioning process.
objOut = api.Pod{} objOut = api.Pod{}
err = runtime.YAMLDecoder(testapi.Codec()).DecodeInto(buf.Bytes(), &objOut) err = runtime.YAMLDecoder(testapi.Default.Codec()).DecodeInto(buf.Bytes(), &objOut)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -430,7 +430,7 @@ func TestTemplateStrings(t *testing.T) { ...@@ -430,7 +430,7 @@ func TestTemplateStrings(t *testing.T) {
t.Fatalf("tmpl fail: %v", err) t.Fatalf("tmpl fail: %v", err)
} }
printer := NewVersionedPrinter(p, api.Scheme, testapi.Version()) printer := NewVersionedPrinter(p, api.Scheme, testapi.Default.Version())
for name, item := range table { for name, item := range table {
buffer := &bytes.Buffer{} buffer := &bytes.Buffer{}
......
...@@ -1008,7 +1008,7 @@ func TestUpdateExistingReplicationController(t *testing.T) { ...@@ -1008,7 +1008,7 @@ func TestUpdateExistingReplicationController(t *testing.T) {
} }
func TestUpdateWithRetries(t *testing.T) { func TestUpdateWithRetries(t *testing.T) {
codec := testapi.Codec() codec := testapi.Default.Codec()
grace := int64(30) grace := int64(30)
rc := &api.ReplicationController{ rc := &api.ReplicationController{
ObjectMeta: api.ObjectMeta{Name: "rc", ObjectMeta: api.ObjectMeta{Name: "rc",
...@@ -1055,7 +1055,7 @@ func TestUpdateWithRetries(t *testing.T) { ...@@ -1055,7 +1055,7 @@ func TestUpdateWithRetries(t *testing.T) {
Codec: codec, Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) { Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; { switch p, m := req.URL.Path, req.Method; {
case p == testapi.ResourcePath("replicationcontrollers", "default", "rc") && m == "PUT": case p == testapi.Default.ResourcePath("replicationcontrollers", "default", "rc") && m == "PUT":
update := updates[0] update := updates[0]
updates = updates[1:] updates = updates[1:]
// We should always get an update with a valid rc even when the get fails. The rc should always // We should always get an update with a valid rc even when the get fails. The rc should always
...@@ -1068,7 +1068,7 @@ func TestUpdateWithRetries(t *testing.T) { ...@@ -1068,7 +1068,7 @@ func TestUpdateWithRetries(t *testing.T) {
delete(c.Spec.Selector, "baz") delete(c.Spec.Selector, "baz")
} }
return update, nil return update, nil
case p == testapi.ResourcePath("replicationcontrollers", "default", "rc") && m == "GET": case p == testapi.Default.ResourcePath("replicationcontrollers", "default", "rc") && m == "GET":
get := gets[0] get := gets[0]
gets = gets[1:] gets = gets[1:]
return get, nil return get, nil
...@@ -1078,7 +1078,7 @@ func TestUpdateWithRetries(t *testing.T) { ...@@ -1078,7 +1078,7 @@ func TestUpdateWithRetries(t *testing.T) {
} }
}), }),
} }
clientConfig := &client.Config{Version: testapi.Version()} clientConfig := &client.Config{Version: testapi.Default.Version()}
client := client.NewOrDie(clientConfig) client := client.NewOrDie(clientConfig)
client.Client = fakeClient.Client client.Client = fakeClient.Client
...@@ -1115,7 +1115,7 @@ func objBody(codec runtime.Codec, obj runtime.Object) io.ReadCloser { ...@@ -1115,7 +1115,7 @@ func objBody(codec runtime.Codec, obj runtime.Object) io.ReadCloser {
func TestAddDeploymentHash(t *testing.T) { func TestAddDeploymentHash(t *testing.T) {
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
codec := testapi.Codec() codec := testapi.Default.Codec()
rc := &api.ReplicationController{ rc := &api.ReplicationController{
ObjectMeta: api.ObjectMeta{Name: "rc"}, ObjectMeta: api.ObjectMeta{Name: "rc"},
Spec: api.ReplicationControllerSpec{ Spec: api.ReplicationControllerSpec{
...@@ -1146,27 +1146,27 @@ func TestAddDeploymentHash(t *testing.T) { ...@@ -1146,27 +1146,27 @@ func TestAddDeploymentHash(t *testing.T) {
Codec: codec, Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) { Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; { switch p, m := req.URL.Path, req.Method; {
case p == testapi.ResourcePath("pods", "default", "") && m == "GET": case p == testapi.Default.ResourcePath("pods", "default", "") && m == "GET":
if req.URL.RawQuery != "labelSelector=foo%3Dbar" { if req.URL.RawQuery != "labelSelector=foo%3Dbar" {
t.Errorf("Unexpected query string: %s", req.URL.RawQuery) t.Errorf("Unexpected query string: %s", req.URL.RawQuery)
} }
return &http.Response{StatusCode: 200, Body: objBody(codec, podList)}, nil return &http.Response{StatusCode: 200, Body: objBody(codec, podList)}, nil
case p == testapi.ResourcePath("pods", "default", "foo") && m == "PUT": case p == testapi.Default.ResourcePath("pods", "default", "foo") && m == "PUT":
seen.Insert("foo") seen.Insert("foo")
obj := readOrDie(t, req, codec) obj := readOrDie(t, req, codec)
podList.Items[0] = *(obj.(*api.Pod)) podList.Items[0] = *(obj.(*api.Pod))
return &http.Response{StatusCode: 200, Body: objBody(codec, &podList.Items[0])}, nil return &http.Response{StatusCode: 200, Body: objBody(codec, &podList.Items[0])}, nil
case p == testapi.ResourcePath("pods", "default", "bar") && m == "PUT": case p == testapi.Default.ResourcePath("pods", "default", "bar") && m == "PUT":
seen.Insert("bar") seen.Insert("bar")
obj := readOrDie(t, req, codec) obj := readOrDie(t, req, codec)
podList.Items[1] = *(obj.(*api.Pod)) podList.Items[1] = *(obj.(*api.Pod))
return &http.Response{StatusCode: 200, Body: objBody(codec, &podList.Items[1])}, nil return &http.Response{StatusCode: 200, Body: objBody(codec, &podList.Items[1])}, nil
case p == testapi.ResourcePath("pods", "default", "baz") && m == "PUT": case p == testapi.Default.ResourcePath("pods", "default", "baz") && m == "PUT":
seen.Insert("baz") seen.Insert("baz")
obj := readOrDie(t, req, codec) obj := readOrDie(t, req, codec)
podList.Items[2] = *(obj.(*api.Pod)) podList.Items[2] = *(obj.(*api.Pod))
return &http.Response{StatusCode: 200, Body: objBody(codec, &podList.Items[2])}, nil return &http.Response{StatusCode: 200, Body: objBody(codec, &podList.Items[2])}, nil
case p == testapi.ResourcePath("replicationcontrollers", "default", "rc") && m == "PUT": case p == testapi.Default.ResourcePath("replicationcontrollers", "default", "rc") && m == "PUT":
updatedRc = true updatedRc = true
return &http.Response{StatusCode: 200, Body: objBody(codec, rc)}, nil return &http.Response{StatusCode: 200, Body: objBody(codec, rc)}, nil
default: default:
...@@ -1175,7 +1175,7 @@ func TestAddDeploymentHash(t *testing.T) { ...@@ -1175,7 +1175,7 @@ func TestAddDeploymentHash(t *testing.T) {
} }
}), }),
} }
clientConfig := &client.Config{Version: testapi.Version()} clientConfig := &client.Config{Version: testapi.Default.Version()}
client := client.NewOrDie(clientConfig) client := client.NewOrDie(clientConfig)
client.Client = fakeClient.Client client.Client = fakeClient.Client
......
...@@ -54,7 +54,7 @@ func TestDecodeSinglePod(t *testing.T) { ...@@ -54,7 +54,7 @@ func TestDecodeSinglePod(t *testing.T) {
}}, }},
}, },
} }
json, err := testapi.Codec().Encode(pod) json, err := testapi.Default.Codec().Encode(pod)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -70,7 +70,7 @@ func TestDecodeSinglePod(t *testing.T) { ...@@ -70,7 +70,7 @@ func TestDecodeSinglePod(t *testing.T) {
} }
for _, version := range registered.RegisteredVersions { for _, version := range registered.RegisteredVersions {
externalPod, err := testapi.Converter().ConvertToVersion(pod, version) externalPod, err := testapi.Default.Converter().ConvertToVersion(pod, version)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -119,7 +119,7 @@ func TestDecodePodList(t *testing.T) { ...@@ -119,7 +119,7 @@ func TestDecodePodList(t *testing.T) {
podList := &api.PodList{ podList := &api.PodList{
Items: []api.Pod{*pod}, Items: []api.Pod{*pod},
} }
json, err := testapi.Codec().Encode(podList) json, err := testapi.Default.Codec().Encode(podList)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -135,7 +135,7 @@ func TestDecodePodList(t *testing.T) { ...@@ -135,7 +135,7 @@ func TestDecodePodList(t *testing.T) {
} }
for _, version := range registered.RegisteredVersions { for _, version := range registered.RegisteredVersions {
externalPodList, err := testapi.Converter().ConvertToVersion(podList, version) externalPodList, err := testapi.Default.Converter().ConvertToVersion(podList, version)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
......
...@@ -117,11 +117,11 @@ func TestReadPodsFromFile(t *testing.T) { ...@@ -117,11 +117,11 @@ func TestReadPodsFromFile(t *testing.T) {
for _, testCase := range testCases { for _, testCase := range testCases {
func() { func() {
var versionedPod runtime.Object var versionedPod runtime.Object
err := testapi.Converter().Convert(&testCase.pod, &versionedPod) err := testapi.Default.Converter().Convert(&testCase.pod, &versionedPod)
if err != nil { if err != nil {
t.Fatalf("%s: error in versioning the pod: %v", testCase.desc, err) t.Fatalf("%s: error in versioning the pod: %v", testCase.desc, err)
} }
fileContents, err := testapi.Codec().Encode(versionedPod) fileContents, err := testapi.Default.Codec().Encode(versionedPod)
if err != nil { if err != nil {
t.Fatalf("%s: error in encoding the pod: %v", testCase.desc, err) t.Fatalf("%s: error in encoding the pod: %v", testCase.desc, err)
} }
......
...@@ -67,7 +67,7 @@ func TestExtractInvalidPods(t *testing.T) { ...@@ -67,7 +67,7 @@ func TestExtractInvalidPods(t *testing.T) {
{ {
desc: "Invalid volume name", desc: "Invalid volume name",
pod: &api.Pod{ pod: &api.Pod{
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()}, TypeMeta: api.TypeMeta{APIVersion: testapi.Default.Version()},
Spec: api.PodSpec{ Spec: api.PodSpec{
Volumes: []api.Volume{{Name: "_INVALID_"}}, Volumes: []api.Volume{{Name: "_INVALID_"}},
}, },
...@@ -76,7 +76,7 @@ func TestExtractInvalidPods(t *testing.T) { ...@@ -76,7 +76,7 @@ func TestExtractInvalidPods(t *testing.T) {
{ {
desc: "Duplicate volume names", desc: "Duplicate volume names",
pod: &api.Pod{ pod: &api.Pod{
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()}, TypeMeta: api.TypeMeta{APIVersion: testapi.Default.Version()},
Spec: api.PodSpec{ Spec: api.PodSpec{
Volumes: []api.Volume{{Name: "repeated"}, {Name: "repeated"}}, Volumes: []api.Volume{{Name: "repeated"}, {Name: "repeated"}},
}, },
...@@ -85,7 +85,7 @@ func TestExtractInvalidPods(t *testing.T) { ...@@ -85,7 +85,7 @@ func TestExtractInvalidPods(t *testing.T) {
{ {
desc: "Unspecified container name", desc: "Unspecified container name",
pod: &api.Pod{ pod: &api.Pod{
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()}, TypeMeta: api.TypeMeta{APIVersion: testapi.Default.Version()},
Spec: api.PodSpec{ Spec: api.PodSpec{
Containers: []api.Container{{Name: ""}}, Containers: []api.Container{{Name: ""}},
}, },
...@@ -94,7 +94,7 @@ func TestExtractInvalidPods(t *testing.T) { ...@@ -94,7 +94,7 @@ func TestExtractInvalidPods(t *testing.T) {
{ {
desc: "Invalid container name", desc: "Invalid container name",
pod: &api.Pod{ pod: &api.Pod{
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()}, TypeMeta: api.TypeMeta{APIVersion: testapi.Default.Version()},
Spec: api.PodSpec{ Spec: api.PodSpec{
Containers: []api.Container{{Name: "_INVALID_"}}, Containers: []api.Container{{Name: "_INVALID_"}},
}, },
...@@ -252,11 +252,11 @@ func TestExtractPodsFromHTTP(t *testing.T) { ...@@ -252,11 +252,11 @@ func TestExtractPodsFromHTTP(t *testing.T) {
for _, testCase := range testCases { for _, testCase := range testCases {
var versionedPods runtime.Object var versionedPods runtime.Object
err := testapi.Converter().Convert(&testCase.pods, &versionedPods) err := testapi.Default.Converter().Convert(&testCase.pods, &versionedPods)
if err != nil { if err != nil {
t.Fatalf("%s: error in versioning the pods: %s", testCase.desc, err) t.Fatalf("%s: error in versioning the pods: %s", testCase.desc, err)
} }
data, err := testapi.Codec().Encode(versionedPods) data, err := testapi.Default.Codec().Encode(versionedPods)
if err != nil { if err != nil {
t.Fatalf("%s: error in encoding the pod: %v", testCase.desc, err) t.Fatalf("%s: error in encoding the pod: %v", testCase.desc, err)
} }
...@@ -288,7 +288,7 @@ func TestExtractPodsFromHTTP(t *testing.T) { ...@@ -288,7 +288,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
func TestURLWithHeader(t *testing.T) { func TestURLWithHeader(t *testing.T) {
pod := &api.Pod{ pod := &api.Pod{
TypeMeta: api.TypeMeta{ TypeMeta: api.TypeMeta{
APIVersion: testapi.Version(), APIVersion: testapi.Default.Version(),
Kind: "Pod", Kind: "Pod",
}, },
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
......
...@@ -66,14 +66,14 @@ func TestGenerateContainerRef(t *testing.T) { ...@@ -66,14 +66,14 @@ func TestGenerateContainerRef(t *testing.T) {
okPod = api.Pod{ okPod = api.Pod{
TypeMeta: api.TypeMeta{ TypeMeta: api.TypeMeta{
Kind: "Pod", Kind: "Pod",
APIVersion: testapi.Version(), APIVersion: testapi.Default.Version(),
}, },
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Name: "ok", Name: "ok",
Namespace: "test-ns", Namespace: "test-ns",
UID: "bar", UID: "bar",
ResourceVersion: "42", ResourceVersion: "42",
SelfLink: "/api/" + testapi.Version() + "/pods/foo", SelfLink: "/api/" + testapi.Default.Version() + "/pods/foo",
}, },
Spec: api.PodSpec{ Spec: api.PodSpec{
Containers: []api.Container{ Containers: []api.Container{
...@@ -90,7 +90,7 @@ func TestGenerateContainerRef(t *testing.T) { ...@@ -90,7 +90,7 @@ func TestGenerateContainerRef(t *testing.T) {
noSelfLinkPod.Kind = "" noSelfLinkPod.Kind = ""
noSelfLinkPod.APIVersion = "" noSelfLinkPod.APIVersion = ""
noSelfLinkPod.ObjectMeta.SelfLink = "" noSelfLinkPod.ObjectMeta.SelfLink = ""
defaultedSelfLinkPod.ObjectMeta.SelfLink = "/api/" + testapi.Version() + "/pods/ok" defaultedSelfLinkPod.ObjectMeta.SelfLink = "/api/" + testapi.Default.Version() + "/pods/ok"
cases := []struct { cases := []struct {
name string name string
...@@ -107,7 +107,7 @@ func TestGenerateContainerRef(t *testing.T) { ...@@ -107,7 +107,7 @@ func TestGenerateContainerRef(t *testing.T) {
}, },
expected: &api.ObjectReference{ expected: &api.ObjectReference{
Kind: "Pod", Kind: "Pod",
APIVersion: testapi.Version(), APIVersion: testapi.Default.Version(),
Name: "ok", Name: "ok",
Namespace: "test-ns", Namespace: "test-ns",
UID: "bar", UID: "bar",
...@@ -122,7 +122,7 @@ func TestGenerateContainerRef(t *testing.T) { ...@@ -122,7 +122,7 @@ func TestGenerateContainerRef(t *testing.T) {
container: &api.Container{}, container: &api.Container{},
expected: &api.ObjectReference{ expected: &api.ObjectReference{
Kind: "Pod", Kind: "Pod",
APIVersion: testapi.Version(), APIVersion: testapi.Default.Version(),
Name: "ok", Name: "ok",
Namespace: "test-ns", Namespace: "test-ns",
UID: "bar", UID: "bar",
...@@ -146,7 +146,7 @@ func TestGenerateContainerRef(t *testing.T) { ...@@ -146,7 +146,7 @@ func TestGenerateContainerRef(t *testing.T) {
}, },
expected: &api.ObjectReference{ expected: &api.ObjectReference{
Kind: "Pod", Kind: "Pod",
APIVersion: testapi.Version(), APIVersion: testapi.Default.Version(),
Name: "ok", Name: "ok",
Namespace: "test-ns", Namespace: "test-ns",
UID: "bar", UID: "bar",
...@@ -163,7 +163,7 @@ func TestGenerateContainerRef(t *testing.T) { ...@@ -163,7 +163,7 @@ func TestGenerateContainerRef(t *testing.T) {
}, },
expected: &api.ObjectReference{ expected: &api.ObjectReference{
Kind: "Pod", Kind: "Pod",
APIVersion: testapi.Version(), APIVersion: testapi.Default.Version(),
Name: "ok", Name: "ok",
Namespace: "test-ns", Namespace: "test-ns",
UID: "bar", UID: "bar",
......
...@@ -449,7 +449,7 @@ func TestKillContainerInPodWithPreStop(t *testing.T) { ...@@ -449,7 +449,7 @@ func TestKillContainerInPodWithPreStop(t *testing.T) {
}, },
{Name: "bar"}}}, {Name: "bar"}}},
} }
podString, err := testapi.Codec().Encode(pod) podString, err := testapi.Default.Codec().Encode(pod)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -2348,7 +2348,7 @@ func TestPodDependsOnPodIP(t *testing.T) { ...@@ -2348,7 +2348,7 @@ func TestPodDependsOnPodIP(t *testing.T) {
Name: "POD_IP", Name: "POD_IP",
ValueFrom: &api.EnvVarSource{ ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{ FieldRef: &api.ObjectFieldSelector{
APIVersion: testapi.Version(), APIVersion: testapi.Default.Version(),
FieldPath: "status.podIP", FieldPath: "status.podIP",
}, },
}, },
...@@ -2369,7 +2369,7 @@ func TestPodDependsOnPodIP(t *testing.T) { ...@@ -2369,7 +2369,7 @@ func TestPodDependsOnPodIP(t *testing.T) {
Name: "POD_NAME", Name: "POD_NAME",
ValueFrom: &api.EnvVarSource{ ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{ FieldRef: &api.ObjectFieldSelector{
APIVersion: testapi.Version(), APIVersion: testapi.Default.Version(),
FieldPath: "metadata.name", FieldPath: "metadata.name",
}, },
}, },
......
...@@ -1227,7 +1227,7 @@ func TestMakeEnvironmentVariables(t *testing.T) { ...@@ -1227,7 +1227,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
Name: "POD_NAME", Name: "POD_NAME",
ValueFrom: &api.EnvVarSource{ ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{ FieldRef: &api.ObjectFieldSelector{
APIVersion: testapi.Version(), APIVersion: testapi.Default.Version(),
FieldPath: "metadata.name", FieldPath: "metadata.name",
}, },
}, },
...@@ -1236,7 +1236,7 @@ func TestMakeEnvironmentVariables(t *testing.T) { ...@@ -1236,7 +1236,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
Name: "POD_NAMESPACE", Name: "POD_NAMESPACE",
ValueFrom: &api.EnvVarSource{ ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{ FieldRef: &api.ObjectFieldSelector{
APIVersion: testapi.Version(), APIVersion: testapi.Default.Version(),
FieldPath: "metadata.namespace", FieldPath: "metadata.namespace",
}, },
}, },
...@@ -1245,7 +1245,7 @@ func TestMakeEnvironmentVariables(t *testing.T) { ...@@ -1245,7 +1245,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
Name: "POD_IP", Name: "POD_IP",
ValueFrom: &api.EnvVarSource{ ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{ FieldRef: &api.ObjectFieldSelector{
APIVersion: testapi.Version(), APIVersion: testapi.Default.Version(),
FieldPath: "status.podIP", FieldPath: "status.podIP",
}, },
}, },
...@@ -1273,7 +1273,7 @@ func TestMakeEnvironmentVariables(t *testing.T) { ...@@ -1273,7 +1273,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
Name: "POD_NAME", Name: "POD_NAME",
ValueFrom: &api.EnvVarSource{ ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{ FieldRef: &api.ObjectFieldSelector{
APIVersion: testapi.Version(), APIVersion: testapi.Default.Version(),
FieldPath: "metadata.name", FieldPath: "metadata.name",
}, },
}, },
......
...@@ -28,7 +28,7 @@ import ( ...@@ -28,7 +28,7 @@ import (
) )
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
return NewREST(etcdStorage), fakeClient return NewREST(etcdStorage), fakeClient
} }
......
...@@ -29,7 +29,7 @@ import ( ...@@ -29,7 +29,7 @@ import (
) )
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "experimental")
return NewREST(etcdStorage), fakeClient return NewREST(etcdStorage), fakeClient
} }
......
...@@ -29,7 +29,7 @@ import ( ...@@ -29,7 +29,7 @@ import (
) )
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "experimental")
return NewREST(etcdStorage), fakeClient return NewREST(etcdStorage), fakeClient
} }
......
...@@ -28,7 +28,7 @@ import ( ...@@ -28,7 +28,7 @@ import (
) )
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
return NewREST(etcdStorage, false), fakeClient return NewREST(etcdStorage, false), fakeClient
} }
......
...@@ -28,7 +28,7 @@ import ( ...@@ -28,7 +28,7 @@ import (
var testTTL uint64 = 60 var testTTL uint64 = 60
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
fakeClient.HideExpires = true fakeClient.HideExpires = true
return NewREST(etcdStorage, testTTL), fakeClient return NewREST(etcdStorage, testTTL), fakeClient
} }
......
...@@ -48,7 +48,7 @@ func TestGetAttrs(t *testing.T) { ...@@ -48,7 +48,7 @@ func TestGetAttrs(t *testing.T) {
Name: "foo", Name: "foo",
Namespace: "baz", Namespace: "baz",
UID: "long uid string", UID: "long uid string",
APIVersion: testapi.Version(), APIVersion: testapi.Default.Version(),
ResourceVersion: "0", ResourceVersion: "0",
FieldPath: "", FieldPath: "",
}, },
...@@ -68,7 +68,7 @@ func TestGetAttrs(t *testing.T) { ...@@ -68,7 +68,7 @@ func TestGetAttrs(t *testing.T) {
"involvedObject.name": "foo", "involvedObject.name": "foo",
"involvedObject.namespace": "baz", "involvedObject.namespace": "baz",
"involvedObject.uid": "long uid string", "involvedObject.uid": "long uid string",
"involvedObject.apiVersion": testapi.Version(), "involvedObject.apiVersion": testapi.Default.Version(),
"involvedObject.resourceVersion": "0", "involvedObject.resourceVersion": "0",
"involvedObject.fieldPath": "", "involvedObject.fieldPath": "",
"reason": "ForTesting", "reason": "ForTesting",
......
...@@ -30,7 +30,7 @@ import ( ...@@ -30,7 +30,7 @@ import (
) )
func newStorage(t *testing.T) (*ScaleREST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*ScaleREST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "experimental")
return NewStorage(etcdStorage).Scale, fakeClient return NewStorage(etcdStorage).Scale, fakeClient
} }
...@@ -82,7 +82,7 @@ func TestGet(t *testing.T) { ...@@ -82,7 +82,7 @@ func TestGet(t *testing.T) {
ctx := api.WithNamespace(api.NewContext(), "test") ctx := api.WithNamespace(api.NewContext(), "test")
key := etcdtest.AddPrefix("/controllers/test/foo") key := etcdtest.AddPrefix("/controllers/test/foo")
if _, err := fakeClient.Set(key, runtime.EncodeOrDie(testapi.Codec(), &validController), 0); err != nil { if _, err := fakeClient.Set(key, runtime.EncodeOrDie(testapi.Experimental.Codec(), &validController), 0); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
...@@ -102,7 +102,7 @@ func TestUpdate(t *testing.T) { ...@@ -102,7 +102,7 @@ func TestUpdate(t *testing.T) {
ctx := api.WithNamespace(api.NewContext(), "test") ctx := api.WithNamespace(api.NewContext(), "test")
key := etcdtest.AddPrefix("/controllers/test/foo") key := etcdtest.AddPrefix("/controllers/test/foo")
if _, err := fakeClient.Set(key, runtime.EncodeOrDie(testapi.Codec(), &validController), 0); err != nil { if _, err := fakeClient.Set(key, runtime.EncodeOrDie(testapi.Experimental.Codec(), &validController), 0); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
replicas := 12 replicas := 12
...@@ -122,7 +122,7 @@ func TestUpdate(t *testing.T) { ...@@ -122,7 +122,7 @@ func TestUpdate(t *testing.T) {
} }
var controller api.ReplicationController var controller api.ReplicationController
testapi.Codec().DecodeInto([]byte(response.Node.Value), &controller) testapi.Experimental.Codec().DecodeInto([]byte(response.Node.Value), &controller)
if controller.Spec.Replicas != replicas { if controller.Spec.Replicas != replicas {
t.Errorf("wrong replicas count expected: %d got: %d", replicas, controller.Spec.Replicas) t.Errorf("wrong replicas count expected: %d got: %d", replicas, controller.Spec.Replicas)
} }
......
...@@ -70,7 +70,7 @@ func hasCreated(t *testing.T, pod *api.Pod) func(runtime.Object) bool { ...@@ -70,7 +70,7 @@ func hasCreated(t *testing.T, pod *api.Pod) func(runtime.Object) bool {
func NewTestGenericEtcdRegistry(t *testing.T) (*tools.FakeEtcdClient, *Etcd) { func NewTestGenericEtcdRegistry(t *testing.T) (*tools.FakeEtcdClient, *Etcd) {
f := tools.NewFakeEtcdClient(t) f := tools.NewFakeEtcdClient(t)
f.TestIndex = true f.TestIndex = true
s := etcdstorage.NewEtcdStorage(f, testapi.Codec(), etcdtest.PathPrefix()) s := etcdstorage.NewEtcdStorage(f, testapi.Default.Codec(), etcdtest.PathPrefix())
strategy := &testRESTStrategy{api.Scheme, api.SimpleNameGenerator, true, false, true} strategy := &testRESTStrategy{api.Scheme, api.SimpleNameGenerator, true, false, true}
podPrefix := "/pods" podPrefix := "/pods"
return f, &Etcd{ return f, &Etcd{
...@@ -135,14 +135,14 @@ func TestEtcdList(t *testing.T) { ...@@ -135,14 +135,14 @@ func TestEtcdList(t *testing.T) {
singleElemListResp := &etcd.Response{ singleElemListResp := &etcd.Response{
Node: &etcd.Node{ Node: &etcd.Node{
Value: runtime.EncodeOrDie(testapi.Codec(), podA), Value: runtime.EncodeOrDie(testapi.Default.Codec(), podA),
}, },
} }
normalListResp := &etcd.Response{ normalListResp := &etcd.Response{
Node: &etcd.Node{ Node: &etcd.Node{
Nodes: []*etcd.Node{ Nodes: []*etcd.Node{
{Value: runtime.EncodeOrDie(testapi.Codec(), podA)}, {Value: runtime.EncodeOrDie(testapi.Default.Codec(), podA)},
{Value: runtime.EncodeOrDie(testapi.Codec(), podB)}, {Value: runtime.EncodeOrDie(testapi.Default.Codec(), podB)},
}, },
}, },
} }
...@@ -243,7 +243,7 @@ func TestEtcdCreate(t *testing.T) { ...@@ -243,7 +243,7 @@ func TestEtcdCreate(t *testing.T) {
nodeWithPodA := tools.EtcdResponseWithError{ nodeWithPodA := tools.EtcdResponseWithError{
R: &etcd.Response{ R: &etcd.Response{
Node: &etcd.Node{ Node: &etcd.Node{
Value: runtime.EncodeOrDie(testapi.Codec(), podA), Value: runtime.EncodeOrDie(testapi.Default.Codec(), podA),
ModifiedIndex: 1, ModifiedIndex: 1,
CreatedIndex: 1, CreatedIndex: 1,
}, },
...@@ -323,7 +323,7 @@ func TestEtcdUpdate(t *testing.T) { ...@@ -323,7 +323,7 @@ func TestEtcdUpdate(t *testing.T) {
nodeWithPodA := tools.EtcdResponseWithError{ nodeWithPodA := tools.EtcdResponseWithError{
R: &etcd.Response{ R: &etcd.Response{
Node: &etcd.Node{ Node: &etcd.Node{
Value: runtime.EncodeOrDie(testapi.Codec(), podA), Value: runtime.EncodeOrDie(testapi.Default.Codec(), podA),
ModifiedIndex: 1, ModifiedIndex: 1,
CreatedIndex: 1, CreatedIndex: 1,
}, },
...@@ -334,7 +334,7 @@ func TestEtcdUpdate(t *testing.T) { ...@@ -334,7 +334,7 @@ func TestEtcdUpdate(t *testing.T) {
newerNodeWithPodA := tools.EtcdResponseWithError{ newerNodeWithPodA := tools.EtcdResponseWithError{
R: &etcd.Response{ R: &etcd.Response{
Node: &etcd.Node{ Node: &etcd.Node{
Value: runtime.EncodeOrDie(testapi.Codec(), podA), Value: runtime.EncodeOrDie(testapi.Default.Codec(), podA),
ModifiedIndex: 2, ModifiedIndex: 2,
CreatedIndex: 1, CreatedIndex: 1,
}, },
...@@ -345,7 +345,7 @@ func TestEtcdUpdate(t *testing.T) { ...@@ -345,7 +345,7 @@ func TestEtcdUpdate(t *testing.T) {
nodeWithPodB := tools.EtcdResponseWithError{ nodeWithPodB := tools.EtcdResponseWithError{
R: &etcd.Response{ R: &etcd.Response{
Node: &etcd.Node{ Node: &etcd.Node{
Value: runtime.EncodeOrDie(testapi.Codec(), podB), Value: runtime.EncodeOrDie(testapi.Default.Codec(), podB),
ModifiedIndex: 1, ModifiedIndex: 1,
CreatedIndex: 1, CreatedIndex: 1,
}, },
...@@ -356,7 +356,7 @@ func TestEtcdUpdate(t *testing.T) { ...@@ -356,7 +356,7 @@ func TestEtcdUpdate(t *testing.T) {
nodeWithPodAWithResourceVersion := tools.EtcdResponseWithError{ nodeWithPodAWithResourceVersion := tools.EtcdResponseWithError{
R: &etcd.Response{ R: &etcd.Response{
Node: &etcd.Node{ Node: &etcd.Node{
Value: runtime.EncodeOrDie(testapi.Codec(), podAWithResourceVersion), Value: runtime.EncodeOrDie(testapi.Default.Codec(), podAWithResourceVersion),
ModifiedIndex: 3, ModifiedIndex: 3,
CreatedIndex: 1, CreatedIndex: 1,
}, },
...@@ -452,7 +452,7 @@ func TestEtcdGet(t *testing.T) { ...@@ -452,7 +452,7 @@ func TestEtcdGet(t *testing.T) {
nodeWithPodA := tools.EtcdResponseWithError{ nodeWithPodA := tools.EtcdResponseWithError{
R: &etcd.Response{ R: &etcd.Response{
Node: &etcd.Node{ Node: &etcd.Node{
Value: runtime.EncodeOrDie(testapi.Codec(), podA), Value: runtime.EncodeOrDie(testapi.Default.Codec(), podA),
ModifiedIndex: 1, ModifiedIndex: 1,
CreatedIndex: 1, CreatedIndex: 1,
}, },
...@@ -508,7 +508,7 @@ func TestEtcdDelete(t *testing.T) { ...@@ -508,7 +508,7 @@ func TestEtcdDelete(t *testing.T) {
nodeWithPodA := tools.EtcdResponseWithError{ nodeWithPodA := tools.EtcdResponseWithError{
R: &etcd.Response{ R: &etcd.Response{
Node: &etcd.Node{ Node: &etcd.Node{
Value: runtime.EncodeOrDie(testapi.Codec(), podA), Value: runtime.EncodeOrDie(testapi.Default.Codec(), podA),
ModifiedIndex: 1, ModifiedIndex: 1,
CreatedIndex: 1, CreatedIndex: 1,
}, },
...@@ -576,7 +576,7 @@ func TestEtcdWatch(t *testing.T) { ...@@ -576,7 +576,7 @@ func TestEtcdWatch(t *testing.T) {
respWithPodA := &etcd.Response{ respWithPodA := &etcd.Response{
Node: &etcd.Node{ Node: &etcd.Node{
Key: "/registry/pods/default/foo", Key: "/registry/pods/default/foo",
Value: runtime.EncodeOrDie(testapi.Codec(), podA), Value: runtime.EncodeOrDie(testapi.Default.Codec(), podA),
ModifiedIndex: 1, ModifiedIndex: 1,
CreatedIndex: 1, CreatedIndex: 1,
}, },
......
...@@ -32,7 +32,7 @@ import ( ...@@ -32,7 +32,7 @@ import (
) )
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "experimental")
return NewREST(etcdStorage), fakeClient return NewREST(etcdStorage), fakeClient
} }
......
...@@ -29,7 +29,7 @@ import ( ...@@ -29,7 +29,7 @@ import (
) )
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
return NewREST(etcdStorage), fakeClient return NewREST(etcdStorage), fakeClient
} }
......
...@@ -37,7 +37,7 @@ func (fakeConnectionInfoGetter) GetConnectionInfo(host string) (string, uint, ht ...@@ -37,7 +37,7 @@ func (fakeConnectionInfoGetter) GetConnectionInfo(host string) (string, uint, ht
} }
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
storage, _ := NewREST(etcdStorage, false, fakeConnectionInfoGetter{}) storage, _ := NewREST(etcdStorage, false, fakeConnectionInfoGetter{})
return storage, fakeClient return storage, fakeClient
} }
......
...@@ -31,7 +31,7 @@ import ( ...@@ -31,7 +31,7 @@ import (
) )
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
storage, _, _ := NewREST(etcdStorage) storage, _, _ := NewREST(etcdStorage)
return storage, fakeClient return storage, fakeClient
} }
...@@ -140,7 +140,7 @@ func TestDeleteNamespaceWithIncompleteFinalizers(t *testing.T) { ...@@ -140,7 +140,7 @@ func TestDeleteNamespaceWithIncompleteFinalizers(t *testing.T) {
}, },
Status: api.NamespaceStatus{Phase: api.NamespaceActive}, Status: api.NamespaceStatus{Phase: api.NamespaceActive},
} }
if _, err := fakeClient.Set(key, runtime.EncodeOrDie(testapi.Codec(), namespace), 0); err != nil { if _, err := fakeClient.Set(key, runtime.EncodeOrDie(testapi.Default.Codec(), namespace), 0); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
if _, err := storage.Delete(ctx, "foo", nil); err == nil { if _, err := storage.Delete(ctx, "foo", nil); err == nil {
...@@ -163,7 +163,7 @@ func TestDeleteNamespaceWithCompleteFinalizers(t *testing.T) { ...@@ -163,7 +163,7 @@ func TestDeleteNamespaceWithCompleteFinalizers(t *testing.T) {
}, },
Status: api.NamespaceStatus{Phase: api.NamespaceActive}, Status: api.NamespaceStatus{Phase: api.NamespaceActive},
} }
if _, err := fakeClient.Set(key, runtime.EncodeOrDie(testapi.Codec(), namespace), 0); err != nil { if _, err := fakeClient.Set(key, runtime.EncodeOrDie(testapi.Default.Codec(), namespace), 0); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
if _, err := storage.Delete(ctx, "foo", nil); err != nil { if _, err := storage.Delete(ctx, "foo", nil); err != nil {
......
...@@ -32,7 +32,7 @@ import ( ...@@ -32,7 +32,7 @@ import (
) )
func newStorage(t *testing.T) (*REST, *StatusREST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*REST, *StatusREST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
storage, statusStorage := NewREST(etcdStorage) storage, statusStorage := NewREST(etcdStorage)
return storage, statusStorage, fakeClient return storage, statusStorage, fakeClient
} }
...@@ -148,7 +148,7 @@ func TestUpdateStatus(t *testing.T) { ...@@ -148,7 +148,7 @@ func TestUpdateStatus(t *testing.T) {
key, _ := storage.KeyFunc(ctx, "foo") key, _ := storage.KeyFunc(ctx, "foo")
key = etcdtest.AddPrefix(key) key = etcdtest.AddPrefix(key)
pvStart := validNewPersistentVolume("foo") pvStart := validNewPersistentVolume("foo")
fakeClient.Set(key, runtime.EncodeOrDie(testapi.Codec(), pvStart), 0) fakeClient.Set(key, runtime.EncodeOrDie(testapi.Default.Codec(), pvStart), 0)
pvIn := &api.PersistentVolume{ pvIn := &api.PersistentVolume{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
......
...@@ -32,7 +32,7 @@ import ( ...@@ -32,7 +32,7 @@ import (
) )
func newStorage(t *testing.T) (*REST, *StatusREST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*REST, *StatusREST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
storage, statusStorage := NewREST(etcdStorage) storage, statusStorage := NewREST(etcdStorage)
return storage, statusStorage, fakeClient return storage, statusStorage, fakeClient
} }
...@@ -141,7 +141,7 @@ func TestUpdateStatus(t *testing.T) { ...@@ -141,7 +141,7 @@ func TestUpdateStatus(t *testing.T) {
key, _ := storage.KeyFunc(ctx, "foo") key, _ := storage.KeyFunc(ctx, "foo")
key = etcdtest.AddPrefix(key) key = etcdtest.AddPrefix(key)
pvcStart := validNewPersistentVolumeClaim("foo", api.NamespaceDefault) pvcStart := validNewPersistentVolumeClaim("foo", api.NamespaceDefault)
fakeClient.Set(key, runtime.EncodeOrDie(testapi.Codec(), pvcStart), 0) fakeClient.Set(key, runtime.EncodeOrDie(testapi.Default.Codec(), pvcStart), 0)
pvc := &api.PersistentVolumeClaim{ pvc := &api.PersistentVolumeClaim{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
......
...@@ -37,7 +37,7 @@ import ( ...@@ -37,7 +37,7 @@ import (
) )
func newStorage(t *testing.T) (*REST, *BindingREST, *StatusREST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*REST, *BindingREST, *StatusREST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
storage := NewStorage(etcdStorage, false, nil) storage := NewStorage(etcdStorage, false, nil)
return storage.Pod, storage.Binding, storage.Status, fakeClient return storage.Pod, storage.Binding, storage.Status, fakeClient
} }
...@@ -256,7 +256,7 @@ func TestResourceLocation(t *testing.T) { ...@@ -256,7 +256,7 @@ func TestResourceLocation(t *testing.T) {
storage, _, _, fakeClient := newStorage(t) storage, _, _, fakeClient := newStorage(t)
key, _ := storage.KeyFunc(ctx, tc.pod.Name) key, _ := storage.KeyFunc(ctx, tc.pod.Name)
key = etcdtest.AddPrefix(key) key = etcdtest.AddPrefix(key)
if _, err := fakeClient.Set(key, runtime.EncodeOrDie(testapi.Codec(), &tc.pod), 0); err != nil { if _, err := fakeClient.Set(key, runtime.EncodeOrDie(testapi.Default.Codec(), &tc.pod), 0); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
...@@ -338,7 +338,7 @@ func TestEtcdCreate(t *testing.T) { ...@@ -338,7 +338,7 @@ func TestEtcdCreate(t *testing.T) {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }
var pod api.Pod var pod api.Pod
err = testapi.Codec().DecodeInto([]byte(resp.Node.Value), &pod) err = testapi.Default.Codec().DecodeInto([]byte(resp.Node.Value), &pod)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -424,7 +424,7 @@ func TestEtcdCreateWithContainersNotFound(t *testing.T) { ...@@ -424,7 +424,7 @@ func TestEtcdCreateWithContainersNotFound(t *testing.T) {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }
var pod api.Pod var pod api.Pod
err = testapi.Codec().DecodeInto([]byte(resp.Node.Value), &pod) err = testapi.Default.Codec().DecodeInto([]byte(resp.Node.Value), &pod)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -495,7 +495,7 @@ func TestEtcdCreateWithExistingContainers(t *testing.T) { ...@@ -495,7 +495,7 @@ func TestEtcdCreateWithExistingContainers(t *testing.T) {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }
var pod api.Pod var pod api.Pod
err = testapi.Codec().DecodeInto([]byte(resp.Node.Value), &pod) err = testapi.Default.Codec().DecodeInto([]byte(resp.Node.Value), &pod)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -578,7 +578,7 @@ func TestEtcdUpdateNotScheduled(t *testing.T) { ...@@ -578,7 +578,7 @@ func TestEtcdUpdateNotScheduled(t *testing.T) {
key, _ := storage.KeyFunc(ctx, "foo") key, _ := storage.KeyFunc(ctx, "foo")
key = etcdtest.AddPrefix(key) key = etcdtest.AddPrefix(key)
fakeClient.Set(key, runtime.EncodeOrDie(testapi.Codec(), validNewPod()), 1) fakeClient.Set(key, runtime.EncodeOrDie(testapi.Default.Codec(), validNewPod()), 1)
podIn := validChangedPod() podIn := validChangedPod()
_, _, err := storage.Update(ctx, podIn) _, _, err := storage.Update(ctx, podIn)
...@@ -590,7 +590,7 @@ func TestEtcdUpdateNotScheduled(t *testing.T) { ...@@ -590,7 +590,7 @@ func TestEtcdUpdateNotScheduled(t *testing.T) {
t.Fatalf("Unexpected error: %v", err) t.Fatalf("Unexpected error: %v", err)
} }
podOut := &api.Pod{} podOut := &api.Pod{}
testapi.Codec().DecodeInto([]byte(response.Node.Value), podOut) testapi.Default.Codec().DecodeInto([]byte(response.Node.Value), podOut)
if !api.Semantic.DeepEqual(podOut, podIn) { if !api.Semantic.DeepEqual(podOut, podIn) {
t.Errorf("objects differ: %v", util.ObjectDiff(podOut, podIn)) t.Errorf("objects differ: %v", util.ObjectDiff(podOut, podIn))
} }
...@@ -603,7 +603,7 @@ func TestEtcdUpdateScheduled(t *testing.T) { ...@@ -603,7 +603,7 @@ func TestEtcdUpdateScheduled(t *testing.T) {
key, _ := storage.KeyFunc(ctx, "foo") key, _ := storage.KeyFunc(ctx, "foo")
key = etcdtest.AddPrefix(key) key = etcdtest.AddPrefix(key)
fakeClient.Set(key, runtime.EncodeOrDie(testapi.Codec(), &api.Pod{ fakeClient.Set(key, runtime.EncodeOrDie(testapi.Default.Codec(), &api.Pod{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Name: "foo", Name: "foo",
Namespace: api.NamespaceDefault, Namespace: api.NamespaceDefault,
...@@ -655,7 +655,7 @@ func TestEtcdUpdateScheduled(t *testing.T) { ...@@ -655,7 +655,7 @@ func TestEtcdUpdateScheduled(t *testing.T) {
t.Fatalf("Unexpected error: %v", err) t.Fatalf("Unexpected error: %v", err)
} }
var podOut api.Pod var podOut api.Pod
testapi.Codec().DecodeInto([]byte(response.Node.Value), &podOut) testapi.Default.Codec().DecodeInto([]byte(response.Node.Value), &podOut)
if !api.Semantic.DeepEqual(podOut, podIn) { if !api.Semantic.DeepEqual(podOut, podIn) {
t.Errorf("expected: %#v, got: %#v", podOut, podIn) t.Errorf("expected: %#v, got: %#v", podOut, podIn)
} }
...@@ -684,7 +684,7 @@ func TestEtcdUpdateStatus(t *testing.T) { ...@@ -684,7 +684,7 @@ func TestEtcdUpdateStatus(t *testing.T) {
}, },
}, },
} }
fakeClient.Set(key, runtime.EncodeOrDie(testapi.Codec(), &podStart), 0) fakeClient.Set(key, runtime.EncodeOrDie(testapi.Default.Codec(), &podStart), 0)
podIn := api.Pod{ podIn := api.Pod{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
......
...@@ -28,7 +28,7 @@ import ( ...@@ -28,7 +28,7 @@ import (
) )
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
return NewREST(etcdStorage), fakeClient return NewREST(etcdStorage), fakeClient
} }
......
...@@ -17,6 +17,7 @@ limitations under the License. ...@@ -17,6 +17,7 @@ limitations under the License.
package registrytest package registrytest
import ( import (
"fmt"
"testing" "testing"
"github.com/coreos/go-etcd/etcd" "github.com/coreos/go-etcd/etcd"
...@@ -34,10 +35,10 @@ import ( ...@@ -34,10 +35,10 @@ import (
"k8s.io/kubernetes/pkg/tools/etcdtest" "k8s.io/kubernetes/pkg/tools/etcdtest"
) )
func NewEtcdStorage(t *testing.T) (storage.Interface, *tools.FakeEtcdClient) { func NewEtcdStorage(t *testing.T, group string) (storage.Interface, *tools.FakeEtcdClient) {
fakeClient := tools.NewFakeEtcdClient(t) fakeClient := tools.NewFakeEtcdClient(t)
fakeClient.TestIndex = true fakeClient.TestIndex = true
etcdStorage := etcdstorage.NewEtcdStorage(fakeClient, testapi.Codec(), etcdtest.PathPrefix()) etcdStorage := etcdstorage.NewEtcdStorage(fakeClient, testapi.Groups[group].Codec(), etcdtest.PathPrefix())
return etcdStorage, fakeClient return etcdStorage, fakeClient
} }
...@@ -149,6 +150,27 @@ func (t *Tester) TestWatch(valid runtime.Object, labelsPass, labelsFail []labels ...@@ -149,6 +150,27 @@ func (t *Tester) TestWatch(valid runtime.Object, labelsPass, labelsFail []labels
} }
// ============================================================================= // =============================================================================
// get codec based on runtime.Object
func getCodec(obj runtime.Object) (runtime.Codec, error) {
_, kind, err := api.Scheme.ObjectVersionAndKind(obj)
if err != nil {
return nil, fmt.Errorf("unexpected encoding error: %v", err)
}
// TODO: caesarxuchao: we should detect which group an object belongs to
// by using the version returned by Schem.ObjectVersionAndKind() once we
// split the schemes for internal objects.
// TODO: caesarxuchao: we should add a map from kind to group in Scheme.
var codec runtime.Codec
if api.Scheme.Recognizes(testapi.Default.GroupAndVersion(), kind) {
codec = testapi.Default.Codec()
} else if api.Scheme.Recognizes(testapi.Experimental.GroupAndVersion(), kind) {
codec = testapi.Experimental.Codec()
} else {
return nil, fmt.Errorf("unexpected kind: %v", kind)
}
return codec, nil
}
// Helper functions // Helper functions
func (t *Tester) getObject(ctx api.Context, obj runtime.Object) (runtime.Object, error) { func (t *Tester) getObject(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
...@@ -166,7 +188,12 @@ func (t *Tester) getObject(ctx api.Context, obj runtime.Object) (runtime.Object, ...@@ -166,7 +188,12 @@ func (t *Tester) getObject(ctx api.Context, obj runtime.Object) (runtime.Object,
return nil, err return nil, err
} }
result := t.storage.NewFunc() result := t.storage.NewFunc()
if err := testapi.Codec().DecodeInto([]byte(resp.Node.Value), result); err != nil {
codec, err := getCodec(obj)
if err != nil {
return nil, err
}
if err := codec.DecodeInto([]byte(resp.Node.Value), result); err != nil {
return nil, err return nil, err
} }
return result, nil return result, nil
...@@ -182,7 +209,12 @@ func (t *Tester) setObject(ctx api.Context, obj runtime.Object) error { ...@@ -182,7 +209,12 @@ func (t *Tester) setObject(ctx api.Context, obj runtime.Object) error {
return err return err
} }
key = etcdtest.AddPrefix(key) key = etcdtest.AddPrefix(key)
_, err = t.fakeClient.Set(key, runtime.EncodeOrDie(testapi.Codec(), obj), 0)
codec, err := getCodec(obj)
if err != nil {
return err
}
_, err = t.fakeClient.Set(key, runtime.EncodeOrDie(codec, obj), 0)
return err return err
} }
...@@ -193,8 +225,9 @@ func (t *Tester) setObjectsForList(objects []runtime.Object) []runtime.Object { ...@@ -193,8 +225,9 @@ func (t *Tester) setObjectsForList(objects []runtime.Object) []runtime.Object {
if len(objects) > 0 { if len(objects) > 0 {
nodes := make([]*etcd.Node, len(objects)) nodes := make([]*etcd.Node, len(objects))
for i, obj := range objects { for i, obj := range objects {
encoded := runtime.EncodeOrDie(testapi.Codec(), obj) codec, _ := getCodec(obj)
decoded, _ := testapi.Codec().Decode([]byte(encoded)) encoded := runtime.EncodeOrDie(codec, obj)
decoded, _ := codec.Decode([]byte(encoded))
nodes[i] = &etcd.Node{Value: encoded} nodes[i] = &etcd.Node{Value: encoded}
result[i] = decoded result[i] = decoded
} }
...@@ -224,7 +257,11 @@ func (t *Tester) injectWatchError(err error) { ...@@ -224,7 +257,11 @@ func (t *Tester) injectWatchError(err error) {
} }
func (t *Tester) emitObject(obj runtime.Object, action string) error { func (t *Tester) emitObject(obj runtime.Object, action string) error {
encoded, err := testapi.Codec().Encode(obj) codec, err := getCodec(obj)
if err != nil {
return err
}
encoded, err := codec.Encode(obj)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -33,7 +33,7 @@ import ( ...@@ -33,7 +33,7 @@ import (
) )
func newStorage(t *testing.T) (*REST, *StatusREST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*REST, *StatusREST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
storage, statusStorage := NewREST(etcdStorage) storage, statusStorage := NewREST(etcdStorage)
return storage, statusStorage, fakeClient return storage, statusStorage, fakeClient
} }
...@@ -152,7 +152,7 @@ func TestUpdateStatus(t *testing.T) { ...@@ -152,7 +152,7 @@ func TestUpdateStatus(t *testing.T) {
key, _ := storage.KeyFunc(ctx, "foo") key, _ := storage.KeyFunc(ctx, "foo")
key = etcdtest.AddPrefix(key) key = etcdtest.AddPrefix(key)
resourcequotaStart := validNewResourceQuota() resourcequotaStart := validNewResourceQuota()
fakeClient.Set(key, runtime.EncodeOrDie(testapi.Codec(), resourcequotaStart), 0) fakeClient.Set(key, runtime.EncodeOrDie(testapi.Default.Codec(), resourcequotaStart), 0)
resourcequotaIn := &api.ResourceQuota{ resourcequotaIn := &api.ResourceQuota{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
......
...@@ -28,7 +28,7 @@ import ( ...@@ -28,7 +28,7 @@ import (
) )
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
return NewREST(etcdStorage), fakeClient return NewREST(etcdStorage), fakeClient
} }
......
...@@ -30,7 +30,7 @@ import ( ...@@ -30,7 +30,7 @@ import (
) )
func newStorage(t *testing.T) (*Etcd, *tools.FakeEtcdClient, allocator.Interface) { func newStorage(t *testing.T) (*Etcd, *tools.FakeEtcdClient, allocator.Interface) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
mem := allocator.NewAllocationMap(100, "rangeSpecValue") mem := allocator.NewAllocationMap(100, "rangeSpecValue")
etcd := NewEtcd(mem, "/ranges/serviceips", "serviceipallocation", etcdStorage) etcd := NewEtcd(mem, "/ranges/serviceips", "serviceipallocation", etcdStorage)
return etcd, fakeClient, mem return etcd, fakeClient, mem
...@@ -57,7 +57,7 @@ func TestEmpty(t *testing.T) { ...@@ -57,7 +57,7 @@ func TestEmpty(t *testing.T) {
func TestStore(t *testing.T) { func TestStore(t *testing.T) {
storage, fakeClient, backing := newStorage(t) storage, fakeClient, backing := newStorage(t)
if _, err := fakeClient.Set(key(), runtime.EncodeOrDie(testapi.Codec(), validNewRangeAllocation()), 0); err != nil { if _, err := fakeClient.Set(key(), runtime.EncodeOrDie(testapi.Default.Codec(), validNewRangeAllocation()), 0); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
......
...@@ -29,7 +29,7 @@ import ( ...@@ -29,7 +29,7 @@ import (
) )
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
return NewREST(etcdStorage), fakeClient return NewREST(etcdStorage), fakeClient
} }
......
...@@ -33,7 +33,7 @@ import ( ...@@ -33,7 +33,7 @@ import (
) )
func newStorage(t *testing.T) (*tools.FakeEtcdClient, ipallocator.Interface, allocator.Interface) { func newStorage(t *testing.T) (*tools.FakeEtcdClient, ipallocator.Interface, allocator.Interface) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
_, cidr, err := net.ParseCIDR("192.168.1.0/24") _, cidr, err := net.ParseCIDR("192.168.1.0/24")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
...@@ -79,7 +79,7 @@ func TestErrors(t *testing.T) { ...@@ -79,7 +79,7 @@ func TestErrors(t *testing.T) {
func TestStore(t *testing.T) { func TestStore(t *testing.T) {
fakeClient, storage, backing := newStorage(t) fakeClient, storage, backing := newStorage(t)
if _, err := fakeClient.Set(key(), runtime.EncodeOrDie(testapi.Codec(), validNewRangeAllocation()), 0); err != nil { if _, err := fakeClient.Set(key(), runtime.EncodeOrDie(testapi.Default.Codec(), validNewRangeAllocation()), 0); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
......
...@@ -28,7 +28,7 @@ import ( ...@@ -28,7 +28,7 @@ import (
) )
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
return NewREST(etcdStorage), fakeClient return NewREST(etcdStorage), fakeClient
} }
......
...@@ -31,7 +31,7 @@ import ( ...@@ -31,7 +31,7 @@ import (
) )
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "experimental")
return NewREST(etcdStorage), fakeClient return NewREST(etcdStorage), fakeClient
} }
......
...@@ -31,7 +31,7 @@ import ( ...@@ -31,7 +31,7 @@ import (
) )
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) { func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t) etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "experimental")
return NewREST(etcdStorage, "foo", "bar"), fakeClient return NewREST(etcdStorage, "foo", "bar"), fakeClient
} }
......
...@@ -137,7 +137,7 @@ func TestDecodeList(t *testing.T) { ...@@ -137,7 +137,7 @@ func TestDecodeList(t *testing.T) {
pl := &api.List{ pl := &api.List{
Items: []runtime.Object{ Items: []runtime.Object{
&api.Pod{ObjectMeta: api.ObjectMeta{Name: "1"}}, &api.Pod{ObjectMeta: api.ObjectMeta{Name: "1"}},
&runtime.Unknown{TypeMeta: runtime.TypeMeta{Kind: "Pod", APIVersion: testapi.Version()}, RawJSON: []byte(`{"kind":"Pod","apiVersion":"` + testapi.Version() + `","metadata":{"name":"test"}}`)}, &runtime.Unknown{TypeMeta: runtime.TypeMeta{Kind: "Pod", APIVersion: testapi.Default.Version()}, RawJSON: []byte(`{"kind":"Pod","apiVersion":"` + testapi.Default.Version() + `","metadata":{"name":"test"}}`)},
&runtime.Unstructured{TypeMeta: runtime.TypeMeta{Kind: "Foo", APIVersion: "Bar"}, Object: map[string]interface{}{"test": "value"}}, &runtime.Unstructured{TypeMeta: runtime.TypeMeta{Kind: "Foo", APIVersion: "Bar"}, Object: map[string]interface{}{"test": "value"}},
}, },
} }
......
...@@ -26,7 +26,7 @@ import ( ...@@ -26,7 +26,7 @@ import (
) )
func TestDecodeUnstructured(t *testing.T) { func TestDecodeUnstructured(t *testing.T) {
version := testapi.Version() version := testapi.Default.Version()
rawJson := fmt.Sprintf(`{"kind":"Pod","apiVersion":"%s","metadata":{"name":"test"}}`, version) rawJson := fmt.Sprintf(`{"kind":"Pod","apiVersion":"%s","metadata":{"name":"test"}}`, version)
pl := &api.List{ pl := &api.List{
Items: []runtime.Object{ Items: []runtime.Object{
......
...@@ -43,7 +43,7 @@ func newTestCacher(client tools.EtcdClient) *storage.Cacher { ...@@ -43,7 +43,7 @@ func newTestCacher(client tools.EtcdClient) *storage.Cacher {
config := storage.CacherConfig{ config := storage.CacherConfig{
CacheCapacity: 10, CacheCapacity: 10,
Versioner: etcdstorage.APIObjectVersioner{}, Versioner: etcdstorage.APIObjectVersioner{},
Storage: etcdstorage.NewEtcdStorage(client, testapi.Codec(), etcdtest.PathPrefix()), Storage: etcdstorage.NewEtcdStorage(client, testapi.Default.Codec(), etcdtest.PathPrefix()),
Type: &api.Pod{}, Type: &api.Pod{},
ResourcePrefix: prefix, ResourcePrefix: prefix,
KeyFunc: func(obj runtime.Object) (string, error) { return storage.NamespaceKeyFunc(prefix, obj) }, KeyFunc: func(obj runtime.Object) (string, error) { return storage.NamespaceKeyFunc(prefix, obj) },
...@@ -94,7 +94,7 @@ func TestListFromMemory(t *testing.T) { ...@@ -94,7 +94,7 @@ func TestListFromMemory(t *testing.T) {
{ {
Action: "create", Action: "create",
Node: &etcd.Node{ Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)), Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1, CreatedIndex: 1,
ModifiedIndex: 1, ModifiedIndex: 1,
}, },
...@@ -102,7 +102,7 @@ func TestListFromMemory(t *testing.T) { ...@@ -102,7 +102,7 @@ func TestListFromMemory(t *testing.T) {
{ {
Action: "create", Action: "create",
Node: &etcd.Node{ Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podBar)), Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podBar)),
CreatedIndex: 2, CreatedIndex: 2,
ModifiedIndex: 2, ModifiedIndex: 2,
}, },
...@@ -110,7 +110,7 @@ func TestListFromMemory(t *testing.T) { ...@@ -110,7 +110,7 @@ func TestListFromMemory(t *testing.T) {
{ {
Action: "create", Action: "create",
Node: &etcd.Node{ Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podBaz)), Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podBaz)),
CreatedIndex: 3, CreatedIndex: 3,
ModifiedIndex: 3, ModifiedIndex: 3,
}, },
...@@ -118,12 +118,12 @@ func TestListFromMemory(t *testing.T) { ...@@ -118,12 +118,12 @@ func TestListFromMemory(t *testing.T) {
{ {
Action: "set", Action: "set",
Node: &etcd.Node{ Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFooPrime)), Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFooPrime)),
CreatedIndex: 1, CreatedIndex: 1,
ModifiedIndex: 4, ModifiedIndex: 4,
}, },
PrevNode: &etcd.Node{ PrevNode: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)), Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1, CreatedIndex: 1,
ModifiedIndex: 1, ModifiedIndex: 1,
}, },
...@@ -135,7 +135,7 @@ func TestListFromMemory(t *testing.T) { ...@@ -135,7 +135,7 @@ func TestListFromMemory(t *testing.T) {
ModifiedIndex: 5, ModifiedIndex: 5,
}, },
PrevNode: &etcd.Node{ PrevNode: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podBar)), Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podBar)),
CreatedIndex: 1, CreatedIndex: 1,
ModifiedIndex: 1, ModifiedIndex: 1,
}, },
...@@ -210,7 +210,7 @@ func TestWatch(t *testing.T) { ...@@ -210,7 +210,7 @@ func TestWatch(t *testing.T) {
etcdResponse: &etcd.Response{ etcdResponse: &etcd.Response{
Action: "create", Action: "create",
Node: &etcd.Node{ Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)), Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1, CreatedIndex: 1,
ModifiedIndex: 1, ModifiedIndex: 1,
}, },
...@@ -223,7 +223,7 @@ func TestWatch(t *testing.T) { ...@@ -223,7 +223,7 @@ func TestWatch(t *testing.T) {
etcdResponse: &etcd.Response{ etcdResponse: &etcd.Response{
Action: "create", Action: "create",
Node: &etcd.Node{ Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podBar)), Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podBar)),
CreatedIndex: 2, CreatedIndex: 2,
ModifiedIndex: 2, ModifiedIndex: 2,
}, },
...@@ -236,12 +236,12 @@ func TestWatch(t *testing.T) { ...@@ -236,12 +236,12 @@ func TestWatch(t *testing.T) {
etcdResponse: &etcd.Response{ etcdResponse: &etcd.Response{
Action: "set", Action: "set",
Node: &etcd.Node{ Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)), Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1, CreatedIndex: 1,
ModifiedIndex: 3, ModifiedIndex: 3,
}, },
PrevNode: &etcd.Node{ PrevNode: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)), Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1, CreatedIndex: 1,
ModifiedIndex: 1, ModifiedIndex: 1,
}, },
...@@ -326,7 +326,7 @@ func TestFiltering(t *testing.T) { ...@@ -326,7 +326,7 @@ func TestFiltering(t *testing.T) {
etcdResponse: &etcd.Response{ etcdResponse: &etcd.Response{
Action: "create", Action: "create",
Node: &etcd.Node{ Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)), Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1, CreatedIndex: 1,
ModifiedIndex: 1, ModifiedIndex: 1,
}, },
...@@ -339,12 +339,12 @@ func TestFiltering(t *testing.T) { ...@@ -339,12 +339,12 @@ func TestFiltering(t *testing.T) {
etcdResponse: &etcd.Response{ etcdResponse: &etcd.Response{
Action: "set", Action: "set",
Node: &etcd.Node{ Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFooFiltered)), Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFooFiltered)),
CreatedIndex: 1, CreatedIndex: 1,
ModifiedIndex: 2, ModifiedIndex: 2,
}, },
PrevNode: &etcd.Node{ PrevNode: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)), Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1, CreatedIndex: 1,
ModifiedIndex: 1, ModifiedIndex: 1,
}, },
...@@ -358,12 +358,12 @@ func TestFiltering(t *testing.T) { ...@@ -358,12 +358,12 @@ func TestFiltering(t *testing.T) {
etcdResponse: &etcd.Response{ etcdResponse: &etcd.Response{
Action: "set", Action: "set",
Node: &etcd.Node{ Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)), Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1, CreatedIndex: 1,
ModifiedIndex: 3, ModifiedIndex: 3,
}, },
PrevNode: &etcd.Node{ PrevNode: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFooFiltered)), Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFooFiltered)),
CreatedIndex: 1, CreatedIndex: 1,
ModifiedIndex: 2, ModifiedIndex: 2,
}, },
...@@ -377,12 +377,12 @@ func TestFiltering(t *testing.T) { ...@@ -377,12 +377,12 @@ func TestFiltering(t *testing.T) {
etcdResponse: &etcd.Response{ etcdResponse: &etcd.Response{
Action: "set", Action: "set",
Node: &etcd.Node{ Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)), Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1, CreatedIndex: 1,
ModifiedIndex: 4, ModifiedIndex: 4,
}, },
PrevNode: &etcd.Node{ PrevNode: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)), Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1, CreatedIndex: 1,
ModifiedIndex: 3, ModifiedIndex: 3,
}, },
...@@ -399,7 +399,7 @@ func TestFiltering(t *testing.T) { ...@@ -399,7 +399,7 @@ func TestFiltering(t *testing.T) {
ModifiedIndex: 5, ModifiedIndex: 5,
}, },
PrevNode: &etcd.Node{ PrevNode: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)), Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1, CreatedIndex: 1,
ModifiedIndex: 4, ModifiedIndex: 4,
}, },
...@@ -462,7 +462,7 @@ func TestStorageError(t *testing.T) { ...@@ -462,7 +462,7 @@ func TestStorageError(t *testing.T) {
fakeClient.WatchResponse <- &etcd.Response{ fakeClient.WatchResponse <- &etcd.Response{
Action: "create", Action: "create",
Node: &etcd.Node{ Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)), Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1, CreatedIndex: 1,
ModifiedIndex: 1, ModifiedIndex: 1,
}, },
......
...@@ -57,8 +57,8 @@ var codec runtime.Codec ...@@ -57,8 +57,8 @@ var codec runtime.Codec
func init() { func init() {
scheme = runtime.NewScheme() scheme = runtime.NewScheme()
scheme.AddKnownTypes("", &TestResource{}) scheme.AddKnownTypes("", &TestResource{})
scheme.AddKnownTypes(testapi.Version(), &TestResource{}) scheme.AddKnownTypes(testapi.Default.Version(), &TestResource{})
codec = runtime.CodecFor(scheme, testapi.Version()) codec = runtime.CodecFor(scheme, testapi.Default.Version())
scheme.AddConversionFuncs( scheme.AddConversionFuncs(
func(in *TestResource, out *TestResource, s conversion.Scope) error { func(in *TestResource, out *TestResource, s conversion.Scope) error {
*out = *in *out = *in
...@@ -85,7 +85,7 @@ func TestIsEtcdNotFound(t *testing.T) { ...@@ -85,7 +85,7 @@ func TestIsEtcdNotFound(t *testing.T) {
// Returns an encoded version of api.Pod with the given name. // Returns an encoded version of api.Pod with the given name.
func getEncodedPod(name string) string { func getEncodedPod(name string) string {
pod, _ := testapi.Codec().Encode(&api.Pod{ pod, _ := testapi.Default.Codec().Encode(&api.Pod{
ObjectMeta: api.ObjectMeta{Name: name}, ObjectMeta: api.ObjectMeta{Name: name},
}) })
return string(pod) return string(pod)
...@@ -93,7 +93,7 @@ func getEncodedPod(name string) string { ...@@ -93,7 +93,7 @@ func getEncodedPod(name string) string {
func TestList(t *testing.T) { func TestList(t *testing.T) {
fakeClient := tools.NewFakeEtcdClient(t) fakeClient := tools.NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix()) helper := newEtcdHelper(fakeClient, testapi.Default.Codec(), etcdtest.PathPrefix())
key := etcdtest.AddPrefix("/some/key") key := etcdtest.AddPrefix("/some/key")
fakeClient.Data[key] = tools.EtcdResponseWithError{ fakeClient.Data[key] = tools.EtcdResponseWithError{
R: &etcd.Response{ R: &etcd.Response{
...@@ -167,7 +167,7 @@ func TestList(t *testing.T) { ...@@ -167,7 +167,7 @@ func TestList(t *testing.T) {
// TestListAcrossDirectories ensures that the client excludes directories and flattens tree-response - simulates cross-namespace query // TestListAcrossDirectories ensures that the client excludes directories and flattens tree-response - simulates cross-namespace query
func TestListAcrossDirectories(t *testing.T) { func TestListAcrossDirectories(t *testing.T) {
fakeClient := tools.NewFakeEtcdClient(t) fakeClient := tools.NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix()) helper := newEtcdHelper(fakeClient, testapi.Default.Codec(), etcdtest.PathPrefix())
key := etcdtest.AddPrefix("/some/key") key := etcdtest.AddPrefix("/some/key")
fakeClient.Data[key] = tools.EtcdResponseWithError{ fakeClient.Data[key] = tools.EtcdResponseWithError{
R: &etcd.Response{ R: &etcd.Response{
...@@ -254,7 +254,7 @@ func TestListAcrossDirectories(t *testing.T) { ...@@ -254,7 +254,7 @@ func TestListAcrossDirectories(t *testing.T) {
func TestListExcludesDirectories(t *testing.T) { func TestListExcludesDirectories(t *testing.T) {
fakeClient := tools.NewFakeEtcdClient(t) fakeClient := tools.NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix()) helper := newEtcdHelper(fakeClient, testapi.Default.Codec(), etcdtest.PathPrefix())
key := etcdtest.AddPrefix("/some/key") key := etcdtest.AddPrefix("/some/key")
fakeClient.Data[key] = tools.EtcdResponseWithError{ fakeClient.Data[key] = tools.EtcdResponseWithError{
R: &etcd.Response{ R: &etcd.Response{
...@@ -329,7 +329,7 @@ func TestListExcludesDirectories(t *testing.T) { ...@@ -329,7 +329,7 @@ func TestListExcludesDirectories(t *testing.T) {
func TestGet(t *testing.T) { func TestGet(t *testing.T) {
fakeClient := tools.NewFakeEtcdClient(t) fakeClient := tools.NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix()) helper := newEtcdHelper(fakeClient, testapi.Default.Codec(), etcdtest.PathPrefix())
key := etcdtest.AddPrefix("/some/key") key := etcdtest.AddPrefix("/some/key")
grace := int64(30) grace := int64(30)
expect := api.Pod{ expect := api.Pod{
...@@ -340,7 +340,7 @@ func TestGet(t *testing.T) { ...@@ -340,7 +340,7 @@ func TestGet(t *testing.T) {
TerminationGracePeriodSeconds: &grace, TerminationGracePeriodSeconds: &grace,
}, },
} }
fakeClient.Set(key, runtime.EncodeOrDie(testapi.Codec(), &expect), 0) fakeClient.Set(key, runtime.EncodeOrDie(testapi.Default.Codec(), &expect), 0)
var got api.Pod var got api.Pod
err := helper.Get("/some/key", &got, false) err := helper.Get("/some/key", &got, false)
if err != nil { if err != nil {
...@@ -353,7 +353,7 @@ func TestGet(t *testing.T) { ...@@ -353,7 +353,7 @@ func TestGet(t *testing.T) {
func TestGetNotFoundErr(t *testing.T) { func TestGetNotFoundErr(t *testing.T) {
fakeClient := tools.NewFakeEtcdClient(t) fakeClient := tools.NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix()) helper := newEtcdHelper(fakeClient, testapi.Default.Codec(), etcdtest.PathPrefix())
key1 := etcdtest.AddPrefix("/some/key") key1 := etcdtest.AddPrefix("/some/key")
fakeClient.Data[key1] = tools.EtcdResponseWithError{ fakeClient.Data[key1] = tools.EtcdResponseWithError{
R: &etcd.Response{ R: &etcd.Response{
...@@ -397,13 +397,13 @@ func TestGetNotFoundErr(t *testing.T) { ...@@ -397,13 +397,13 @@ func TestGetNotFoundErr(t *testing.T) {
func TestCreate(t *testing.T) { func TestCreate(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}} obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
fakeClient := tools.NewFakeEtcdClient(t) fakeClient := tools.NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix()) helper := newEtcdHelper(fakeClient, testapi.Default.Codec(), etcdtest.PathPrefix())
returnedObj := &api.Pod{} returnedObj := &api.Pod{}
err := helper.Create("/some/key", obj, returnedObj, 5) err := helper.Create("/some/key", obj, returnedObj, 5)
if err != nil { if err != nil {
t.Errorf("Unexpected error %#v", err) t.Errorf("Unexpected error %#v", err)
} }
data, err := testapi.Codec().Encode(obj) data, err := testapi.Default.Codec().Encode(obj)
if err != nil { if err != nil {
t.Errorf("Unexpected error %#v", err) t.Errorf("Unexpected error %#v", err)
} }
...@@ -423,7 +423,7 @@ func TestCreate(t *testing.T) { ...@@ -423,7 +423,7 @@ func TestCreate(t *testing.T) {
func TestCreateNilOutParam(t *testing.T) { func TestCreateNilOutParam(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}} obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
fakeClient := tools.NewFakeEtcdClient(t) fakeClient := tools.NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix()) helper := newEtcdHelper(fakeClient, testapi.Default.Codec(), etcdtest.PathPrefix())
err := helper.Create("/some/key", obj, nil, 5) err := helper.Create("/some/key", obj, nil, 5)
if err != nil { if err != nil {
t.Errorf("Unexpected error %#v", err) t.Errorf("Unexpected error %#v", err)
...@@ -433,13 +433,13 @@ func TestCreateNilOutParam(t *testing.T) { ...@@ -433,13 +433,13 @@ func TestCreateNilOutParam(t *testing.T) {
func TestSet(t *testing.T) { func TestSet(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}} obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
fakeClient := tools.NewFakeEtcdClient(t) fakeClient := tools.NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix()) helper := newEtcdHelper(fakeClient, testapi.Default.Codec(), etcdtest.PathPrefix())
returnedObj := &api.Pod{} returnedObj := &api.Pod{}
err := helper.Set("/some/key", obj, returnedObj, 5) err := helper.Set("/some/key", obj, returnedObj, 5)
if err != nil { if err != nil {
t.Errorf("Unexpected error %#v", err) t.Errorf("Unexpected error %#v", err)
} }
data, err := testapi.Codec().Encode(obj) data, err := testapi.Default.Codec().Encode(obj)
if err != nil { if err != nil {
t.Errorf("Unexpected error %#v", err) t.Errorf("Unexpected error %#v", err)
} }
...@@ -461,7 +461,7 @@ func TestSetFailCAS(t *testing.T) { ...@@ -461,7 +461,7 @@ func TestSetFailCAS(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"}} obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"}}
fakeClient := tools.NewFakeEtcdClient(t) fakeClient := tools.NewFakeEtcdClient(t)
fakeClient.CasErr = fakeClient.NewError(123) fakeClient.CasErr = fakeClient.NewError(123)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix()) helper := newEtcdHelper(fakeClient, testapi.Default.Codec(), etcdtest.PathPrefix())
err := helper.Set("/some/key", obj, nil, 5) err := helper.Set("/some/key", obj, nil, 5)
if err == nil { if err == nil {
t.Errorf("Expecting error.") t.Errorf("Expecting error.")
...@@ -472,12 +472,12 @@ func TestSetWithVersion(t *testing.T) { ...@@ -472,12 +472,12 @@ func TestSetWithVersion(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"}} obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"}}
fakeClient := tools.NewFakeEtcdClient(t) fakeClient := tools.NewFakeEtcdClient(t)
fakeClient.TestIndex = true fakeClient.TestIndex = true
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix()) helper := newEtcdHelper(fakeClient, testapi.Default.Codec(), etcdtest.PathPrefix())
key := etcdtest.AddPrefix("/some/key") key := etcdtest.AddPrefix("/some/key")
fakeClient.Data[key] = tools.EtcdResponseWithError{ fakeClient.Data[key] = tools.EtcdResponseWithError{
R: &etcd.Response{ R: &etcd.Response{
Node: &etcd.Node{ Node: &etcd.Node{
Value: runtime.EncodeOrDie(testapi.Codec(), obj), Value: runtime.EncodeOrDie(testapi.Default.Codec(), obj),
ModifiedIndex: 1, ModifiedIndex: 1,
}, },
}, },
...@@ -488,7 +488,7 @@ func TestSetWithVersion(t *testing.T) { ...@@ -488,7 +488,7 @@ func TestSetWithVersion(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Unexpected error %#v", err) t.Fatalf("Unexpected error %#v", err)
} }
data, err := testapi.Codec().Encode(obj) data, err := testapi.Default.Codec().Encode(obj)
if err != nil { if err != nil {
t.Fatalf("Unexpected error %#v", err) t.Fatalf("Unexpected error %#v", err)
} }
...@@ -508,7 +508,7 @@ func TestSetWithVersion(t *testing.T) { ...@@ -508,7 +508,7 @@ func TestSetWithVersion(t *testing.T) {
func TestSetWithoutResourceVersioner(t *testing.T) { func TestSetWithoutResourceVersioner(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}} obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
fakeClient := tools.NewFakeEtcdClient(t) fakeClient := tools.NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix()) helper := newEtcdHelper(fakeClient, testapi.Default.Codec(), etcdtest.PathPrefix())
helper.versioner = nil helper.versioner = nil
returnedObj := &api.Pod{} returnedObj := &api.Pod{}
err := helper.Set("/some/key", obj, returnedObj, 3) err := helper.Set("/some/key", obj, returnedObj, 3)
...@@ -516,7 +516,7 @@ func TestSetWithoutResourceVersioner(t *testing.T) { ...@@ -516,7 +516,7 @@ func TestSetWithoutResourceVersioner(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Unexpected error %#v", err) t.Errorf("Unexpected error %#v", err)
} }
data, err := testapi.Codec().Encode(obj) data, err := testapi.Default.Codec().Encode(obj)
if err != nil { if err != nil {
t.Errorf("Unexpected error %#v", err) t.Errorf("Unexpected error %#v", err)
} }
...@@ -536,7 +536,7 @@ func TestSetWithoutResourceVersioner(t *testing.T) { ...@@ -536,7 +536,7 @@ func TestSetWithoutResourceVersioner(t *testing.T) {
func TestSetNilOutParam(t *testing.T) { func TestSetNilOutParam(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}} obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
fakeClient := tools.NewFakeEtcdClient(t) fakeClient := tools.NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix()) helper := newEtcdHelper(fakeClient, testapi.Default.Codec(), etcdtest.PathPrefix())
helper.versioner = nil helper.versioner = nil
err := helper.Set("/some/key", obj, nil, 3) err := helper.Set("/some/key", obj, nil, 3)
if err != nil { if err != nil {
...@@ -860,7 +860,7 @@ func TestGetEtcdVersion_NotListening(t *testing.T) { ...@@ -860,7 +860,7 @@ func TestGetEtcdVersion_NotListening(t *testing.T) {
func TestPrefixEtcdKey(t *testing.T) { func TestPrefixEtcdKey(t *testing.T) {
fakeClient := tools.NewFakeEtcdClient(t) fakeClient := tools.NewFakeEtcdClient(t)
prefix := path.Join("/", etcdtest.PathPrefix()) prefix := path.Join("/", etcdtest.PathPrefix())
helper := newEtcdHelper(fakeClient, testapi.Codec(), prefix) helper := newEtcdHelper(fakeClient, testapi.Default.Codec(), prefix)
baseKey := "/some/key" baseKey := "/some/key"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment