Commit 2e2def36 authored by k8s-merge-robot's avatar k8s-merge-robot

Merge pull request #13581 from caesarxuchao/APIGroup-testapi-2

Auto commit by PR queue bot
parents e6e69e31 9fc79e9d
......@@ -38,6 +38,7 @@ import (
"k8s.io/kubernetes/pkg/api"
apierrors "k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/latest"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/apiserver"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/record"
......@@ -69,8 +70,6 @@ import (
var (
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.
maxConcurrency int
)
......@@ -93,7 +92,7 @@ func (h *delegateHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusNotFound)
}
func startComponents(firstManifestURL, secondManifestURL, apiVersion string) (string, string) {
func startComponents(firstManifestURL, secondManifestURL string) (string, string) {
// Setup
servers := []string{}
glog.Infof("Creating etcd client pointing to %v", servers)
......@@ -126,13 +125,17 @@ func startComponents(firstManifestURL, secondManifestURL, apiVersion string) (st
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 {
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 {
glog.Fatalf("Unable to get etcd storage for experimental: %v", err)
}
......@@ -891,7 +894,6 @@ func runSchedulerNoPhantomPodsTest(client *client.Client) {
type testFunc func(*client.Client)
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(
&maxConcurrency, "max-concurrency", -1, "Maximum number of tests to be run simultaneously. Unlimited if set to negative.")
}
......@@ -911,18 +913,21 @@ func main() {
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)
secondManifestURL := ServeCachedManifestFile(testPodSpecFile)
apiServerURL, _ := startComponents(firstManifestURL, secondManifestURL, apiVersion)
apiServerURL, _ := startComponents(firstManifestURL, secondManifestURL)
// Ok. we're good to go.
glog.Infof("API Server started on %s", apiServerURL)
// Wait for the synchronization threads to come up.
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
testFuncs := []testFunc{
......
......@@ -318,7 +318,7 @@ func TestExecutorLaunchAndKillTask(t *testing.T) {
Updates: updates,
APIClient: client.NewOrDie(&client.Config{
Host: testApiServer.server.URL,
Version: testapi.Version(),
Version: testapi.Default.Version(),
}),
Kubelet: &fakeKubelet{
Kubelet: &kubelet.Kubelet{},
......@@ -355,7 +355,7 @@ func TestExecutorLaunchAndKillTask(t *testing.T) {
assert.Equal(t, nil, err, "must be able to create a task from a pod")
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")
taskInfo.Data = data
var statusUpdateCalls sync.WaitGroup
......@@ -484,7 +484,7 @@ func TestExecutorStaticPods(t *testing.T) {
Updates: make(chan interface{}, 1), // allow kube-executor source to proceed past init
APIClient: client.NewOrDie(&client.Config{
Host: testApiServer.server.URL,
Version: testapi.Version(),
Version: testapi.Default.Version(),
}),
Kubelet: &kubelet.Kubelet{},
PodStatusFunc: func(kl KubeletInterface, pod *api.Pod) (*api.PodStatus, error) {
......@@ -565,7 +565,7 @@ func TestExecutorFrameworkMessage(t *testing.T) {
Updates: make(chan interface{}, 1024),
APIClient: client.NewOrDie(&client.Config{
Host: testApiServer.server.URL,
Version: testapi.Version(),
Version: testapi.Default.Version(),
}),
Kubelet: &fakeKubelet{
Kubelet: &kubelet.Kubelet{},
......@@ -602,7 +602,7 @@ func TestExecutorFrameworkMessage(t *testing.T) {
*pod, &mesosproto.ExecutorInfo{})
taskInfo := podTask.BuildTaskInfo()
data, _ := testapi.Codec().Encode(pod)
data, _ := testapi.Default.Codec().Encode(pod)
taskInfo.Data = data
mockDriver.On(
......@@ -660,11 +660,11 @@ func TestExecutorFrameworkMessage(t *testing.T) {
func NewTestPod(i int) *api.Pod {
name := fmt.Sprintf("pod%d", i)
return &api.Pod{
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()},
TypeMeta: api.TypeMeta{APIVersion: testapi.Default.Version()},
ObjectMeta: api.ObjectMeta{
Name: name,
Namespace: api.NamespaceDefault,
SelfLink: testapi.SelfLink("pods", string(i)),
SelfLink: testapi.Default.SelfLink("pods", string(i)),
},
Spec: api.PodSpec{
Containers: []api.Container{
......@@ -710,7 +710,7 @@ func NewTestServer(t *testing.T, namespace string, pods *api.PodList) *TestServe
}
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)
})
......
......@@ -61,13 +61,13 @@ func NewTestServer(t *testing.T, namespace string, mockPodListWatch *MockPodsLis
}
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)
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) {
name := r.URL.Path[len(podsPrefix):]
......@@ -79,13 +79,13 @@ func NewTestServer(t *testing.T, namespace string, mockPodListWatch *MockPodsLis
p := mockPodListWatch.GetPod(name)
if p != nil {
w.WriteHeader(http.StatusOK)
w.Write([]byte(runtime.EncodeOrDie(testapi.Codec(), p)))
w.Write([]byte(runtime.EncodeOrDie(testapi.Default.Codec(), p)))
return
}
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)
})
......@@ -196,7 +196,7 @@ func NewTestPod() (*api.Pod, int) {
currentPodNum = currentPodNum + 1
name := fmt.Sprintf("pod%d", currentPodNum)
return &api.Pod{
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()},
TypeMeta: api.TypeMeta{APIVersion: testapi.Default.Version()},
ObjectMeta: api.ObjectMeta{
Name: name,
Namespace: api.NamespaceDefault,
......@@ -398,7 +398,7 @@ func TestPlugin_LifeCycle(t *testing.T) {
podtask.NewDefaultProcurement(mresource.DefaultDefaultContainerCPULimit, mresource.DefaultDefaultContainerMemLimit))
testScheduler := New(Config{
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),
Schedcfg: *schedcfg.CreateDefaultConfig(),
})
......
......@@ -52,8 +52,13 @@ KUBE_COVERPROCS=${KUBE_COVERPROCS:-4}
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.
KUBE_GOVERALLS_BIN=${KUBE_GOVERALLS_BIN:-}
# Comma separated list of API Versions that should be tested.
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1"}
# Lists of API Versions of each groups that should be tested, groups are
# 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
# (kubernetes.io/registry).
KUBE_TEST_ETCD_PREFIXES=${KUBE_TEST_ETCD_PREFIXES:-"registry,kubernetes.io/registry"}
......@@ -131,7 +136,8 @@ junitFilenamePrefix() {
return
fi
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() {
......@@ -205,7 +211,7 @@ runTests() {
fi
# 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
kube::log::status "Saving coverage output in '${cover_report_dir}'"
mkdir -p "${@+${@/#/${cover_report_dir}/}}"
......@@ -266,7 +272,7 @@ reportCoverageToCoveralls() {
}
# 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}"
apiVersionsCount=${#apiVersions[@]}
etcdPrefixesCount=${#etcdPrefixes[@]}
......@@ -274,7 +280,10 @@ for (( i=0, j=0; ; )); do
apiVersion=${apiVersions[i]}
etcdPrefix=${etcdPrefixes[j]}
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
j=${j}+1
if [[ i -eq ${apiVersionsCount} ]] && [[ j -eq ${etcdPrefixesCount} ]]; then
......
......@@ -24,8 +24,12 @@ set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"
# Comma separated list of API Versions that should be tested.
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1"}
# Lists of API Versions of each groups that should be tested, groups are
# 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"}
LOG_LEVEL=${LOG_LEVEL:-2}
......@@ -48,8 +52,8 @@ runTests() {
kube::log::status "Running integration test scenario"
KUBE_API_VERSIONS="v1" "${KUBE_OUTPUT_HOSTBIN}/integration" --v=${LOG_LEVEL} --api-version="$1" \
--max-concurrency="${KUBE_INTEGRATION_TEST_MAX_CONCURRENCY}"
KUBE_API_VERSIONS="v1" KUBE_TEST_API_VERSIONS="$1" "${KUBE_OUTPUT_HOSTBIN}/integration" --v=${LOG_LEVEL} \
--max-concurrency="${KUBE_INTEGRATION_TEST_MAX_CONCURRENCY}"
cleanup
}
......@@ -60,7 +64,7 @@ KUBE_API_VERSIONS="v1" "${KUBE_ROOT}/hack/build-go.sh" "$@" cmd/integration
trap cleanup EXIT
# 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
runTests "${apiVersion}"
done
......@@ -37,7 +37,7 @@ func BenchmarkPodConversion(b *testing.B) {
scheme := api.Scheme.Raw()
var result *api.Pod
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 {
b.Fatalf("Conversion error: %v", err)
}
......@@ -65,7 +65,7 @@ func BenchmarkNodeConversion(b *testing.B) {
scheme := api.Scheme.Raw()
var result *api.Node
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 {
b.Fatalf("Conversion error: %v", err)
}
......@@ -93,7 +93,7 @@ func BenchmarkReplicationControllerConversion(b *testing.B) {
scheme := api.Scheme.Raw()
var result *api.ReplicationController
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 {
b.Fatalf("Conversion error: %v", err)
}
......
......@@ -28,7 +28,7 @@ import (
func TestDeepCopyApiObjects(t *testing.T) {
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()))
for kind := range api.Scheme.KnownTypes(version) {
item, err := api.Scheme.New(version, kind)
......
......@@ -90,10 +90,10 @@ func roundTripSame(t *testing.T, item runtime.Object, except ...string) {
set := util.NewStringSet(except...)
seed := rand.Int63()
fuzzInternalObject(t, "", item, seed)
version := testapi.Version()
version := testapi.Default.Version()
if !set.Has(version) {
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
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
import (
......@@ -24,63 +24,161 @@ import (
"k8s.io/kubernetes/pkg/api/latest"
"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"
)
// Version returns the API version to test against, as set by the KUBE_API_VERSION env var.
func Version() string {
version := os.Getenv("KUBE_API_VERSION")
if version == "" {
version = latest.Version
var (
Groups = make(map[string]TestGroup)
Default TestGroup
Experimental TestGroup
)
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
// KUBE_API_VERSION env var.
func Codec() runtime.Codec {
interfaces, err := latest.InterfacesFor(Version())
if err != nil {
panic(err)
// KUBE_TEST_API env var.
func (g TestGroup) Codec() runtime.Codec {
// TODO: caesarxuchao: Restructure the body once we have a central `latest`.
if g.Group == "" {
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
// KUBE_API_VERSION env var.
func Converter() runtime.ObjectConvertor {
interfaces, err := latest.InterfacesFor(Version())
if err != nil {
panic(err)
// KUBE_TEST_API env var.
func (g TestGroup) Converter() runtime.ObjectConvertor {
// TODO: caesarxuchao: Restructure the body once we have a central `latest`.
if g.Group == "" {
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,
// as set by the KUBE_API_VERSION env var.
func MetadataAccessor() meta.MetadataAccessor {
interfaces, err := latest.InterfacesFor(Version())
if err != nil {
panic(err)
// as set by the KUBE_TEST_API env var.
func (g TestGroup) MetadataAccessor() meta.MetadataAccessor {
// TODO: caesarxuchao: Restructure the body once we have a central `latest`.
if g.Group == "" {
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().
// 'resource' should be the resource path, e.g. "pods" for the Pod type. 'name' should be
// empty for lists.
func SelfLink(resource, name string) string {
if name == "" {
return fmt.Sprintf("/api/%s/%s", Version(), resource)
func (g TestGroup) SelfLink(resource, name string) string {
if g.Group == "" {
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.
// For ex, this is of the form:
// /api/v1/watch/namespaces/foo/pods/pod0 for v1.
func ResourcePathWithPrefix(prefix, resource, namespace, name string) string {
path := "/api/" + Version()
func (g TestGroup) ResourcePathWithPrefix(prefix, resource, namespace, name string) string {
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 != "" {
path = path + "/" + prefix
}
......@@ -101,6 +199,6 @@ func ResourcePathWithPrefix(prefix, resource, namespace, name string) string {
// Returns the appropriate path for the given resource, namespace and name.
// For example, this is of the form:
// /api/v1/namespaces/foo/pods/pod0 for v1.
func ResourcePath(resource, namespace, name string) string {
return ResourcePathWithPrefix("", resource, namespace, name)
func (g TestGroup) ResourcePath(resource, namespace, name string) string {
return g.ResourcePathWithPrefix("", resource, namespace, name)
}
......@@ -28,14 +28,14 @@ func TestResourcePathWithPrefix(t *testing.T) {
name string
expected string
}{
{"prefix", "resource", "mynamespace", "myresource", "/api/" + Version() + "/prefix/namespaces/mynamespace/resource/myresource"},
{"prefix", "resource", "", "myresource", "/api/" + Version() + "/prefix/resource/myresource"},
{"prefix", "resource", "mynamespace", "", "/api/" + Version() + "/prefix/namespaces/mynamespace/resource"},
{"prefix", "resource", "", "", "/api/" + Version() + "/prefix/resource"},
{"", "resource", "mynamespace", "myresource", "/api/" + Version() + "/namespaces/mynamespace/resource/myresource"},
{"prefix", "resource", "mynamespace", "myresource", "/api/" + Default.Version() + "/prefix/namespaces/mynamespace/resource/myresource"},
{"prefix", "resource", "", "myresource", "/api/" + Default.Version() + "/prefix/resource/myresource"},
{"prefix", "resource", "mynamespace", "", "/api/" + Default.Version() + "/prefix/namespaces/mynamespace/resource"},
{"prefix", "resource", "", "", "/api/" + Default.Version() + "/prefix/resource"},
{"", "resource", "mynamespace", "myresource", "/api/" + Default.Version() + "/namespaces/mynamespace/resource/myresource"},
}
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)
}
}
......@@ -48,13 +48,13 @@ func TestResourcePath(t *testing.T) {
name string
expected string
}{
{"resource", "mynamespace", "myresource", "/api/" + Version() + "/namespaces/mynamespace/resource/myresource"},
{"resource", "", "myresource", "/api/" + Version() + "/resource/myresource"},
{"resource", "mynamespace", "", "/api/" + Version() + "/namespaces/mynamespace/resource"},
{"resource", "", "", "/api/" + Version() + "/resource"},
{"resource", "mynamespace", "myresource", "/api/" + Default.Version() + "/namespaces/mynamespace/resource/myresource"},
{"resource", "", "myresource", "/api/" + Default.Version() + "/resource/myresource"},
{"resource", "mynamespace", "", "/api/" + Default.Version() + "/namespaces/mynamespace/resource"},
{"resource", "", "", "/api/" + Default.Version() + "/resource"},
}
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)
}
}
......
/*
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 (
)
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 {
return "", err
}
......@@ -36,7 +36,7 @@ func readPod(filename string) (string, 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)
if err != nil {
return nil, err
......@@ -71,7 +71,7 @@ func TestValidateOk(t *testing.T) {
for _, test := range tests {
testObj := test.obj
apiObjectFuzzer.Fuzz(testObj)
data, err := testapi.Codec().Encode(testObj)
data, err := testapi.Default.Codec().Encode(testObj)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
......
......@@ -638,7 +638,7 @@ func TestValidateEnv(t *testing.T) {
Name: "abc",
ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{
APIVersion: testapi.Version(),
APIVersion: testapi.Default.Version(),
FieldPath: "metadata.name",
},
},
......@@ -670,7 +670,7 @@ func TestValidateEnv(t *testing.T) {
Value: "foo",
ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{
APIVersion: testapi.Version(),
APIVersion: testapi.Default.Version(),
FieldPath: "metadata.name",
},
},
......@@ -683,7 +683,7 @@ func TestValidateEnv(t *testing.T) {
Name: "abc",
ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{
APIVersion: testapi.Version(),
APIVersion: testapi.Default.Version(),
},
},
}},
......@@ -708,7 +708,7 @@ func TestValidateEnv(t *testing.T) {
ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{
FieldPath: "metadata.whoops",
APIVersion: testapi.Version(),
APIVersion: testapi.Default.Version(),
},
},
}},
......@@ -747,7 +747,7 @@ func TestValidateEnv(t *testing.T) {
ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{
FieldPath: "status.phase",
APIVersion: testapi.Version(),
APIVersion: testapi.Default.Version(),
},
},
}},
......
......@@ -52,11 +52,11 @@ func expectHTTP(url string, code int, t *testing.T) {
}
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 {
return testapi.ResourcePathWithPrefix(prefix, resource, namespace, name)
return testapi.Default.ResourcePathWithPrefix(prefix, resource, namespace, name)
}
func TestMaxInFlight(t *testing.T) {
......@@ -231,15 +231,15 @@ func TestGetAPIRequestInfo(t *testing.T) {
{"GET", "/watch/namespaces/other/pods", "watch", "", "other", "pods", "", "Pod", "", []string{"pods"}},
// fully-qualified paths
{"GET", getPath("pods", "other", ""), "list", testapi.Version(), "other", "pods", "", "Pod", "", []string{"pods"}},
{"GET", getPath("pods", "other", "foo"), "get", testapi.Version(), "other", "pods", "", "Pod", "foo", []string{"pods", "foo"}},
{"GET", getPath("pods", "", ""), "list", testapi.Version(), api.NamespaceAll, "pods", "", "Pod", "", []string{"pods"}},
{"POST", getPath("pods", "", ""), "create", testapi.Version(), api.NamespaceAll, "pods", "", "Pod", "", []string{"pods"}},
{"GET", getPath("pods", "", "foo"), "get", testapi.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("watch", "pods", "", ""), "watch", testapi.Version(), api.NamespaceAll, "pods", "", "Pod", "", []string{"pods"}},
{"GET", pathWithPrefix("redirect", "pods", "", ""), "redirect", testapi.Version(), api.NamespaceAll, "pods", "", "Pod", "", []string{"pods"}},
{"GET", pathWithPrefix("watch", "pods", "other", ""), "watch", 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.Default.Version(), "other", "pods", "", "Pod", "foo", []string{"pods", "foo"}},
{"GET", getPath("pods", "", ""), "list", testapi.Default.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.Default.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.Default.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.Default.Version(), "other", "pods", "", "Pod", "", []string{"pods"}},
// subresource identification
{"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 {
}
func TestListWatchesCanList(t *testing.T) {
fieldSelectorQueryParamName := api.FieldSelectorQueryParam(testapi.Version())
fieldSelectorQueryParamName := api.FieldSelectorQueryParam(testapi.Default.Version())
table := []struct {
location string
resource string
......@@ -63,7 +63,7 @@ func TestListWatchesCanList(t *testing.T) {
}{
// Minion
{
location: testapi.ResourcePath("minions", api.NamespaceAll, ""),
location: testapi.Default.ResourcePath("minions", api.NamespaceAll, ""),
resource: "minions",
namespace: api.NamespaceAll,
fieldSelector: parseSelectorOrDie(""),
......@@ -71,7 +71,7 @@ func TestListWatchesCanList(t *testing.T) {
// pod with "assigned" field selector.
{
location: buildLocation(
testapi.ResourcePath("pods", api.NamespaceAll, ""),
testapi.Default.ResourcePath("pods", api.NamespaceAll, ""),
buildQueryValues(url.Values{fieldSelectorQueryParamName: []string{"spec.host="}})),
resource: "pods",
namespace: api.NamespaceAll,
......@@ -80,7 +80,7 @@ func TestListWatchesCanList(t *testing.T) {
// pod in namespace "foo"
{
location: buildLocation(
testapi.ResourcePath("pods", "foo", ""),
testapi.Default.ResourcePath("pods", "foo", ""),
buildQueryValues(url.Values{fieldSelectorQueryParamName: []string{"spec.host="}})),
resource: "pods",
namespace: "foo",
......@@ -95,7 +95,7 @@ func TestListWatchesCanList(t *testing.T) {
}
server := httptest.NewServer(&handler)
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)
// This test merely tests that the correct request is made.
lw.List()
......@@ -104,7 +104,7 @@ func TestListWatchesCanList(t *testing.T) {
}
func TestListWatchesCanWatch(t *testing.T) {
fieldSelectorQueryParamName := api.FieldSelectorQueryParam(testapi.Version())
fieldSelectorQueryParamName := api.FieldSelectorQueryParam(testapi.Default.Version())
table := []struct {
rv string
location string
......@@ -115,7 +115,7 @@ func TestListWatchesCanWatch(t *testing.T) {
// Minion
{
location: buildLocation(
testapi.ResourcePathWithPrefix("watch", "minions", api.NamespaceAll, ""),
testapi.Default.ResourcePathWithPrefix("watch", "minions", api.NamespaceAll, ""),
buildQueryValues(url.Values{"resourceVersion": []string{""}})),
rv: "",
resource: "minions",
......@@ -124,7 +124,7 @@ func TestListWatchesCanWatch(t *testing.T) {
},
{
location: buildLocation(
testapi.ResourcePathWithPrefix("watch", "minions", api.NamespaceAll, ""),
testapi.Default.ResourcePathWithPrefix("watch", "minions", api.NamespaceAll, ""),
buildQueryValues(url.Values{"resourceVersion": []string{"42"}})),
rv: "42",
resource: "minions",
......@@ -134,7 +134,7 @@ func TestListWatchesCanWatch(t *testing.T) {
// pod with "assigned" field selector.
{
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"}})),
rv: "0",
resource: "pods",
......@@ -144,7 +144,7 @@ func TestListWatchesCanWatch(t *testing.T) {
// pod with namespace foo and assigned field selector
{
location: buildLocation(
testapi.ResourcePathWithPrefix("watch", "pods", "foo", ""),
testapi.Default.ResourcePathWithPrefix("watch", "pods", "foo", ""),
buildQueryValues(url.Values{fieldSelectorQueryParamName: []string{"spec.host="}, "resourceVersion": []string{"0"}})),
rv: "0",
resource: "pods",
......@@ -161,7 +161,7 @@ func TestListWatchesCanWatch(t *testing.T) {
}
server := httptest.NewServer(&handler)
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)
// This test merely tests that the correct request is made.
lw.Watch(item.rv)
......
......@@ -68,23 +68,34 @@ type testClient struct {
QueryValidator map[string]func(string, string) bool
}
func (c *testClient) Setup() *testClient {
func (c *testClient) Setup(t *testing.T) *testClient {
c.handler = &util.FakeHandler{
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.server = httptest.NewServer(c.handler)
if c.Client == nil {
version := c.Version
if len(version) == 0 {
version = testapi.Version()
version = testapi.Default.Version()
}
c.Client = NewOrDie(&Config{
Host: c.server.URL,
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{}
return c
......@@ -124,7 +135,7 @@ func (c *testClient) ValidateCommon(t *testing.T, err error) {
return
}
requestBody := body(c.Request.Body, c.Request.RawBody)
requestBody := body(t, c.Request.Body, c.Request.RawBody)
actualQuery := c.handler.RequestReceived.URL.Query()
t.Logf("got query: %v", actualQuery)
t.Logf("path: %v", c.Request.Path)
......@@ -136,9 +147,9 @@ func (c *testClient) ValidateCommon(t *testing.T, err error) {
validator, ok := c.QueryValidator[key]
if !ok {
switch key {
case api.LabelSelectorQueryParam(testapi.Version()):
case api.LabelSelectorQueryParam(testapi.Default.Version()):
validator = validateLabels
case api.FieldSelectorQueryParam(testapi.Version()):
case api.FieldSelectorQueryParam(testapi.Default.Version()):
validator = validateFields
default:
validator = func(a, b string) bool { return a == b }
......@@ -200,9 +211,30 @@ func validateFields(a, b string) bool {
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 {
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)
return &body
}
......
......@@ -20,8 +20,8 @@ import (
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/expapi"
"k8s.io/kubernetes/pkg/expapi/testapi"
"k8s.io/kubernetes/pkg/labels"
)
......@@ -34,7 +34,7 @@ func TestListDaemons(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getDCResourceName(), ns, ""),
Path: testapi.Experimental.ResourcePath(getDCResourceName(), ns, ""),
},
Response: Response{StatusCode: 200,
Body: &expapi.DaemonList{
......@@ -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)
}
......@@ -63,7 +63,7 @@ func TestListDaemons(t *testing.T) {
func TestGetDaemon(t *testing.T) {
ns := api.NamespaceDefault
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{
StatusCode: 200,
Body: &expapi.Daemon{
......@@ -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)
}
func TestGetDaemonWithNoName(t *testing.T) {
ns := api.NamespaceDefault
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) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
}
......@@ -101,7 +101,7 @@ func TestUpdateDaemon(t *testing.T) {
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"},
}
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{
StatusCode: 200,
Body: &expapi.Daemon{
......@@ -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)
}
func TestDeleteDaemon(t *testing.T) {
ns := api.NamespaceDefault
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},
}
err := c.Setup().Experimental().Daemons(ns).Delete("foo")
err := c.Setup(t).Experimental().Daemons(ns).Delete("foo")
c.Validate(t, nil, err)
}
......@@ -138,7 +138,7 @@ func TestCreateDaemon(t *testing.T) {
ObjectMeta: api.ObjectMeta{Name: "foo"},
}
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{
StatusCode: 200,
Body: &expapi.Daemon{
......@@ -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)
}
......@@ -21,8 +21,8 @@ import (
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/expapi"
"k8s.io/kubernetes/pkg/expapi/testapi"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
)
......@@ -42,14 +42,14 @@ func TestDeploymentCreate(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "POST",
Path: testapi.ResourcePath(getDeploymentsResoureName(), ns, ""),
Path: testapi.Experimental.ResourcePath(getDeploymentsResoureName(), ns, ""),
Query: buildQueryValues(nil),
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 {
t.Fatalf("unexpected error: %v", err)
}
......@@ -67,14 +67,14 @@ func TestDeploymentGet(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getDeploymentsResoureName(), ns, "abc"),
Path: testapi.Experimental.ResourcePath(getDeploymentsResoureName(), ns, "abc"),
Query: buildQueryValues(nil),
Body: nil,
},
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)
}
......@@ -93,13 +93,13 @@ func TestDeploymentList(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getDeploymentsResoureName(), ns, ""),
Path: testapi.Experimental.ResourcePath(getDeploymentsResoureName(), ns, ""),
Query: buildQueryValues(nil),
Body: nil,
},
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)
}
......@@ -115,12 +115,12 @@ func TestDeploymentUpdate(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "PUT",
Path: testapi.ResourcePath(getDeploymentsResoureName(), ns, "abc"),
Path: testapi.Experimental.ResourcePath(getDeploymentsResoureName(), ns, "abc"),
Query: buildQueryValues(nil),
},
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)
}
......@@ -129,12 +129,12 @@ func TestDeploymentDelete(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "DELETE",
Path: testapi.ResourcePath(getDeploymentsResoureName(), ns, "foo"),
Path: testapi.Experimental.ResourcePath(getDeploymentsResoureName(), ns, "foo"),
Query: buildQueryValues(nil),
},
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)
}
......@@ -142,11 +142,11 @@ func TestDeploymentWatch(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePathWithPrefix("watch", getDeploymentsResoureName(), "", ""),
Path: testapi.Experimental.ResourcePathWithPrefix("watch", getDeploymentsResoureName(), "", ""),
Query: url.Values{"resourceVersion": []string{}},
},
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)
}
......@@ -27,7 +27,7 @@ import (
func TestListEndpoints(t *testing.T) {
ns := api.NamespaceDefault
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,
Body: &api.EndpointsList{
Items: []api.Endpoints{
......@@ -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)
}
func TestGetEndpoints(t *testing.T) {
ns := api.NamespaceDefault
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, err := c.Setup().Endpoints(ns).Get("endpoint-1")
response, err := c.Setup(t).Endpoints(ns).Get("endpoint-1")
c.Validate(t, response, err)
}
func TestGetEndpointWithNoName(t *testing.T) {
ns := api.NamespaceDefault
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) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
}
......
......@@ -32,24 +32,24 @@ func TestEventSearch(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath("events", "baz", ""),
Path: testapi.Default.ResourcePath("events", "baz", ""),
Query: url.Values{
api.FieldSelectorQueryParam(testapi.Version()): []string{
getInvolvedObjectNameFieldLabel(testapi.Version()) + "=foo,",
api.FieldSelectorQueryParam(testapi.Default.Version()): []string{
getInvolvedObjectNameFieldLabel(testapi.Default.Version()) + "=foo,",
"involvedObject.namespace=baz,",
"involvedObject.kind=Pod",
},
api.LabelSelectorQueryParam(testapi.Version()): []string{},
api.LabelSelectorQueryParam(testapi.Default.Version()): []string{},
},
},
Response: Response{StatusCode: 200, Body: &api.EventList{}},
}
eventList, err := c.Setup().Events("baz").Search(
eventList, err := c.Setup(t).Events("baz").Search(
&api.Pod{
ObjectMeta: api.ObjectMeta{
Name: "foo",
Namespace: "baz",
SelfLink: testapi.SelfLink("pods", ""),
SelfLink: testapi.Default.SelfLink("pods", ""),
},
},
)
......@@ -78,13 +78,13 @@ func TestEventCreate(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "POST",
Path: testapi.ResourcePath("events", api.NamespaceDefault, ""),
Path: testapi.Default.ResourcePath("events", api.NamespaceDefault, ""),
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 {
t.Fatalf("%v should be nil.", err)
......@@ -117,13 +117,13 @@ func TestEventGet(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath("events", "other", "1"),
Path: testapi.Default.ResourcePath("events", "other", "1"),
Body: nil,
},
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 {
t.Fatalf("%v should be nil.", err)
......@@ -158,12 +158,12 @@ func TestEventList(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath("events", ns, ""),
Path: testapi.Default.ResourcePath("events", ns, ""),
Body: nil,
},
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())
if err != nil {
......@@ -186,10 +186,10 @@ func TestEventDelete(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "DELETE",
Path: testapi.ResourcePath("events", ns, "foo"),
Path: testapi.Default.ResourcePath("events", ns, "foo"),
},
Response: Response{StatusCode: 200},
}
err := c.Setup().Events(ns).Delete("foo")
err := c.Setup(t).Events(ns).Delete("foo")
c.Validate(t, nil, err)
}
......@@ -41,23 +41,23 @@ type FakeRESTClient struct {
}
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 {
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 {
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 {
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 {
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) {
......
......@@ -401,40 +401,40 @@ func TestNegotiateVersion(t *testing.T) {
name: "server supports client default",
version: "version1",
config: &Config{},
serverVersions: []string{"version1", testapi.Version()},
clientVersions: []string{"version1", testapi.Version()},
serverVersions: []string{"version1", testapi.Default.Version()},
clientVersions: []string{"version1", testapi.Default.Version()},
expectedVersion: "version1",
expectErr: false,
},
{
name: "server falls back to client supported",
version: testapi.Version(),
version: testapi.Default.Version(),
config: &Config{},
serverVersions: []string{"version1"},
clientVersions: []string{"version1", testapi.Version()},
clientVersions: []string{"version1", testapi.Default.Version()},
expectedVersion: "version1",
expectErr: false,
},
{
name: "explicit version supported",
version: "",
config: &Config{Version: testapi.Version()},
serverVersions: []string{"version1", testapi.Version()},
clientVersions: []string{"version1", testapi.Version()},
expectedVersion: testapi.Version(),
config: &Config{Version: testapi.Default.Version()},
serverVersions: []string{"version1", testapi.Default.Version()},
clientVersions: []string{"version1", testapi.Default.Version()},
expectedVersion: testapi.Default.Version(),
expectErr: false,
},
{
name: "explicit version not supported",
version: "",
config: &Config{Version: testapi.Version()},
config: &Config{Version: testapi.Default.Version()},
serverVersions: []string{"version1"},
clientVersions: []string{"version1", testapi.Version()},
clientVersions: []string{"version1", testapi.Default.Version()},
expectedVersion: "",
expectErr: true,
},
}
codec := testapi.Codec()
codec := testapi.Default.Codec()
for _, test := range tests {
fakeClient := &FakeRESTClient{
......
......@@ -21,8 +21,8 @@ import (
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/expapi"
"k8s.io/kubernetes/pkg/expapi/testapi"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
)
......@@ -42,14 +42,14 @@ func TestHorizontalPodAutoscalerCreate(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "POST",
Path: testapi.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, ""),
Path: testapi.Experimental.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, ""),
Query: buildQueryValues(nil),
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 {
t.Fatalf("unexpected error: %v", err)
}
......@@ -67,14 +67,14 @@ func TestHorizontalPodAutoscalerGet(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, "abc"),
Path: testapi.Experimental.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, "abc"),
Query: buildQueryValues(nil),
Body: nil,
},
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)
}
......@@ -93,13 +93,13 @@ func TestHorizontalPodAutoscalerList(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, ""),
Path: testapi.Experimental.ResourcePath(getHorizontalPodAutoscalersResoureName(), ns, ""),
Query: buildQueryValues(nil),
Body: nil,
},
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)
}
......@@ -113,20 +113,20 @@ func TestHorizontalPodAutoscalerUpdate(t *testing.T) {
},
}
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, err := c.Setup().Experimental().HorizontalPodAutoscalers(ns).Update(horizontalPodAutoscaler)
response, err := c.Setup(t).Experimental().HorizontalPodAutoscalers(ns).Update(horizontalPodAutoscaler)
c.Validate(t, response, err)
}
func TestHorizontalPodAutoscalerDelete(t *testing.T) {
ns := api.NamespaceDefault
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},
}
err := c.Setup().Experimental().HorizontalPodAutoscalers(ns).Delete("foo", nil)
err := c.Setup(t).Experimental().HorizontalPodAutoscalers(ns).Delete("foo", nil)
c.Validate(t, nil, err)
}
......@@ -134,10 +134,10 @@ func TestHorizontalPodAutoscalerWatch(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePathWithPrefix("watch", getHorizontalPodAutoscalersResoureName(), "", ""),
Path: testapi.Experimental.ResourcePathWithPrefix("watch", getHorizontalPodAutoscalersResoureName(), "", ""),
Query: url.Values{"resourceVersion": []string{}}},
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)
}
......@@ -56,14 +56,14 @@ func TestLimitRangeCreate(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "POST",
Path: testapi.ResourcePath(getLimitRangesResourceName(), ns, ""),
Path: testapi.Default.ResourcePath(getLimitRangesResourceName(), ns, ""),
Query: buildQueryValues(nil),
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)
}
......@@ -92,14 +92,14 @@ func TestLimitRangeGet(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getLimitRangesResourceName(), ns, "abc"),
Path: testapi.Default.ResourcePath(getLimitRangesResourceName(), ns, "abc"),
Query: buildQueryValues(nil),
Body: nil,
},
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)
}
......@@ -116,13 +116,13 @@ func TestLimitRangeList(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getLimitRangesResourceName(), ns, ""),
Path: testapi.Default.ResourcePath(getLimitRangesResourceName(), ns, ""),
Query: buildQueryValues(nil),
Body: nil,
},
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)
}
......@@ -150,10 +150,10 @@ func TestLimitRangeUpdate(t *testing.T) {
},
}
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, err := c.Setup().LimitRanges(ns).Update(limitRange)
response, err := c.Setup(t).LimitRanges(ns).Update(limitRange)
c.Validate(t, response, err)
}
......@@ -180,10 +180,10 @@ func TestInvalidLimitRangeUpdate(t *testing.T) {
},
}
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},
}
_, err := c.Setup().LimitRanges(ns).Update(limitRange)
_, err := c.Setup(t).LimitRanges(ns).Update(limitRange)
if err == nil {
t.Errorf("Expected an error due to missing ResourceVersion")
}
......@@ -192,10 +192,10 @@ func TestInvalidLimitRangeUpdate(t *testing.T) {
func TestLimitRangeDelete(t *testing.T) {
ns := api.NamespaceDefault
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},
}
err := c.Setup().LimitRanges(ns).Delete("foo")
err := c.Setup(t).LimitRanges(ns).Delete("foo")
c.Validate(t, nil, err)
}
......@@ -203,10 +203,10 @@ func TestLimitRangeWatch(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePathWithPrefix("watch", getLimitRangesResourceName(), "", ""),
Path: testapi.Default.ResourcePathWithPrefix("watch", getLimitRangesResourceName(), "", ""),
Query: url.Values{"resourceVersion": []string{}}},
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)
}
......@@ -34,14 +34,14 @@ func TestNamespaceCreate(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "POST",
Path: testapi.ResourcePath("namespaces", "", ""),
Path: testapi.Default.ResourcePath("namespaces", "", ""),
Body: namespace,
},
Response: Response{StatusCode: 200, Body: namespace},
}
// 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 {
t.Errorf("%#v should be nil.", err)
......@@ -59,13 +59,13 @@ func TestNamespaceGet(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath("namespaces", "", "foo"),
Path: testapi.Default.ResourcePath("namespaces", "", "foo"),
Body: nil,
},
Response: Response{StatusCode: 200, Body: namespace},
}
response, err := c.Setup().Namespaces().Get("foo")
response, err := c.Setup(t).Namespaces().Get("foo")
if err != nil {
t.Errorf("%#v should be nil.", err)
......@@ -87,12 +87,12 @@ func TestNamespaceList(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath("namespaces", "", ""),
Path: testapi.Default.ResourcePath("namespaces", "", ""),
Body: nil,
},
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 {
t.Errorf("%#v should be nil.", err)
......@@ -125,10 +125,10 @@ func TestNamespaceUpdate(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "PUT",
Path: testapi.ResourcePath("namespaces", "", "foo")},
Path: testapi.Default.ResourcePath("namespaces", "", "foo")},
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)
}
......@@ -149,20 +149,20 @@ func TestNamespaceFinalize(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "PUT",
Path: testapi.ResourcePath("namespaces", "", "foo") + "/finalize",
Path: testapi.Default.ResourcePath("namespaces", "", "foo") + "/finalize",
},
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)
}
func TestNamespaceDelete(t *testing.T) {
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},
}
err := c.Setup().Namespaces().Delete("foo")
err := c.Setup(t).Namespaces().Delete("foo")
c.Validate(t, nil, err)
}
......@@ -170,10 +170,10 @@ func TestNamespaceWatch(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePathWithPrefix("watch", "namespaces", "", ""),
Path: testapi.Default.ResourcePathWithPrefix("watch", "namespaces", "", ""),
Query: url.Values{"resourceVersion": []string{}}},
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)
}
......@@ -35,20 +35,20 @@ func TestListMinions(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getNodesResourceName(), "", ""),
Path: testapi.Default.ResourcePath(getNodesResourceName(), "", ""),
},
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)
}
func TestListMinionsLabels(t *testing.T) {
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Version())
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Default.Version())
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getNodesResourceName(), "", ""),
Path: testapi.Default.ResourcePath(getNodesResourceName(), "", ""),
Query: buildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
Response: Response{
StatusCode: 200,
......@@ -66,7 +66,7 @@ func TestListMinionsLabels(t *testing.T) {
},
},
}
c.Setup()
c.Setup(t)
c.QueryValidator[labelSelectorQueryParamName] = validateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
receivedNodeList, err := c.Nodes().List(selector, fields.Everything())
......@@ -77,17 +77,17 @@ func TestGetMinion(t *testing.T) {
c := &testClient{
Request: testRequest{
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, err := c.Setup().Nodes().Get("1")
response, err := c.Setup(t).Nodes().Get("1")
c.Validate(t, response, err)
}
func TestGetMinionWithNoName(t *testing.T) {
c := &testClient{Error: true}
receivedNode, err := c.Setup().Nodes().Get("")
receivedNode, err := c.Setup(t).Nodes().Get("")
if (err != nil) && (err.Error() != nameRequiredError) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
}
......@@ -113,14 +113,14 @@ func TestCreateMinion(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "POST",
Path: testapi.ResourcePath(getNodesResourceName(), "", ""),
Path: testapi.Default.ResourcePath(getNodesResourceName(), "", ""),
Body: requestMinion},
Response: Response{
StatusCode: 200,
Body: requestMinion,
},
}
receivedMinion, err := c.Setup().Nodes().Create(requestMinion)
receivedMinion, err := c.Setup(t).Nodes().Create(requestMinion)
c.Validate(t, receivedMinion, err)
}
......@@ -128,11 +128,11 @@ func TestDeleteMinion(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "DELETE",
Path: testapi.ResourcePath(getNodesResourceName(), "", "foo"),
Path: testapi.Default.ResourcePath(getNodesResourceName(), "", "foo"),
},
Response: Response{StatusCode: 200},
}
err := c.Setup().Nodes().Delete("foo")
err := c.Setup(t).Nodes().Delete("foo")
c.Validate(t, nil, err)
}
......@@ -155,10 +155,10 @@ func TestUpdateMinion(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "PUT",
Path: testapi.ResourcePath(getNodesResourceName(), "", "foo"),
Path: testapi.Default.ResourcePath(getNodesResourceName(), "", "foo"),
},
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)
}
......@@ -49,14 +49,14 @@ func TestPersistentVolumeCreate(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "POST",
Path: testapi.ResourcePath(getPersistentVolumesResoureName(), "", ""),
Path: testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", ""),
Query: buildQueryValues(nil),
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)
}
......@@ -78,14 +78,14 @@ func TestPersistentVolumeGet(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getPersistentVolumesResoureName(), "", "abc"),
Path: testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", "abc"),
Query: buildQueryValues(nil),
Body: nil,
},
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)
}
......@@ -100,13 +100,13 @@ func TestPersistentVolumeList(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getPersistentVolumesResoureName(), "", ""),
Path: testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", ""),
Query: buildQueryValues(nil),
Body: nil,
},
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)
}
......@@ -126,10 +126,10 @@ func TestPersistentVolumeUpdate(t *testing.T) {
},
}
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, err := c.Setup().PersistentVolumes().Update(persistentVolume)
response, err := c.Setup(t).PersistentVolumes().Update(persistentVolume)
c.Validate(t, response, err)
}
......@@ -155,20 +155,20 @@ func TestPersistentVolumeStatusUpdate(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "PUT",
Path: testapi.ResourcePath(getPersistentVolumesResoureName(), "", "abc") + "/status",
Path: testapi.Default.ResourcePath(getPersistentVolumesResoureName(), "", "abc") + "/status",
Query: buildQueryValues(nil)},
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)
}
func TestPersistentVolumeDelete(t *testing.T) {
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},
}
err := c.Setup().PersistentVolumes().Delete("foo")
err := c.Setup(t).PersistentVolumes().Delete("foo")
c.Validate(t, nil, err)
}
......@@ -176,10 +176,10 @@ func TestPersistentVolumeWatch(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePathWithPrefix("watch", getPersistentVolumesResoureName(), "", ""),
Path: testapi.Default.ResourcePathWithPrefix("watch", getPersistentVolumesResoureName(), "", ""),
Query: url.Values{"resourceVersion": []string{}}},
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)
}
......@@ -53,14 +53,14 @@ func TestPersistentVolumeClaimCreate(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "POST",
Path: testapi.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, ""),
Path: testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, ""),
Query: buildQueryValues(nil),
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)
}
......@@ -86,14 +86,14 @@ func TestPersistentVolumeClaimGet(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "abc"),
Path: testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "abc"),
Query: buildQueryValues(nil),
Body: nil,
},
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)
}
......@@ -109,13 +109,13 @@ func TestPersistentVolumeClaimList(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, ""),
Path: testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, ""),
Query: buildQueryValues(nil),
Body: nil,
},
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)
}
......@@ -139,10 +139,10 @@ func TestPersistentVolumeClaimUpdate(t *testing.T) {
},
}
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, err := c.Setup().PersistentVolumeClaims(ns).Update(persistentVolumeClaim)
response, err := c.Setup(t).PersistentVolumeClaims(ns).Update(persistentVolumeClaim)
c.Validate(t, response, err)
}
......@@ -171,21 +171,21 @@ func TestPersistentVolumeClaimStatusUpdate(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "PUT",
Path: testapi.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "abc") + "/status",
Path: testapi.Default.ResourcePath(getPersistentVolumeClaimsResoureName(), ns, "abc") + "/status",
Query: buildQueryValues(nil)},
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)
}
func TestPersistentVolumeClaimDelete(t *testing.T) {
ns := api.NamespaceDefault
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},
}
err := c.Setup().PersistentVolumeClaims(ns).Delete("foo")
err := c.Setup(t).PersistentVolumeClaims(ns).Delete("foo")
c.Validate(t, nil, err)
}
......@@ -193,10 +193,10 @@ func TestPersistentVolumeClaimWatch(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePathWithPrefix("watch", getPersistentVolumeClaimsResoureName(), "", ""),
Path: testapi.Default.ResourcePathWithPrefix("watch", getPersistentVolumeClaimsResoureName(), "", ""),
Query: url.Values{"resourceVersion": []string{}}},
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)
}
......@@ -42,14 +42,14 @@ func TestPodTemplateCreate(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "POST",
Path: testapi.ResourcePath(getPodTemplatesResoureName(), ns, ""),
Path: testapi.Default.ResourcePath(getPodTemplatesResoureName(), ns, ""),
Query: buildQueryValues(nil),
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)
}
......@@ -65,14 +65,14 @@ func TestPodTemplateGet(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getPodTemplatesResoureName(), ns, "abc"),
Path: testapi.Default.ResourcePath(getPodTemplatesResoureName(), ns, "abc"),
Query: buildQueryValues(nil),
Body: nil,
},
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)
}
......@@ -91,13 +91,13 @@ func TestPodTemplateList(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getPodTemplatesResoureName(), ns, ""),
Path: testapi.Default.ResourcePath(getPodTemplatesResoureName(), ns, ""),
Query: buildQueryValues(nil),
Body: nil,
},
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)
}
......@@ -112,20 +112,20 @@ func TestPodTemplateUpdate(t *testing.T) {
Template: api.PodTemplateSpec{},
}
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, err := c.Setup().PodTemplates(ns).Update(podTemplate)
response, err := c.Setup(t).PodTemplates(ns).Update(podTemplate)
c.Validate(t, response, err)
}
func TestPodTemplateDelete(t *testing.T) {
ns := api.NamespaceDefault
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},
}
err := c.Setup().PodTemplates(ns).Delete("foo", nil)
err := c.Setup(t).PodTemplates(ns).Delete("foo", nil)
c.Validate(t, nil, err)
}
......@@ -133,10 +133,10 @@ func TestPodTemplateWatch(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePathWithPrefix("watch", getPodTemplatesResoureName(), "", ""),
Path: testapi.Default.ResourcePathWithPrefix("watch", getPodTemplatesResoureName(), "", ""),
Query: url.Values{"resourceVersion": []string{}}},
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)
}
......@@ -29,17 +29,17 @@ import (
func TestListEmptyPods(t *testing.T) {
ns := api.NamespaceDefault
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{}},
}
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)
}
func TestListPods(t *testing.T) {
ns := api.NamespaceDefault
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{
Items: []api.Pod{
......@@ -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)
}
func TestListPodsLabels(t *testing.T) {
ns := api.NamespaceDefault
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Version())
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Default.Version())
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath("pods", ns, ""),
Path: testapi.Default.ResourcePath("pods", ns, ""),
Query: buildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
Response: Response{
StatusCode: 200,
......@@ -89,7 +89,7 @@ func TestListPodsLabels(t *testing.T) {
},
},
}
c.Setup()
c.Setup(t)
c.QueryValidator[labelSelectorQueryParamName] = validateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
receivedPodList, err := c.Pods(ns).List(selector, fields.Everything())
......@@ -99,7 +99,7 @@ func TestListPodsLabels(t *testing.T) {
func TestGetPod(t *testing.T) {
ns := api.NamespaceDefault
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{
StatusCode: 200,
Body: &api.Pod{
......@@ -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)
}
func TestGetPodWithNoName(t *testing.T) {
ns := api.NamespaceDefault
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) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
}
......@@ -133,10 +133,10 @@ func TestGetPodWithNoName(t *testing.T) {
func TestDeletePod(t *testing.T) {
ns := api.NamespaceDefault
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},
}
err := c.Setup().Pods(ns).Delete("foo", nil)
err := c.Setup(t).Pods(ns).Delete("foo", nil)
c.Validate(t, nil, err)
}
......@@ -154,13 +154,13 @@ func TestCreatePod(t *testing.T) {
},
}
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{
StatusCode: 200,
Body: requestPod,
},
}
receivedPod, err := c.Setup().Pods(ns).Create(requestPod)
receivedPod, err := c.Setup(t).Pods(ns).Create(requestPod)
c.Validate(t, receivedPod, err)
}
......@@ -180,9 +180,9 @@ func TestUpdatePod(t *testing.T) {
},
}
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},
}
receivedPod, err := c.Setup().Pods(ns).Update(requestPod)
receivedPod, err := c.Setup(t).Pods(ns).Update(requestPod)
c.Validate(t, receivedPod, err)
}
......@@ -33,7 +33,7 @@ func TestListControllers(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getRCResourceName(), ns, ""),
Path: testapi.Default.ResourcePath(getRCResourceName(), ns, ""),
},
Response: Response{StatusCode: 200,
Body: &api.ReplicationControllerList{
......@@ -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)
}
......@@ -63,7 +63,7 @@ func TestListControllers(t *testing.T) {
func TestGetController(t *testing.T) {
ns := api.NamespaceDefault
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{
StatusCode: 200,
Body: &api.ReplicationController{
......@@ -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)
}
func TestGetControllerWithNoName(t *testing.T) {
ns := api.NamespaceDefault
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) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
}
......@@ -102,7 +102,7 @@ func TestUpdateController(t *testing.T) {
ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"},
}
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{
StatusCode: 200,
Body: &api.ReplicationController{
......@@ -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)
}
func TestDeleteController(t *testing.T) {
ns := api.NamespaceDefault
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},
}
err := c.Setup().ReplicationControllers(ns).Delete("foo")
err := c.Setup(t).ReplicationControllers(ns).Delete("foo")
c.Validate(t, nil, err)
}
......@@ -140,7 +140,7 @@ func TestCreateController(t *testing.T) {
ObjectMeta: api.ObjectMeta{Name: "foo"},
}
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{
StatusCode: 200,
Body: &api.ReplicationController{
......@@ -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)
}
......@@ -52,14 +52,14 @@ func TestResourceQuotaCreate(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "POST",
Path: testapi.ResourcePath(getResourceQuotasResoureName(), ns, ""),
Path: testapi.Default.ResourcePath(getResourceQuotasResoureName(), ns, ""),
Query: buildQueryValues(nil),
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)
}
......@@ -84,14 +84,14 @@ func TestResourceQuotaGet(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getResourceQuotasResoureName(), ns, "abc"),
Path: testapi.Default.ResourcePath(getResourceQuotasResoureName(), ns, "abc"),
Query: buildQueryValues(nil),
Body: nil,
},
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)
}
......@@ -108,13 +108,13 @@ func TestResourceQuotaList(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath(getResourceQuotasResoureName(), ns, ""),
Path: testapi.Default.ResourcePath(getResourceQuotasResoureName(), ns, ""),
Query: buildQueryValues(nil),
Body: nil,
},
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)
}
......@@ -138,10 +138,10 @@ func TestResourceQuotaUpdate(t *testing.T) {
},
}
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, err := c.Setup().ResourceQuotas(ns).Update(resourceQuota)
response, err := c.Setup(t).ResourceQuotas(ns).Update(resourceQuota)
c.Validate(t, response, err)
}
......@@ -167,21 +167,21 @@ func TestResourceQuotaStatusUpdate(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "PUT",
Path: testapi.ResourcePath(getResourceQuotasResoureName(), ns, "abc") + "/status",
Path: testapi.Default.ResourcePath(getResourceQuotasResoureName(), ns, "abc") + "/status",
Query: buildQueryValues(nil)},
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)
}
func TestResourceQuotaDelete(t *testing.T) {
ns := api.NamespaceDefault
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},
}
err := c.Setup().ResourceQuotas(ns).Delete("foo")
err := c.Setup(t).ResourceQuotas(ns).Delete("foo")
c.Validate(t, nil, err)
}
......@@ -189,10 +189,10 @@ func TestResourceQuotaWatch(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePathWithPrefix("watch", getResourceQuotasResoureName(), "", ""),
Path: testapi.Default.ResourcePathWithPrefix("watch", getResourceQuotasResoureName(), "", ""),
Query: url.Values{"resourceVersion": []string{}}},
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)
}
......@@ -35,8 +35,8 @@ func TestSetsCodec(t *testing.T) {
Prefix string
Codec runtime.Codec
}{
testapi.Version(): {false, "/api/" + testapi.Version() + "/", testapi.Codec()},
"invalidVersion": {true, "", nil},
testapi.Default.Version(): {false, "/api/" + testapi.Default.Version() + "/", testapi.Default.Codec()},
"invalidVersion": {true, "", nil},
}
for version, expected := range testCases {
client, err := New(&Config{Host: "127.0.0.1", Version: version})
......@@ -60,13 +60,13 @@ func TestSetsCodec(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")
}
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")
}
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)
}
}
......@@ -79,17 +79,17 @@ func TestValidatesHostParameter(t *testing.T) {
URL string
Err bool
}{
{"127.0.0.1", "", "http://127.0.0.1/" + testapi.Version() + "/", false},
{"127.0.0.1:8080", "", "http://127.0.0.1:8080/" + testapi.Version() + "/", false},
{"foo.bar.com", "", "http://foo.bar.com/" + testapi.Version() + "/", false},
{"http://host/prefix", "", "http://host/prefix/" + testapi.Version() + "/", false},
{"http://host", "", "http://host/" + testapi.Version() + "/", false},
{"http://host", "/", "http://host/" + testapi.Version() + "/", false},
{"http://host", "/other", "http://host/other/" + 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.Default.Version() + "/", false},
{"foo.bar.com", "", "http://foo.bar.com/" + testapi.Default.Version() + "/", false},
{"http://host/prefix", "", "http://host/prefix/" + testapi.Default.Version() + "/", false},
{"http://host", "", "http://host/" + testapi.Default.Version() + "/", false},
{"http://host", "/", "http://host/" + testapi.Default.Version() + "/", false},
{"http://host", "/other", "http://host/other/" + testapi.Default.Version() + "/", false},
{"host/server", "", "", true},
}
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 {
case err == nil && testCase.Err:
t.Errorf("expected error but was nil")
......@@ -120,8 +120,8 @@ func TestDoRequestBearer(t *testing.T) {
request, _ := http.NewRequest("GET", testServer.URL, nil)
c, err := RESTClientFor(&Config{
Host: testServer.URL,
Version: testapi.Version(),
Codec: testapi.Codec(),
Version: testapi.Default.Version(),
Codec: testapi.Default.Codec(),
BearerToken: "test",
})
if err != nil {
......@@ -148,8 +148,8 @@ func TestDoRequestWithoutPassword(t *testing.T) {
defer testServer.Close()
c, err := RESTClientFor(&Config{
Host: testServer.URL,
Version: testapi.Version(),
Codec: testapi.Codec(),
Version: testapi.Default.Version(),
Codec: testapi.Default.Codec(),
Username: "test",
})
if err != nil {
......@@ -172,7 +172,7 @@ func TestDoRequestWithoutPassword(t *testing.T) {
if body != nil {
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) {
......@@ -187,8 +187,8 @@ func TestDoRequestSuccess(t *testing.T) {
defer testServer.Close()
c, err := RESTClientFor(&Config{
Host: testServer.URL,
Version: testapi.Version(),
Codec: testapi.Codec(),
Version: testapi.Default.Version(),
Codec: testapi.Default.Codec(),
Username: "user",
Password: "pass",
})
......@@ -209,7 +209,7 @@ func TestDoRequestSuccess(t *testing.T) {
if !reflect.DeepEqual(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) {
......@@ -230,8 +230,8 @@ func TestDoRequestFailed(t *testing.T) {
defer testServer.Close()
c, err := RESTClientFor(&Config{
Host: testServer.URL,
Version: testapi.Version(),
Codec: testapi.Codec(),
Version: testapi.Default.Version(),
Codec: testapi.Default.Codec(),
})
if err != nil {
t.Fatalf("unexpected error: %v", err)
......@@ -262,8 +262,8 @@ func TestDoRequestCreated(t *testing.T) {
defer testServer.Close()
c, err := RESTClientFor(&Config{
Host: testServer.URL,
Version: testapi.Version(),
Codec: testapi.Codec(),
Version: testapi.Default.Version(),
Codec: testapi.Default.Codec(),
Username: "user",
Password: "pass",
})
......@@ -285,5 +285,5 @@ func TestDoRequestCreated(t *testing.T) {
if !reflect.DeepEqual(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) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath("services", ns, ""),
Path: testapi.Default.ResourcePath("services", ns, ""),
Query: buildQueryValues(nil)},
Response: Response{StatusCode: 200,
Body: &api.ServiceList{
......@@ -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)
c.Validate(t, receivedServiceList, err)
}
func TestListServicesLabels(t *testing.T) {
ns := api.NamespaceDefault
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Version())
labelSelectorQueryParamName := api.LabelSelectorQueryParam(testapi.Default.Version())
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath("services", ns, ""),
Path: testapi.Default.ResourcePath("services", ns, ""),
Query: buildQueryValues(url.Values{labelSelectorQueryParamName: []string{"foo=bar,name=baz"}})},
Response: Response{StatusCode: 200,
Body: &api.ServiceList{
......@@ -87,7 +87,7 @@ func TestListServicesLabels(t *testing.T) {
},
},
}
c.Setup()
c.Setup(t)
c.QueryValidator[labelSelectorQueryParamName] = validateLabels
selector := labels.Set{"foo": "bar", "name": "baz"}.AsSelector()
receivedServiceList, err := c.Services(ns).List(selector)
......@@ -99,18 +99,18 @@ func TestGetService(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath("services", ns, "1"),
Path: testapi.Default.ResourcePath("services", ns, "1"),
Query: buildQueryValues(nil)},
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)
}
func TestGetServiceWithNoName(t *testing.T) {
ns := api.NamespaceDefault
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) {
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
}
......@@ -123,12 +123,12 @@ func TestCreateService(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "POST",
Path: testapi.ResourcePath("services", ns, ""),
Path: testapi.Default.ResourcePath("services", ns, ""),
Body: &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1"}},
Query: buildQueryValues(nil)},
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)
}
......@@ -136,20 +136,20 @@ func TestUpdateService(t *testing.T) {
ns := api.NamespaceDefault
svc := &api.Service{ObjectMeta: api.ObjectMeta{Name: "service-1", ResourceVersion: "1"}}
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, err := c.Setup().Services(ns).Update(svc)
response, err := c.Setup(t).Services(ns).Update(svc)
c.Validate(t, response, err)
}
func TestDeleteService(t *testing.T) {
ns := api.NamespaceDefault
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},
}
err := c.Setup().Services(ns).Delete("1")
err := c.Setup(t).Services(ns).Delete("1")
c.Validate(t, nil, err)
}
......@@ -159,11 +159,11 @@ func TestServiceProxyGet(t *testing.T) {
c := &testClient{
Request: testRequest{
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"}}),
},
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)
}
......@@ -80,7 +80,7 @@ func makeTestServer(t *testing.T, responses map[string]*serverResponse) (*httpte
mkHandler := func(url string, response serverResponse) *util.FakeHandler {
handler := util.FakeHandler{
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)
glog.Infof("Will handle %s", url)
......@@ -176,8 +176,8 @@ func TestSyncEndpointsItemsPreserveNoSelector(t *testing.T) {
})
defer testServer.Close()
kubeClient := client.NewOrDie(&client.Config{Host: testServer.URL, Version: testapi.Version()})
expClient := client.NewExperimentalOrDie(&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.Experimental.Version()})
fakeRC := fakeResourceConsumptionClient{metrics: map[api.ResourceName]expapi.ResourceConsumption{
api.ResourceCPU: {Resource: api.ResourceCPU, Quantity: resource.MustParse("650m")},
......
......@@ -57,7 +57,7 @@ func makeTestServer(t *testing.T, responses map[string]*serverResponse) (*httpte
mkHandler := func(url string, response serverResponse) *util.FakeHandler {
handler := util.FakeHandler{
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)
glog.Infof("Will handle %s", url)
......@@ -119,7 +119,7 @@ func TestHeapsterResourceConsumptionGet(t *testing.T) {
})
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)
......
......@@ -48,7 +48,7 @@ func NewFakeControllerExpectationsLookup(ttl time.Duration) (*ControllerExpectat
func newReplicationController(replicas int) *api.ReplicationController {
rc := &api.ReplicationController{
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()},
TypeMeta: api.TypeMeta{APIVersion: testapi.Default.Version()},
ObjectMeta: api.ObjectMeta{
UID: util.NewUUID(),
Name: "foobar",
......@@ -181,14 +181,14 @@ func TestControllerExpectations(t *testing.T) {
func TestCreateReplica(t *testing.T) {
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{
StatusCode: 200,
ResponseBody: string(body),
}
testServer := httptest.NewServer(&fakeHandler)
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{
KubeClient: client,
......@@ -207,7 +207,7 @@ func TestCreateReplica(t *testing.T) {
},
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))
if err != nil {
t.Errorf("Unexpected error: %#v", err)
......
......@@ -36,11 +36,11 @@ type serverResponse struct {
func makeTestServer(t *testing.T, namespace string, serviceAccountResponse serverResponse) (*httptest.Server, *util.FakeHandler) {
fakeServiceAccountsHandler := util.FakeHandler{
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.Handle(testapi.ResourcePath("serviceAccounts", namespace, ""), &fakeServiceAccountsHandler)
mux.Handle(testapi.Default.ResourcePath("serviceAccounts", namespace, ""), &fakeServiceAccountsHandler)
mux.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
t.Errorf("unexpected request: %v", req.RequestURI)
res.WriteHeader(http.StatusNotFound)
......
......@@ -391,7 +391,7 @@ func TestAnnotateErrors(t *testing.T) {
f, tf, _ := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Namespace = "test"
tf.ClientConfig = &client.Config{Version: testapi.Version()}
tf.ClientConfig = &client.Config{Version: testapi.Default.Version()}
buf := bytes.NewBuffer([]byte{})
cmd := NewCmdAnnotate(f, buf)
......@@ -447,7 +447,7 @@ func TestAnnotateObject(t *testing.T) {
}),
}
tf.Namespace = "test"
tf.ClientConfig = &client.Config{Version: testapi.Version()}
tf.ClientConfig = &client.Config{Version: testapi.Default.Version()}
options := &AnnotateOptions{}
args := []string{"pods/foo", "a=b", "c-"}
......@@ -494,7 +494,7 @@ func TestAnnotateObjectFromFile(t *testing.T) {
}),
}
tf.Namespace = "test"
tf.ClientConfig = &client.Config{Version: testapi.Version()}
tf.ClientConfig = &client.Config{Version: testapi.Default.Version()}
options := &AnnotateOptions{}
options.filenames = []string{"../../../examples/cassandra/cassandra.yaml"}
......@@ -544,7 +544,7 @@ func TestAnnotateMultipleObjects(t *testing.T) {
}),
}
tf.Namespace = "test"
tf.ClientConfig = &client.Config{Version: testapi.Version()}
tf.ClientConfig = &client.Config{Version: testapi.Default.Version()}
options := &AnnotateOptions{}
options.all = true
......
......@@ -105,7 +105,7 @@ func TestPodAndContainerAttach(t *testing.T) {
}
func TestAttach(t *testing.T) {
version := testapi.Version()
version := testapi.Default.Version()
tests := []struct {
name, version, podPath, attachPath, container string
pod *api.Pod
......
......@@ -79,10 +79,10 @@ func newExternalScheme() (*runtime.Scheme, meta.RESTMapper, runtime.Codec) {
scheme.AddKnownTypeWithName("", "Type", &internalType{})
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.
scheme.AddKnownTypeWithName(testapi.Version(), "Type", &ExternalType2{})
scheme.AddKnownTypeWithName(testapi.Default.Version(), "Type", &ExternalType2{})
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) {
return &meta.VersionInterfaces{
Codec: runtime.CodecFor(scheme, version),
......@@ -228,7 +228,7 @@ func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) {
generator, ok := generators[name]
return generator, ok
},
}, t, testapi.Codec()
}, t, testapi.Default.Codec()
}
func objBody(codec runtime.Codec, obj runtime.Object) io.ReadCloser {
......@@ -245,7 +245,7 @@ func stringBody(body string) io.ReadCloser {
//func TestClientVersions(t *testing.T) {
// f := cmdutil.NewFactory(nil)
//
// version := testapi.Version()
// version := testapi.Default.Version()
// mapping := &meta.RESTMapping{
// APIVersion: version,
// }
......
......@@ -577,13 +577,13 @@ func TestNewEmptyCluster(t *testing.T) {
func TestAdditionalCluster(t *testing.T) {
expectedConfig := newRedFederalCowHammerConfig()
cluster := clientcmdapi.NewCluster()
cluster.APIVersion = testapi.Version()
cluster.APIVersion = testapi.Default.Version()
cluster.CertificateAuthority = "/ca-location"
cluster.InsecureSkipTLSVerify = false
cluster.Server = "serverlocation"
expectedConfig.Clusters["different-cluster"] = cluster
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(),
expectedConfig: expectedConfig,
}
......
......@@ -416,12 +416,12 @@ func TestDeleteMultipleSelector(t *testing.T) {
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
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)
}
return &http.Response{StatusCode: 200, Body: objBody(codec, pods)}, nil
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)
}
return &http.Response{StatusCode: 200, Body: objBody(codec, svc)}, nil
......
......@@ -129,7 +129,7 @@ func TestPodAndContainer(t *testing.T) {
}
func TestExec(t *testing.T) {
version := testapi.Version()
version := testapi.Default.Version()
tests := []struct {
name, version, podPath, execPath, container string
pod *api.Pod
......
......@@ -176,14 +176,14 @@ func TestGetUnknownSchemaObjectListGeneric(t *testing.T) {
rcVersion: latest.Version, // see expected behavior 3b
},
"handles common version": {
outputVersion: testapi.Version(),
listVersion: testapi.Version(),
outputVersion: testapi.Default.Version(),
listVersion: testapi.Default.Version(),
testtypeVersion: "unlikelyversion",
rcVersion: testapi.Version(),
rcVersion: testapi.Default.Version(),
},
}
for k, test := range testCases {
apiCodec := runtime.CodecFor(api.Scheme, testapi.Version())
apiCodec := runtime.CodecFor(api.Scheme, testapi.Default.Version())
regularClient := &client.FakeRESTClient{
Codec: apiCodec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
......@@ -440,7 +440,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
}),
}
tf.Namespace = "test"
tf.ClientConfig = &client.Config{Version: testapi.Version()}
tf.ClientConfig = &client.Config{Version: testapi.Default.Version()}
buf := bytes.NewBuffer([]byte{})
cmd := NewCmdGet(f, buf)
......@@ -488,7 +488,7 @@ func TestGetMultipleTypeObjectsWithSelector(t *testing.T) {
tf.Client = &client.FakeRESTClient{
Codec: codec,
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)
}
switch req.URL.Path {
......@@ -624,7 +624,7 @@ func TestWatchSelector(t *testing.T) {
tf.Client = &client.FakeRESTClient{
Codec: codec,
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)
}
switch req.URL.Path {
......
......@@ -300,7 +300,7 @@ func TestLabelErrors(t *testing.T) {
f, tf, _ := NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Namespace = "test"
tf.ClientConfig = &client.Config{Version: testapi.Version()}
tf.ClientConfig = &client.Config{Version: testapi.Default.Version()}
buf := bytes.NewBuffer([]byte{})
cmd := NewCmdLabel(f, buf)
......@@ -353,7 +353,7 @@ func TestLabelForResourceFromFile(t *testing.T) {
}),
}
tf.Namespace = "test"
tf.ClientConfig = &client.Config{Version: testapi.Version()}
tf.ClientConfig = &client.Config{Version: testapi.Default.Version()}
buf := bytes.NewBuffer([]byte{})
cmd := NewCmdLabel(f, buf)
......@@ -402,7 +402,7 @@ func TestLabelMultipleObjects(t *testing.T) {
}),
}
tf.Namespace = "test"
tf.ClientConfig = &client.Config{Version: testapi.Version()}
tf.ClientConfig = &client.Config{Version: testapi.Default.Version()}
buf := bytes.NewBuffer([]byte{})
cmd := NewCmdLabel(f, buf)
......
......@@ -39,7 +39,7 @@ func (f *fakePortForwarder) ForwardPorts(req *client.Request, config *client.Con
}
func TestPortForward(t *testing.T) {
version := testapi.Version()
version := testapi.Default.Version()
tests := []struct {
name, version, podPath, pfPath, container string
......@@ -101,7 +101,7 @@ func TestPortForward(t *testing.T) {
}
func TestPortForwardWithPFlag(t *testing.T) {
version := testapi.Version()
version := testapi.Default.Version()
tests := []struct {
name, version, podPath, pfPath, container string
......
......@@ -49,7 +49,7 @@ func TestMerge(t *testing.T) {
Name: "foo",
},
},
fragment: fmt.Sprintf(`{ "apiVersion": "%s" }`, testapi.Version()),
fragment: fmt.Sprintf(`{ "apiVersion": "%s" }`, testapi.Default.Version()),
expected: &api.Pod{
ObjectMeta: api.ObjectMeta{
Name: "foo",
......@@ -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{
ObjectMeta: api.ObjectMeta{
Name: "foo",
......@@ -108,7 +108,7 @@ func TestMerge(t *testing.T) {
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{
ObjectMeta: api.ObjectMeta{
Name: "foo",
......@@ -148,7 +148,7 @@ func TestMerge(t *testing.T) {
obj: &api.Service{
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{
Spec: api.ServiceSpec{
SessionAffinity: "None",
......@@ -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{
Spec: api.ServiceSpec{
SessionAffinity: "None",
......
......@@ -512,7 +512,7 @@ func TestResourceByNameAndEmptySelector(t *testing.T) {
func TestSelector(t *testing.T) {
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{
"/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, pods),
"/namespaces/test/services?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, svc),
......@@ -808,7 +808,7 @@ func TestSingularRootScopedObject(t *testing.T) {
func TestListObject(t *testing.T) {
pods, _ := testData()
labelKey := api.LabelSelectorQueryParam(testapi.Version())
labelKey := api.LabelSelectorQueryParam(testapi.Default.Version())
b := NewBuilder(latest.RESTMapper, api.Scheme, fakeClientWith("", t, map[string]string{
"/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, pods),
})).
......@@ -841,7 +841,7 @@ func TestListObject(t *testing.T) {
func TestListObjectWithDifferentVersions(t *testing.T) {
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{
"/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, pods),
"/namespaces/test/services?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, svc),
......
......@@ -34,7 +34,7 @@ import (
)
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.
......@@ -93,7 +93,7 @@ func TestHelperDelete(t *testing.T) {
}
for _, test := range tests {
client := &client.FakeRESTClient{
Codec: testapi.Codec(),
Codec: testapi.Default.Codec(),
Resp: test.Resp,
Err: test.HttpErr,
}
......@@ -184,7 +184,7 @@ func TestHelperCreate(t *testing.T) {
}
for i, test := range tests {
client := &client.FakeRESTClient{
Codec: testapi.Codec(),
Codec: testapi.Default.Codec(),
Resp: test.Resp,
Err: test.HttpErr,
}
......@@ -193,13 +193,13 @@ func TestHelperCreate(t *testing.T) {
}
modifier := &Helper{
RESTClient: client,
Codec: testapi.Codec(),
Versioner: testapi.MetadataAccessor(),
Codec: testapi.Default.Codec(),
Versioner: testapi.Default.MetadataAccessor(),
NamespaceScoped: true,
}
data := []byte{}
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)
if (err != nil) != test.Err {
......@@ -218,7 +218,7 @@ func TestHelperCreate(t *testing.T) {
t.Logf("got body: %s", string(body))
expect := []byte{}
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) {
t.Errorf("%d: unexpected body: %s", i, string(body))
......@@ -270,7 +270,7 @@ func TestHelperGet(t *testing.T) {
}
for _, test := range tests {
client := &client.FakeRESTClient{
Codec: testapi.Codec(),
Codec: testapi.Default.Codec(),
Resp: test.Resp,
Err: test.HttpErr,
}
......@@ -331,7 +331,7 @@ func TestHelperList(t *testing.T) {
t.Errorf("url doesn't contain name: %#v", req.URL)
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)
return false
}
......@@ -341,7 +341,7 @@ func TestHelperList(t *testing.T) {
}
for _, test := range tests {
client := &client.FakeRESTClient{
Codec: testapi.Codec(),
Codec: testapi.Default.Codec(),
Resp: test.Resp,
Err: test.HttpErr,
}
......@@ -349,7 +349,7 @@ func TestHelperList(t *testing.T) {
RESTClient: client,
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 {
t.Errorf("unexpected error: %t %v", test.Err, err)
}
......@@ -444,7 +444,7 @@ func TestHelperReplace(t *testing.T) {
}
for i, test := range tests {
client := &client.FakeRESTClient{
Codec: testapi.Codec(),
Codec: testapi.Default.Codec(),
Resp: test.Resp,
Err: test.HttpErr,
}
......@@ -453,13 +453,13 @@ func TestHelperReplace(t *testing.T) {
}
modifier := &Helper{
RESTClient: client,
Codec: testapi.Codec(),
Versioner: testapi.MetadataAccessor(),
Codec: testapi.Default.Codec(),
Versioner: testapi.Default.MetadataAccessor(),
NamespaceScoped: true,
}
data := []byte{}
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)
if (err != nil) != test.Err {
......@@ -478,7 +478,7 @@ func TestHelperReplace(t *testing.T) {
t.Logf("got body: %s", string(body))
expect := []byte{}
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) {
t.Errorf("%d: unexpected body: %s", i, string(body))
......
......@@ -49,7 +49,7 @@ func (ts *testStruct) IsAnAPIObject() {}
func init() {
api.Scheme.AddKnownTypes("", &testStruct{})
api.Scheme.AddKnownTypes(testapi.Version(), &testStruct{})
api.Scheme.AddKnownTypes(testapi.Default.Version(), &testStruct{})
}
var testData = testStruct{
......@@ -72,7 +72,7 @@ func TestVersionedPrinter(t *testing.T) {
return nil
}),
api.Scheme,
testapi.Version(),
testapi.Default.Version(),
)
if err := p.PrintObj(original, nil); err != nil {
t.Errorf("unexpected error: %v", err)
......@@ -110,7 +110,7 @@ func TestPrinter(t *testing.T) {
},
}
emptyListTest := &api.PodList{}
testapi, err := api.Scheme.ConvertToVersion(podTest, testapi.Version())
testapi, err := api.Scheme.ConvertToVersion(podTest, testapi.Default.Version())
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
......@@ -183,7 +183,7 @@ func testPrinter(t *testing.T, printer ResourcePrinter, unmarshalFunc func(data
}
// Use real decode function to undo the versioning process.
poutput = testStruct{}
err = runtime.YAMLDecoder(testapi.Codec()).DecodeInto(buf.Bytes(), &poutput)
err = runtime.YAMLDecoder(testapi.Default.Codec()).DecodeInto(buf.Bytes(), &poutput)
if err != nil {
t.Fatal(err)
}
......@@ -204,7 +204,7 @@ func testPrinter(t *testing.T, printer ResourcePrinter, unmarshalFunc func(data
}
// Use real decode function to undo the versioning process.
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 {
t.Fatal(err)
}
......@@ -430,7 +430,7 @@ func TestTemplateStrings(t *testing.T) {
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 {
buffer := &bytes.Buffer{}
......
......@@ -1008,7 +1008,7 @@ func TestUpdateExistingReplicationController(t *testing.T) {
}
func TestUpdateWithRetries(t *testing.T) {
codec := testapi.Codec()
codec := testapi.Default.Codec()
grace := int64(30)
rc := &api.ReplicationController{
ObjectMeta: api.ObjectMeta{Name: "rc",
......@@ -1055,7 +1055,7 @@ func TestUpdateWithRetries(t *testing.T) {
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
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]
updates = updates[1:]
// 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) {
delete(c.Spec.Selector, "baz")
}
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]
gets = gets[1:]
return get, nil
......@@ -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 = fakeClient.Client
......@@ -1115,7 +1115,7 @@ func objBody(codec runtime.Codec, obj runtime.Object) io.ReadCloser {
func TestAddDeploymentHash(t *testing.T) {
buf := &bytes.Buffer{}
codec := testapi.Codec()
codec := testapi.Default.Codec()
rc := &api.ReplicationController{
ObjectMeta: api.ObjectMeta{Name: "rc"},
Spec: api.ReplicationControllerSpec{
......@@ -1146,27 +1146,27 @@ func TestAddDeploymentHash(t *testing.T) {
Codec: codec,
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
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" {
t.Errorf("Unexpected query string: %s", req.URL.RawQuery)
}
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")
obj := readOrDie(t, req, codec)
podList.Items[0] = *(obj.(*api.Pod))
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")
obj := readOrDie(t, req, codec)
podList.Items[1] = *(obj.(*api.Pod))
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")
obj := readOrDie(t, req, codec)
podList.Items[2] = *(obj.(*api.Pod))
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
return &http.Response{StatusCode: 200, Body: objBody(codec, rc)}, nil
default:
......@@ -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 = fakeClient.Client
......
......@@ -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 {
t.Errorf("unexpected error: %v", err)
}
......@@ -70,7 +70,7 @@ func TestDecodeSinglePod(t *testing.T) {
}
for _, version := range registered.RegisteredVersions {
externalPod, err := testapi.Converter().ConvertToVersion(pod, version)
externalPod, err := testapi.Default.Converter().ConvertToVersion(pod, version)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
......@@ -119,7 +119,7 @@ func TestDecodePodList(t *testing.T) {
podList := &api.PodList{
Items: []api.Pod{*pod},
}
json, err := testapi.Codec().Encode(podList)
json, err := testapi.Default.Codec().Encode(podList)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
......@@ -135,7 +135,7 @@ func TestDecodePodList(t *testing.T) {
}
for _, version := range registered.RegisteredVersions {
externalPodList, err := testapi.Converter().ConvertToVersion(podList, version)
externalPodList, err := testapi.Default.Converter().ConvertToVersion(podList, version)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
......
......@@ -117,11 +117,11 @@ func TestReadPodsFromFile(t *testing.T) {
for _, testCase := range testCases {
func() {
var versionedPod runtime.Object
err := testapi.Converter().Convert(&testCase.pod, &versionedPod)
err := testapi.Default.Converter().Convert(&testCase.pod, &versionedPod)
if err != nil {
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 {
t.Fatalf("%s: error in encoding the pod: %v", testCase.desc, err)
}
......
......@@ -67,7 +67,7 @@ func TestExtractInvalidPods(t *testing.T) {
{
desc: "Invalid volume name",
pod: &api.Pod{
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()},
TypeMeta: api.TypeMeta{APIVersion: testapi.Default.Version()},
Spec: api.PodSpec{
Volumes: []api.Volume{{Name: "_INVALID_"}},
},
......@@ -76,7 +76,7 @@ func TestExtractInvalidPods(t *testing.T) {
{
desc: "Duplicate volume names",
pod: &api.Pod{
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()},
TypeMeta: api.TypeMeta{APIVersion: testapi.Default.Version()},
Spec: api.PodSpec{
Volumes: []api.Volume{{Name: "repeated"}, {Name: "repeated"}},
},
......@@ -85,7 +85,7 @@ func TestExtractInvalidPods(t *testing.T) {
{
desc: "Unspecified container name",
pod: &api.Pod{
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()},
TypeMeta: api.TypeMeta{APIVersion: testapi.Default.Version()},
Spec: api.PodSpec{
Containers: []api.Container{{Name: ""}},
},
......@@ -94,7 +94,7 @@ func TestExtractInvalidPods(t *testing.T) {
{
desc: "Invalid container name",
pod: &api.Pod{
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()},
TypeMeta: api.TypeMeta{APIVersion: testapi.Default.Version()},
Spec: api.PodSpec{
Containers: []api.Container{{Name: "_INVALID_"}},
},
......@@ -252,11 +252,11 @@ func TestExtractPodsFromHTTP(t *testing.T) {
for _, testCase := range testCases {
var versionedPods runtime.Object
err := testapi.Converter().Convert(&testCase.pods, &versionedPods)
err := testapi.Default.Converter().Convert(&testCase.pods, &versionedPods)
if err != nil {
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 {
t.Fatalf("%s: error in encoding the pod: %v", testCase.desc, err)
}
......@@ -288,7 +288,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
func TestURLWithHeader(t *testing.T) {
pod := &api.Pod{
TypeMeta: api.TypeMeta{
APIVersion: testapi.Version(),
APIVersion: testapi.Default.Version(),
Kind: "Pod",
},
ObjectMeta: api.ObjectMeta{
......
......@@ -66,14 +66,14 @@ func TestGenerateContainerRef(t *testing.T) {
okPod = api.Pod{
TypeMeta: api.TypeMeta{
Kind: "Pod",
APIVersion: testapi.Version(),
APIVersion: testapi.Default.Version(),
},
ObjectMeta: api.ObjectMeta{
Name: "ok",
Namespace: "test-ns",
UID: "bar",
ResourceVersion: "42",
SelfLink: "/api/" + testapi.Version() + "/pods/foo",
SelfLink: "/api/" + testapi.Default.Version() + "/pods/foo",
},
Spec: api.PodSpec{
Containers: []api.Container{
......@@ -90,7 +90,7 @@ func TestGenerateContainerRef(t *testing.T) {
noSelfLinkPod.Kind = ""
noSelfLinkPod.APIVersion = ""
noSelfLinkPod.ObjectMeta.SelfLink = ""
defaultedSelfLinkPod.ObjectMeta.SelfLink = "/api/" + testapi.Version() + "/pods/ok"
defaultedSelfLinkPod.ObjectMeta.SelfLink = "/api/" + testapi.Default.Version() + "/pods/ok"
cases := []struct {
name string
......@@ -107,7 +107,7 @@ func TestGenerateContainerRef(t *testing.T) {
},
expected: &api.ObjectReference{
Kind: "Pod",
APIVersion: testapi.Version(),
APIVersion: testapi.Default.Version(),
Name: "ok",
Namespace: "test-ns",
UID: "bar",
......@@ -122,7 +122,7 @@ func TestGenerateContainerRef(t *testing.T) {
container: &api.Container{},
expected: &api.ObjectReference{
Kind: "Pod",
APIVersion: testapi.Version(),
APIVersion: testapi.Default.Version(),
Name: "ok",
Namespace: "test-ns",
UID: "bar",
......@@ -146,7 +146,7 @@ func TestGenerateContainerRef(t *testing.T) {
},
expected: &api.ObjectReference{
Kind: "Pod",
APIVersion: testapi.Version(),
APIVersion: testapi.Default.Version(),
Name: "ok",
Namespace: "test-ns",
UID: "bar",
......@@ -163,7 +163,7 @@ func TestGenerateContainerRef(t *testing.T) {
},
expected: &api.ObjectReference{
Kind: "Pod",
APIVersion: testapi.Version(),
APIVersion: testapi.Default.Version(),
Name: "ok",
Namespace: "test-ns",
UID: "bar",
......
......@@ -449,7 +449,7 @@ func TestKillContainerInPodWithPreStop(t *testing.T) {
},
{Name: "bar"}}},
}
podString, err := testapi.Codec().Encode(pod)
podString, err := testapi.Default.Codec().Encode(pod)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
......@@ -2348,7 +2348,7 @@ func TestPodDependsOnPodIP(t *testing.T) {
Name: "POD_IP",
ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{
APIVersion: testapi.Version(),
APIVersion: testapi.Default.Version(),
FieldPath: "status.podIP",
},
},
......@@ -2369,7 +2369,7 @@ func TestPodDependsOnPodIP(t *testing.T) {
Name: "POD_NAME",
ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{
APIVersion: testapi.Version(),
APIVersion: testapi.Default.Version(),
FieldPath: "metadata.name",
},
},
......
......@@ -1247,7 +1247,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
Name: "POD_NAME",
ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{
APIVersion: testapi.Version(),
APIVersion: testapi.Default.Version(),
FieldPath: "metadata.name",
},
},
......@@ -1256,7 +1256,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
Name: "POD_NAMESPACE",
ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{
APIVersion: testapi.Version(),
APIVersion: testapi.Default.Version(),
FieldPath: "metadata.namespace",
},
},
......@@ -1265,7 +1265,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
Name: "POD_IP",
ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{
APIVersion: testapi.Version(),
APIVersion: testapi.Default.Version(),
FieldPath: "status.podIP",
},
},
......@@ -1293,7 +1293,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
Name: "POD_NAME",
ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{
APIVersion: testapi.Version(),
APIVersion: testapi.Default.Version(),
FieldPath: "metadata.name",
},
},
......
......@@ -28,7 +28,7 @@ import (
)
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
return NewREST(etcdStorage), fakeClient
}
......
......@@ -29,7 +29,7 @@ import (
)
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "experimental")
return NewREST(etcdStorage), fakeClient
}
......
......@@ -29,7 +29,7 @@ import (
)
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "experimental")
return NewREST(etcdStorage), fakeClient
}
......
......@@ -28,7 +28,7 @@ import (
)
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
return NewREST(etcdStorage, false), fakeClient
}
......
......@@ -28,7 +28,7 @@ import (
var testTTL uint64 = 60
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
fakeClient.HideExpires = true
return NewREST(etcdStorage, testTTL), fakeClient
}
......
......@@ -48,7 +48,7 @@ func TestGetAttrs(t *testing.T) {
Name: "foo",
Namespace: "baz",
UID: "long uid string",
APIVersion: testapi.Version(),
APIVersion: testapi.Default.Version(),
ResourceVersion: "0",
FieldPath: "",
},
......@@ -68,7 +68,7 @@ func TestGetAttrs(t *testing.T) {
"involvedObject.name": "foo",
"involvedObject.namespace": "baz",
"involvedObject.uid": "long uid string",
"involvedObject.apiVersion": testapi.Version(),
"involvedObject.apiVersion": testapi.Default.Version(),
"involvedObject.resourceVersion": "0",
"involvedObject.fieldPath": "",
"reason": "ForTesting",
......
......@@ -30,7 +30,7 @@ import (
)
func newStorage(t *testing.T) (*ScaleREST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "experimental")
return NewStorage(etcdStorage).Scale, fakeClient
}
......@@ -82,7 +82,7 @@ func TestGet(t *testing.T) {
ctx := api.WithNamespace(api.NewContext(), "test")
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)
}
......@@ -102,7 +102,7 @@ func TestUpdate(t *testing.T) {
ctx := api.WithNamespace(api.NewContext(), "test")
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)
}
replicas := 12
......@@ -122,7 +122,7 @@ func TestUpdate(t *testing.T) {
}
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 {
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 {
func NewTestGenericEtcdRegistry(t *testing.T) (*tools.FakeEtcdClient, *Etcd) {
f := tools.NewFakeEtcdClient(t)
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}
podPrefix := "/pods"
return f, &Etcd{
......@@ -135,14 +135,14 @@ func TestEtcdList(t *testing.T) {
singleElemListResp := &etcd.Response{
Node: &etcd.Node{
Value: runtime.EncodeOrDie(testapi.Codec(), podA),
Value: runtime.EncodeOrDie(testapi.Default.Codec(), podA),
},
}
normalListResp := &etcd.Response{
Node: &etcd.Node{
Nodes: []*etcd.Node{
{Value: runtime.EncodeOrDie(testapi.Codec(), podA)},
{Value: runtime.EncodeOrDie(testapi.Codec(), podB)},
{Value: runtime.EncodeOrDie(testapi.Default.Codec(), podA)},
{Value: runtime.EncodeOrDie(testapi.Default.Codec(), podB)},
},
},
}
......@@ -243,7 +243,7 @@ func TestEtcdCreate(t *testing.T) {
nodeWithPodA := tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Value: runtime.EncodeOrDie(testapi.Codec(), podA),
Value: runtime.EncodeOrDie(testapi.Default.Codec(), podA),
ModifiedIndex: 1,
CreatedIndex: 1,
},
......@@ -323,7 +323,7 @@ func TestEtcdUpdate(t *testing.T) {
nodeWithPodA := tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Value: runtime.EncodeOrDie(testapi.Codec(), podA),
Value: runtime.EncodeOrDie(testapi.Default.Codec(), podA),
ModifiedIndex: 1,
CreatedIndex: 1,
},
......@@ -334,7 +334,7 @@ func TestEtcdUpdate(t *testing.T) {
newerNodeWithPodA := tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Value: runtime.EncodeOrDie(testapi.Codec(), podA),
Value: runtime.EncodeOrDie(testapi.Default.Codec(), podA),
ModifiedIndex: 2,
CreatedIndex: 1,
},
......@@ -345,7 +345,7 @@ func TestEtcdUpdate(t *testing.T) {
nodeWithPodB := tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Value: runtime.EncodeOrDie(testapi.Codec(), podB),
Value: runtime.EncodeOrDie(testapi.Default.Codec(), podB),
ModifiedIndex: 1,
CreatedIndex: 1,
},
......@@ -356,7 +356,7 @@ func TestEtcdUpdate(t *testing.T) {
nodeWithPodAWithResourceVersion := tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Value: runtime.EncodeOrDie(testapi.Codec(), podAWithResourceVersion),
Value: runtime.EncodeOrDie(testapi.Default.Codec(), podAWithResourceVersion),
ModifiedIndex: 3,
CreatedIndex: 1,
},
......@@ -452,7 +452,7 @@ func TestEtcdGet(t *testing.T) {
nodeWithPodA := tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Value: runtime.EncodeOrDie(testapi.Codec(), podA),
Value: runtime.EncodeOrDie(testapi.Default.Codec(), podA),
ModifiedIndex: 1,
CreatedIndex: 1,
},
......@@ -508,7 +508,7 @@ func TestEtcdDelete(t *testing.T) {
nodeWithPodA := tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Value: runtime.EncodeOrDie(testapi.Codec(), podA),
Value: runtime.EncodeOrDie(testapi.Default.Codec(), podA),
ModifiedIndex: 1,
CreatedIndex: 1,
},
......@@ -576,7 +576,7 @@ func TestEtcdWatch(t *testing.T) {
respWithPodA := &etcd.Response{
Node: &etcd.Node{
Key: "/registry/pods/default/foo",
Value: runtime.EncodeOrDie(testapi.Codec(), podA),
Value: runtime.EncodeOrDie(testapi.Default.Codec(), podA),
ModifiedIndex: 1,
CreatedIndex: 1,
},
......
......@@ -32,7 +32,7 @@ import (
)
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "experimental")
return NewREST(etcdStorage), fakeClient
}
......
......@@ -29,7 +29,7 @@ import (
)
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
return NewREST(etcdStorage), fakeClient
}
......
......@@ -37,7 +37,7 @@ func (fakeConnectionInfoGetter) GetConnectionInfo(host string) (string, uint, ht
}
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
storage, _ := NewREST(etcdStorage, false, fakeConnectionInfoGetter{})
return storage, fakeClient
}
......
......@@ -31,7 +31,7 @@ import (
)
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
storage, _, _ := NewREST(etcdStorage)
return storage, fakeClient
}
......@@ -140,7 +140,7 @@ func TestDeleteNamespaceWithIncompleteFinalizers(t *testing.T) {
},
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)
}
if _, err := storage.Delete(ctx, "foo", nil); err == nil {
......@@ -163,7 +163,7 @@ func TestDeleteNamespaceWithCompleteFinalizers(t *testing.T) {
},
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)
}
if _, err := storage.Delete(ctx, "foo", nil); err != nil {
......
......@@ -32,7 +32,7 @@ import (
)
func newStorage(t *testing.T) (*REST, *StatusREST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
storage, statusStorage := NewREST(etcdStorage)
return storage, statusStorage, fakeClient
}
......@@ -148,7 +148,7 @@ func TestUpdateStatus(t *testing.T) {
key, _ := storage.KeyFunc(ctx, "foo")
key = etcdtest.AddPrefix(key)
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{
ObjectMeta: api.ObjectMeta{
......
......@@ -32,7 +32,7 @@ import (
)
func newStorage(t *testing.T) (*REST, *StatusREST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
storage, statusStorage := NewREST(etcdStorage)
return storage, statusStorage, fakeClient
}
......@@ -141,7 +141,7 @@ func TestUpdateStatus(t *testing.T) {
key, _ := storage.KeyFunc(ctx, "foo")
key = etcdtest.AddPrefix(key)
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{
ObjectMeta: api.ObjectMeta{
......
......@@ -37,7 +37,7 @@ import (
)
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)
return storage.Pod, storage.Binding, storage.Status, fakeClient
}
......@@ -256,7 +256,7 @@ func TestResourceLocation(t *testing.T) {
storage, _, _, fakeClient := newStorage(t)
key, _ := storage.KeyFunc(ctx, tc.pod.Name)
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)
}
......@@ -338,7 +338,7 @@ func TestEtcdCreate(t *testing.T) {
t.Fatalf("Unexpected error %v", err)
}
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 {
t.Errorf("unexpected error: %v", err)
}
......@@ -424,7 +424,7 @@ func TestEtcdCreateWithContainersNotFound(t *testing.T) {
t.Fatalf("Unexpected error %v", err)
}
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 {
t.Errorf("unexpected error: %v", err)
}
......@@ -495,7 +495,7 @@ func TestEtcdCreateWithExistingContainers(t *testing.T) {
t.Fatalf("Unexpected error %v", err)
}
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 {
t.Errorf("unexpected error: %v", err)
}
......@@ -578,7 +578,7 @@ func TestEtcdUpdateNotScheduled(t *testing.T) {
key, _ := storage.KeyFunc(ctx, "foo")
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()
_, _, err := storage.Update(ctx, podIn)
......@@ -590,7 +590,7 @@ func TestEtcdUpdateNotScheduled(t *testing.T) {
t.Fatalf("Unexpected error: %v", err)
}
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) {
t.Errorf("objects differ: %v", util.ObjectDiff(podOut, podIn))
}
......@@ -603,7 +603,7 @@ func TestEtcdUpdateScheduled(t *testing.T) {
key, _ := storage.KeyFunc(ctx, "foo")
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{
Name: "foo",
Namespace: api.NamespaceDefault,
......@@ -655,7 +655,7 @@ func TestEtcdUpdateScheduled(t *testing.T) {
t.Fatalf("Unexpected error: %v", err)
}
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) {
t.Errorf("expected: %#v, got: %#v", podOut, podIn)
}
......@@ -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{
ObjectMeta: api.ObjectMeta{
......
......@@ -28,7 +28,7 @@ import (
)
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
return NewREST(etcdStorage), fakeClient
}
......
......@@ -17,6 +17,7 @@ limitations under the License.
package registrytest
import (
"fmt"
"testing"
"github.com/coreos/go-etcd/etcd"
......@@ -34,10 +35,10 @@ import (
"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.TestIndex = true
etcdStorage := etcdstorage.NewEtcdStorage(fakeClient, testapi.Codec(), etcdtest.PathPrefix())
etcdStorage := etcdstorage.NewEtcdStorage(fakeClient, testapi.Groups[group].Codec(), etcdtest.PathPrefix())
return etcdStorage, fakeClient
}
......@@ -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
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,
return nil, err
}
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 result, nil
......@@ -182,7 +209,12 @@ func (t *Tester) setObject(ctx api.Context, obj runtime.Object) error {
return err
}
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
}
......@@ -193,8 +225,9 @@ func (t *Tester) setObjectsForList(objects []runtime.Object) []runtime.Object {
if len(objects) > 0 {
nodes := make([]*etcd.Node, len(objects))
for i, obj := range objects {
encoded := runtime.EncodeOrDie(testapi.Codec(), obj)
decoded, _ := testapi.Codec().Decode([]byte(encoded))
codec, _ := getCodec(obj)
encoded := runtime.EncodeOrDie(codec, obj)
decoded, _ := codec.Decode([]byte(encoded))
nodes[i] = &etcd.Node{Value: encoded}
result[i] = decoded
}
......@@ -224,7 +257,11 @@ func (t *Tester) injectWatchError(err 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 {
return err
}
......
......@@ -33,7 +33,7 @@ import (
)
func newStorage(t *testing.T) (*REST, *StatusREST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
storage, statusStorage := NewREST(etcdStorage)
return storage, statusStorage, fakeClient
}
......@@ -152,7 +152,7 @@ func TestUpdateStatus(t *testing.T) {
key, _ := storage.KeyFunc(ctx, "foo")
key = etcdtest.AddPrefix(key)
resourcequotaStart := validNewResourceQuota()
fakeClient.Set(key, runtime.EncodeOrDie(testapi.Codec(), resourcequotaStart), 0)
fakeClient.Set(key, runtime.EncodeOrDie(testapi.Default.Codec(), resourcequotaStart), 0)
resourcequotaIn := &api.ResourceQuota{
ObjectMeta: api.ObjectMeta{
......
......@@ -28,7 +28,7 @@ import (
)
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
return NewREST(etcdStorage), fakeClient
}
......
......@@ -30,7 +30,7 @@ import (
)
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")
etcd := NewEtcd(mem, "/ranges/serviceips", "serviceipallocation", etcdStorage)
return etcd, fakeClient, mem
......@@ -57,7 +57,7 @@ func TestEmpty(t *testing.T) {
func TestStore(t *testing.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)
}
......
......@@ -29,7 +29,7 @@ import (
)
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
return NewREST(etcdStorage), fakeClient
}
......
......@@ -33,7 +33,7 @@ import (
)
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")
if err != nil {
t.Fatal(err)
......@@ -79,7 +79,7 @@ func TestErrors(t *testing.T) {
func TestStore(t *testing.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)
}
......
......@@ -28,7 +28,7 @@ import (
)
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "")
return NewREST(etcdStorage), fakeClient
}
......
......@@ -31,7 +31,7 @@ import (
)
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t)
etcdStorage, fakeClient := registrytest.NewEtcdStorage(t, "experimental")
return NewREST(etcdStorage), fakeClient
}
......
......@@ -31,7 +31,7 @@ import (
)
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
}
......
......@@ -137,7 +137,7 @@ func TestDecodeList(t *testing.T) {
pl := &api.List{
Items: []runtime.Object{
&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"}},
},
}
......
......@@ -26,7 +26,7 @@ import (
)
func TestDecodeUnstructured(t *testing.T) {
version := testapi.Version()
version := testapi.Default.Version()
rawJson := fmt.Sprintf(`{"kind":"Pod","apiVersion":"%s","metadata":{"name":"test"}}`, version)
pl := &api.List{
Items: []runtime.Object{
......
......@@ -43,7 +43,7 @@ func newTestCacher(client tools.EtcdClient) *storage.Cacher {
config := storage.CacherConfig{
CacheCapacity: 10,
Versioner: etcdstorage.APIObjectVersioner{},
Storage: etcdstorage.NewEtcdStorage(client, testapi.Codec(), etcdtest.PathPrefix()),
Storage: etcdstorage.NewEtcdStorage(client, testapi.Default.Codec(), etcdtest.PathPrefix()),
Type: &api.Pod{},
ResourcePrefix: prefix,
KeyFunc: func(obj runtime.Object) (string, error) { return storage.NamespaceKeyFunc(prefix, obj) },
......@@ -94,7 +94,7 @@ func TestListFromMemory(t *testing.T) {
{
Action: "create",
Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)),
Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1,
ModifiedIndex: 1,
},
......@@ -102,7 +102,7 @@ func TestListFromMemory(t *testing.T) {
{
Action: "create",
Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podBar)),
Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podBar)),
CreatedIndex: 2,
ModifiedIndex: 2,
},
......@@ -110,7 +110,7 @@ func TestListFromMemory(t *testing.T) {
{
Action: "create",
Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podBaz)),
Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podBaz)),
CreatedIndex: 3,
ModifiedIndex: 3,
},
......@@ -118,12 +118,12 @@ func TestListFromMemory(t *testing.T) {
{
Action: "set",
Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFooPrime)),
Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFooPrime)),
CreatedIndex: 1,
ModifiedIndex: 4,
},
PrevNode: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)),
Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1,
ModifiedIndex: 1,
},
......@@ -135,7 +135,7 @@ func TestListFromMemory(t *testing.T) {
ModifiedIndex: 5,
},
PrevNode: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podBar)),
Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podBar)),
CreatedIndex: 1,
ModifiedIndex: 1,
},
......@@ -210,7 +210,7 @@ func TestWatch(t *testing.T) {
etcdResponse: &etcd.Response{
Action: "create",
Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)),
Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1,
ModifiedIndex: 1,
},
......@@ -223,7 +223,7 @@ func TestWatch(t *testing.T) {
etcdResponse: &etcd.Response{
Action: "create",
Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podBar)),
Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podBar)),
CreatedIndex: 2,
ModifiedIndex: 2,
},
......@@ -236,12 +236,12 @@ func TestWatch(t *testing.T) {
etcdResponse: &etcd.Response{
Action: "set",
Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)),
Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1,
ModifiedIndex: 3,
},
PrevNode: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)),
Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1,
ModifiedIndex: 1,
},
......@@ -326,7 +326,7 @@ func TestFiltering(t *testing.T) {
etcdResponse: &etcd.Response{
Action: "create",
Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)),
Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1,
ModifiedIndex: 1,
},
......@@ -339,12 +339,12 @@ func TestFiltering(t *testing.T) {
etcdResponse: &etcd.Response{
Action: "set",
Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFooFiltered)),
Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFooFiltered)),
CreatedIndex: 1,
ModifiedIndex: 2,
},
PrevNode: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)),
Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1,
ModifiedIndex: 1,
},
......@@ -358,12 +358,12 @@ func TestFiltering(t *testing.T) {
etcdResponse: &etcd.Response{
Action: "set",
Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)),
Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1,
ModifiedIndex: 3,
},
PrevNode: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFooFiltered)),
Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFooFiltered)),
CreatedIndex: 1,
ModifiedIndex: 2,
},
......@@ -377,12 +377,12 @@ func TestFiltering(t *testing.T) {
etcdResponse: &etcd.Response{
Action: "set",
Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)),
Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1,
ModifiedIndex: 4,
},
PrevNode: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)),
Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1,
ModifiedIndex: 3,
},
......@@ -399,7 +399,7 @@ func TestFiltering(t *testing.T) {
ModifiedIndex: 5,
},
PrevNode: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)),
Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1,
ModifiedIndex: 4,
},
......@@ -462,7 +462,7 @@ func TestStorageError(t *testing.T) {
fakeClient.WatchResponse <- &etcd.Response{
Action: "create",
Node: &etcd.Node{
Value: string(runtime.EncodeOrDie(testapi.Codec(), podFoo)),
Value: string(runtime.EncodeOrDie(testapi.Default.Codec(), podFoo)),
CreatedIndex: 1,
ModifiedIndex: 1,
},
......
......@@ -57,8 +57,8 @@ var codec runtime.Codec
func init() {
scheme = runtime.NewScheme()
scheme.AddKnownTypes("", &TestResource{})
scheme.AddKnownTypes(testapi.Version(), &TestResource{})
codec = runtime.CodecFor(scheme, testapi.Version())
scheme.AddKnownTypes(testapi.Default.Version(), &TestResource{})
codec = runtime.CodecFor(scheme, testapi.Default.Version())
scheme.AddConversionFuncs(
func(in *TestResource, out *TestResource, s conversion.Scope) error {
*out = *in
......@@ -85,7 +85,7 @@ func TestIsEtcdNotFound(t *testing.T) {
// Returns an encoded version of api.Pod with the given name.
func getEncodedPod(name string) string {
pod, _ := testapi.Codec().Encode(&api.Pod{
pod, _ := testapi.Default.Codec().Encode(&api.Pod{
ObjectMeta: api.ObjectMeta{Name: name},
})
return string(pod)
......@@ -93,7 +93,7 @@ func getEncodedPod(name string) string {
func TestList(t *testing.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")
fakeClient.Data[key] = tools.EtcdResponseWithError{
R: &etcd.Response{
......@@ -167,7 +167,7 @@ func TestList(t *testing.T) {
// TestListAcrossDirectories ensures that the client excludes directories and flattens tree-response - simulates cross-namespace query
func TestListAcrossDirectories(t *testing.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")
fakeClient.Data[key] = tools.EtcdResponseWithError{
R: &etcd.Response{
......@@ -254,7 +254,7 @@ func TestListAcrossDirectories(t *testing.T) {
func TestListExcludesDirectories(t *testing.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")
fakeClient.Data[key] = tools.EtcdResponseWithError{
R: &etcd.Response{
......@@ -329,7 +329,7 @@ func TestListExcludesDirectories(t *testing.T) {
func TestGet(t *testing.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")
grace := int64(30)
expect := api.Pod{
......@@ -340,7 +340,7 @@ func TestGet(t *testing.T) {
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
err := helper.Get("/some/key", &got, false)
if err != nil {
......@@ -353,7 +353,7 @@ func TestGet(t *testing.T) {
func TestGetNotFoundErr(t *testing.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")
fakeClient.Data[key1] = tools.EtcdResponseWithError{
R: &etcd.Response{
......@@ -397,13 +397,13 @@ func TestGetNotFoundErr(t *testing.T) {
func TestCreate(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
fakeClient := tools.NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix())
helper := newEtcdHelper(fakeClient, testapi.Default.Codec(), etcdtest.PathPrefix())
returnedObj := &api.Pod{}
err := helper.Create("/some/key", obj, returnedObj, 5)
if err != nil {
t.Errorf("Unexpected error %#v", err)
}
data, err := testapi.Codec().Encode(obj)
data, err := testapi.Default.Codec().Encode(obj)
if err != nil {
t.Errorf("Unexpected error %#v", err)
}
......@@ -423,7 +423,7 @@ func TestCreate(t *testing.T) {
func TestCreateNilOutParam(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
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)
if err != nil {
t.Errorf("Unexpected error %#v", err)
......@@ -433,13 +433,13 @@ func TestCreateNilOutParam(t *testing.T) {
func TestSet(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
fakeClient := tools.NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix())
helper := newEtcdHelper(fakeClient, testapi.Default.Codec(), etcdtest.PathPrefix())
returnedObj := &api.Pod{}
err := helper.Set("/some/key", obj, returnedObj, 5)
if err != nil {
t.Errorf("Unexpected error %#v", err)
}
data, err := testapi.Codec().Encode(obj)
data, err := testapi.Default.Codec().Encode(obj)
if err != nil {
t.Errorf("Unexpected error %#v", err)
}
......@@ -461,7 +461,7 @@ func TestSetFailCAS(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"}}
fakeClient := tools.NewFakeEtcdClient(t)
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)
if err == nil {
t.Errorf("Expecting error.")
......@@ -472,12 +472,12 @@ func TestSetWithVersion(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"}}
fakeClient := tools.NewFakeEtcdClient(t)
fakeClient.TestIndex = true
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix())
helper := newEtcdHelper(fakeClient, testapi.Default.Codec(), etcdtest.PathPrefix())
key := etcdtest.AddPrefix("/some/key")
fakeClient.Data[key] = tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Value: runtime.EncodeOrDie(testapi.Codec(), obj),
Value: runtime.EncodeOrDie(testapi.Default.Codec(), obj),
ModifiedIndex: 1,
},
},
......@@ -488,7 +488,7 @@ func TestSetWithVersion(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error %#v", err)
}
data, err := testapi.Codec().Encode(obj)
data, err := testapi.Default.Codec().Encode(obj)
if err != nil {
t.Fatalf("Unexpected error %#v", err)
}
......@@ -508,7 +508,7 @@ func TestSetWithVersion(t *testing.T) {
func TestSetWithoutResourceVersioner(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
fakeClient := tools.NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix())
helper := newEtcdHelper(fakeClient, testapi.Default.Codec(), etcdtest.PathPrefix())
helper.versioner = nil
returnedObj := &api.Pod{}
err := helper.Set("/some/key", obj, returnedObj, 3)
......@@ -516,7 +516,7 @@ func TestSetWithoutResourceVersioner(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error %#v", err)
}
data, err := testapi.Codec().Encode(obj)
data, err := testapi.Default.Codec().Encode(obj)
if err != nil {
t.Errorf("Unexpected error %#v", err)
}
......@@ -536,7 +536,7 @@ func TestSetWithoutResourceVersioner(t *testing.T) {
func TestSetNilOutParam(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
fakeClient := tools.NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix())
helper := newEtcdHelper(fakeClient, testapi.Default.Codec(), etcdtest.PathPrefix())
helper.versioner = nil
err := helper.Set("/some/key", obj, nil, 3)
if err != nil {
......@@ -860,7 +860,7 @@ func TestGetEtcdVersion_NotListening(t *testing.T) {
func TestPrefixEtcdKey(t *testing.T) {
fakeClient := tools.NewFakeEtcdClient(t)
prefix := path.Join("/", etcdtest.PathPrefix())
helper := newEtcdHelper(fakeClient, testapi.Codec(), prefix)
helper := newEtcdHelper(fakeClient, testapi.Default.Codec(), prefix)
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