mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Shorten 'CodecForVersionOrDie' name, add 'ResourceVersioner' to testapi
This commit is contained in:
parent
13acb63fb3
commit
d34914517f
@ -24,7 +24,7 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version returns the API version to test against as set by the KUBE_API_VERSION env var.
|
// Version returns the API version to test against, as set by the KUBE_API_VERSION env var.
|
||||||
func Version() string {
|
func Version() string {
|
||||||
version := os.Getenv("KUBE_API_VERSION")
|
version := os.Getenv("KUBE_API_VERSION")
|
||||||
if version == "" {
|
if version == "" {
|
||||||
@ -33,10 +33,22 @@ func Version() string {
|
|||||||
return version
|
return version
|
||||||
}
|
}
|
||||||
|
|
||||||
func CodecForVersionOrDie() runtime.Codec {
|
// 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())
|
interfaces, err := latest.InterfacesFor(Version())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return interfaces.Codec
|
return interfaces.Codec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ResourceVersioner returns the ResourceVersioner for the API version to test against,
|
||||||
|
// as set by the KUBE_API_VERSION env var.
|
||||||
|
func ResourceVersioner() runtime.ResourceVersioner {
|
||||||
|
interfaces, err := latest.InterfacesFor(Version())
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return interfaces.ResourceVersioner
|
||||||
|
}
|
||||||
|
@ -109,7 +109,7 @@ func TestDoRequest(t *testing.T) {
|
|||||||
{Request: testRequest{Method: "GET", Path: "error"}, Response: Response{StatusCode: 500}, Error: true},
|
{Request: testRequest{Method: "GET", Path: "error"}, Response: Response{StatusCode: 500}, Error: true},
|
||||||
{Request: testRequest{Method: "POST", Path: "faildecode"}, Response: Response{StatusCode: 200, RawBody: &invalid}},
|
{Request: testRequest{Method: "POST", Path: "faildecode"}, Response: Response{StatusCode: 200, RawBody: &invalid}},
|
||||||
{Request: testRequest{Method: "GET", Path: "failread"}, Response: Response{StatusCode: 200, RawBody: &invalid}},
|
{Request: testRequest{Method: "GET", Path: "failread"}, Response: Response{StatusCode: 200, RawBody: &invalid}},
|
||||||
{Client: &Client{&RESTClient{baseURL: uri, Codec: testapi.CodecForVersionOrDie()}}, Request: testRequest{Method: "GET", Path: "nocertificate"}, Error: true},
|
{Client: &Client{&RESTClient{baseURL: uri, Codec: testapi.Codec()}}, Request: testRequest{Method: "GET", Path: "nocertificate"}, Error: true},
|
||||||
}
|
}
|
||||||
for _, c := range testClients {
|
for _, c := range testClients {
|
||||||
client := c.Setup()
|
client := c.Setup()
|
||||||
|
@ -149,7 +149,7 @@ func TestSyncReplicationControllerDeletes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSyncReplicationControllerCreates(t *testing.T) {
|
func TestSyncReplicationControllerCreates(t *testing.T) {
|
||||||
body := runtime.EncodeOrDie(testapi.CodecForVersionOrDie(), newPodList(0))
|
body := runtime.EncodeOrDie(testapi.Codec(), newPodList(0))
|
||||||
fakeHandler := util.FakeHandler{
|
fakeHandler := util.FakeHandler{
|
||||||
StatusCode: 200,
|
StatusCode: 200,
|
||||||
ResponseBody: string(body),
|
ResponseBody: string(body),
|
||||||
@ -170,7 +170,7 @@ func TestSyncReplicationControllerCreates(t *testing.T) {
|
|||||||
|
|
||||||
func TestCreateReplica(t *testing.T) {
|
func TestCreateReplica(t *testing.T) {
|
||||||
ctx := api.NewDefaultContext()
|
ctx := api.NewDefaultContext()
|
||||||
body := runtime.EncodeOrDie(testapi.CodecForVersionOrDie(), &api.Pod{})
|
body := runtime.EncodeOrDie(testapi.Codec(), &api.Pod{})
|
||||||
fakeHandler := util.FakeHandler{
|
fakeHandler := util.FakeHandler{
|
||||||
StatusCode: 200,
|
StatusCode: 200,
|
||||||
ResponseBody: string(body),
|
ResponseBody: string(body),
|
||||||
|
@ -203,7 +203,7 @@ func TestSyncEndpointsItemsPreexisting(t *testing.T) {
|
|||||||
if err := endpoints.SyncServiceEndpoints(); err != nil {
|
if err := endpoints.SyncServiceEndpoints(); err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
data := runtime.EncodeOrDie(testapi.CodecForVersionOrDie(), &api.Endpoints{
|
data := runtime.EncodeOrDie(testapi.Codec(), &api.Endpoints{
|
||||||
TypeMeta: api.TypeMeta{
|
TypeMeta: api.TypeMeta{
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
@ -261,7 +261,7 @@ func TestSyncEndpointsItems(t *testing.T) {
|
|||||||
if err := endpoints.SyncServiceEndpoints(); err != nil {
|
if err := endpoints.SyncServiceEndpoints(); err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
data := runtime.EncodeOrDie(testapi.CodecForVersionOrDie(), &api.Endpoints{
|
data := runtime.EncodeOrDie(testapi.Codec(), &api.Endpoints{
|
||||||
TypeMeta: api.TypeMeta{
|
TypeMeta: api.TypeMeta{
|
||||||
ResourceVersion: "",
|
ResourceVersion: "",
|
||||||
},
|
},
|
||||||
|
@ -317,7 +317,7 @@ func TestBind(t *testing.T) {
|
|||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
expectedBody := runtime.EncodeOrDie(testapi.CodecForVersionOrDie(), item.binding)
|
expectedBody := runtime.EncodeOrDie(testapi.Codec(), item.binding)
|
||||||
handler.ValidateRequest(t, "/api/"+testapi.Version()+"/bindings", "POST", &expectedBody)
|
handler.ValidateRequest(t, "/api/"+testapi.Version()+"/bindings", "POST", &expectedBody)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user