本文整理汇总了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi.Version函数的典型用法代码示例。如果您正苦于以下问题:Golang Version函数的具体用法?Golang Version怎么用?Golang Version使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Version函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: BenchmarkCheckRetryClosesBody
func BenchmarkCheckRetryClosesBody(t *testing.B) {
count := 0
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
count++
if count%3 == 0 {
w.WriteHeader(http.StatusOK)
return
}
w.Header().Set("Retry-After", "0")
w.WriteHeader(apierrors.StatusTooManyRequests)
}))
defer testServer.Close()
c := NewOrDie(&Config{Host: testServer.URL, Version: testapi.Version(), Username: "user", Password: "pass"})
r := c.Verb("POST").
Prefix("foo", "bar").
Suffix("baz").
Timeout(time.Second).
Body([]byte(strings.Repeat("abcd", 1000)))
for i := 0; i < t.N; i++ {
if _, err := r.DoRaw(); err != nil {
t.Fatalf("Unexpected error: %v %#v", err, err)
}
}
}
开发者ID:eghobo,项目名称:kubedash,代码行数:26,代码来源:request_test.go
示例2: TestSyncReplicationControllerCreates
func TestSyncReplicationControllerCreates(t *testing.T) {
body := runtime.EncodeOrDie(testapi.Codec(), newPodList(0))
fakePodHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(body),
}
fakePodControl := FakePodControl{}
controller := newReplicationController(2)
fakeUpdateHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: runtime.EncodeOrDie(testapi.Codec(), &controller),
T: t,
}
testServerMux := http.NewServeMux()
testServerMux.Handle("/api/"+testapi.Version()+"/pods/", &fakePodHandler)
testServerMux.Handle(fmt.Sprintf("/api/"+testapi.Version()+"/replicationControllers/%s", controller.Name), &fakeUpdateHandler)
testServer := httptest.NewServer(testServerMux)
defer testServer.Close()
client := client.NewOrDie(&client.Config{Host: testServer.URL, Version: testapi.Version()})
manager := NewReplicationManager(client)
manager.podControl = &fakePodControl
manager.syncReplicationController(controller)
validateSyncReplication(t, &fakePodControl, 2, 0)
// No Status.Replicas update expected even though 2 pods were just created,
// because the controller manager can't observe the pods till the next sync cycle.
if fakeUpdateHandler.RequestReceived != nil {
t.Errorf("Unexpected updates for controller via %v",
fakeUpdateHandler.RequestReceived.URL)
}
}
开发者ID:vrosnet,项目名称:kubernetes,代码行数:34,代码来源:replication_controller_test.go
示例3: TestSecrets
// TestSecrets tests apiserver-side behavior of creation of secret objects and their use by pods.
func TestSecrets(t *testing.T) {
helper, err := framework.NewHelper()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
var m *master.Master
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
m.Handler.ServeHTTP(w, req)
}))
defer s.Close()
m = master.New(&master.Config{
EtcdHelper: helper,
KubeletClient: client.FakeKubeletClient{},
EnableCoreControllers: true,
EnableLogsSupport: false,
EnableUISupport: false,
EnableIndex: true,
APIPrefix: "/api",
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
AdmissionControl: admit.NewAlwaysAdmit(),
})
framework.DeleteAllEtcdKeys()
client := client.NewOrDie(&client.Config{Host: s.URL, Version: testapi.Version()})
DoTestSecrets(t, client, testapi.Version())
}
开发者ID:chenzhen411,项目名称:kubernetes,代码行数:29,代码来源:secret_test.go
示例4: TestDoRequestAccepted
func TestDoRequestAccepted(t *testing.T) {
status := &api.Status{Status: api.StatusWorking}
expectedBody, _ := latest.Codec.Encode(status)
fakeHandler := util.FakeHandler{
StatusCode: 202,
ResponseBody: string(expectedBody),
T: t,
}
testServer := httptest.NewServer(&fakeHandler)
defer testServer.Close()
c, err := RESTClientFor(&Config{Host: testServer.URL, Username: "test", Version: testapi.Version()})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
body, err := c.Get().Path("test").Do().Raw()
if err == nil {
t.Fatalf("Unexpected non-error")
}
if fakeHandler.RequestReceived.Header["Authorization"] == nil {
t.Errorf("Request is missing authorization header: %#v", fakeHandler.RequestReceived)
}
se, ok := err.(APIStatus)
if !ok {
t.Fatalf("Unexpected kind of error: %#v", err)
}
if !reflect.DeepEqual(se.Status(), *status) {
t.Errorf("Unexpected status: %#v %#v", se.Status(), status)
}
if body != nil {
t.Errorf("Expected nil body, but saw: '%s'", string(body))
}
fakeHandler.ValidateRequest(t, "/"+testapi.Version()+"/test", "GET", nil)
}
开发者ID:ericcapricorn,项目名称:kubernetes,代码行数:33,代码来源:restclient_test.go
示例5: TestSyncEndpointsItems
func TestSyncEndpointsItems(t *testing.T) {
serviceList := api.ServiceList{
Items: []api.Service{
{
ObjectMeta: api.ObjectMeta{Name: "foo"},
Spec: api.ServiceSpec{
Selector: map[string]string{
"foo": "bar",
},
},
},
},
}
testServer, endpointsHandler := makeTestServer(t,
serverResponse{http.StatusOK, newPodList(1)},
serverResponse{http.StatusOK, serviceList},
serverResponse{http.StatusOK, api.Endpoints{}})
defer testServer.Close()
client := client.NewOrDie(&client.Config{Host: testServer.URL, Version: testapi.Version()})
endpoints := NewEndpointController(client)
if err := endpoints.SyncServiceEndpoints(); err != nil {
t.Errorf("unexpected error: %v", err)
}
data := runtime.EncodeOrDie(testapi.Codec(), &api.Endpoints{
ObjectMeta: api.ObjectMeta{
ResourceVersion: "",
},
Endpoints: []string{"1.2.3.4:8080"},
})
endpointsHandler.ValidateRequest(t, "/api/"+testapi.Version()+"/endpoints", "POST", &data)
}
开发者ID:ericcapricorn,项目名称:kubernetes,代码行数:31,代码来源:endpoints_controller_test.go
示例6: TestSetsCodec
func TestSetsCodec(t *testing.T) {
testCases := map[string]struct {
Err bool
Prefix string
Codec runtime.Codec
}{
testapi.Version(): {false, "/api/" + testapi.Version() + "/", testapi.Codec()},
"invalidVersion": {true, "", nil},
}
for version, expected := range testCases {
client, err := New(&Config{Host: "127.0.0.1", Version: version})
switch {
case err == nil && expected.Err:
t.Errorf("expected error but was nil")
continue
case err != nil && !expected.Err:
t.Errorf("unexpected error %v", err)
continue
case err != nil:
continue
}
if e, a := expected.Prefix, client.RESTClient.baseURL.Path; e != a {
t.Errorf("expected %#v, got %#v", e, a)
}
if e, a := expected.Codec, client.RESTClient.Codec; e != a {
t.Errorf("expected %#v, got %#v", e, a)
}
}
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:29,代码来源:restclient_test.go
示例7: newPodList
func newPodList(count int) *api.PodList {
pods := []api.Pod{}
for i := 0; i < count; i++ {
pods = append(pods, api.Pod{
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()},
ObjectMeta: api.ObjectMeta{Name: fmt.Sprintf("pod%d", i)},
Spec: api.PodSpec{
Containers: []api.Container{
{
Ports: []api.ContainerPort{
{
ContainerPort: 8080,
},
},
},
},
},
Status: api.PodStatus{
PodIP: "1.2.3.4",
Conditions: []api.PodCondition{
{
Type: api.PodReady,
Status: api.ConditionFull,
},
},
},
})
}
return &api.PodList{
TypeMeta: api.TypeMeta{APIVersion: testapi.Version(), Kind: "PodList"},
Items: pods,
}
}
开发者ID:vrosnet,项目名称:kubernetes,代码行数:33,代码来源:endpoints_controller_test.go
示例8: newPodList
func newPodList(count int) api.PodList {
pods := []api.Pod{}
for i := 0; i < count; i++ {
pods = append(pods, api.Pod{
TypeMeta: api.TypeMeta{APIVersion: testapi.Version()},
ObjectMeta: api.ObjectMeta{Name: fmt.Sprintf("pod%d", i)},
DesiredState: api.PodState{
Manifest: api.ContainerManifest{
Containers: []api.Container{
{
Ports: []api.Port{
{
ContainerPort: 8080,
},
},
},
},
},
},
CurrentState: api.PodState{
PodIP: "1.2.3.4",
},
})
}
return api.PodList{
TypeMeta: api.TypeMeta{APIVersion: testapi.Version(), Kind: "PodList"},
Items: pods,
}
}
开发者ID:ericcapricorn,项目名称:kubernetes,代码行数:29,代码来源:endpoints_controller_test.go
示例9: TestReadManifestFromFileWithDefaults
func TestReadManifestFromFileWithDefaults(t *testing.T) {
if !api.PreV1Beta3(testapi.Version()) {
return
}
file := writeTestFile(t, os.TempDir(), "test_pod_config",
fmt.Sprintf(`{
"version": "%s",
"id": "test",
"containers": [{ "name": "image", "image": "test/image" }]
}`, testapi.Version()))
defer os.Remove(file.Name())
ch := make(chan interface{})
NewSourceFile(file.Name(), "localhost", time.Millisecond, ch)
select {
case got := <-ch:
update := got.(kubelet.PodUpdate)
if update.Pods[0].UID == "" {
t.Errorf("Unexpected UID: %s", update.Pods[0].UID)
}
case <-time.After(time.Second):
t.Errorf("Expected update, timeout instead")
}
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:25,代码来源:file_test.go
示例10: newExternalScheme
func newExternalScheme() (*runtime.Scheme, meta.RESTMapper, runtime.Codec) {
scheme := runtime.NewScheme()
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{})
codec := runtime.CodecFor(scheme, "unlikelyversion")
validVersion := testapi.Version()
mapper := meta.NewDefaultRESTMapper([]string{"unlikelyversion", validVersion}, func(version string) (*meta.VersionInterfaces, bool) {
return &meta.VersionInterfaces{
Codec: runtime.CodecFor(scheme, version),
ObjectConvertor: scheme,
MetadataAccessor: meta.NewAccessor(),
}, (version == validVersion || version == "unlikelyversion")
})
for _, version := range []string{"unlikelyversion", validVersion} {
for kind := range scheme.KnownTypes(version) {
mixedCase := false
scope := meta.RESTScopeNamespace
mapper.Add(scope, kind, version, mixedCase)
}
}
return scheme, mapper, codec
}
开发者ID:EricCheung3,项目名称:kubernetes,代码行数:26,代码来源:cmd_test.go
示例11: runAMaster
func runAMaster(t *testing.T) (*master.Master, *httptest.Server) {
helper, err := master.NewEtcdHelper(newEtcdClient(), testapi.Version(), etcdtest.PathPrefix())
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
m := master.New(&master.Config{
EtcdHelper: helper,
KubeletClient: client.FakeKubeletClient{},
EnableCoreControllers: true,
EnableLogsSupport: false,
EnableProfiling: true,
EnableUISupport: false,
APIPrefix: "/api",
// Enable v1beta3 if we are testing that version.
EnableV1Beta3: testapi.Version() == "v1beta3",
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
AdmissionControl: admit.NewAlwaysAdmit(),
})
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
m.Handler.ServeHTTP(w, req)
}))
return m, s
}
开发者ID:EricCheung3,项目名称:kubernetes,代码行数:26,代码来源:utils.go
示例12: TestEventSearch
func TestEventSearch(t *testing.T) {
c := &testClient{
Request: testRequest{
Method: "GET",
Path: testapi.ResourcePath("events", "baz", ""),
Query: url.Values{
api.FieldSelectorQueryParam(testapi.Version()): []string{
getInvolvedObjectNameFieldLabel(testapi.Version()) + "=foo,",
"involvedObject.namespace=baz,",
"involvedObject.kind=Pod",
},
api.LabelSelectorQueryParam(testapi.Version()): []string{},
},
},
Response: Response{StatusCode: 200, Body: &api.EventList{}},
}
eventList, err := c.Setup().Events("baz").Search(
&api.Pod{
ObjectMeta: api.ObjectMeta{
Name: "foo",
Namespace: "baz",
SelfLink: testapi.SelfLink("pods", ""),
},
},
)
c.Validate(t, eventList, err)
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:27,代码来源:events_test.go
示例13: TestBind
func TestBind(t *testing.T) {
table := []struct {
binding *api.Binding
}{
{binding: &api.Binding{PodID: "foo", Host: "foohost.kubernetes.mydomain.com"}},
}
for _, item := range table {
handler := util.FakeHandler{
StatusCode: 200,
ResponseBody: "",
T: t,
}
server := httptest.NewServer(&handler)
defer server.Close()
client := client.NewOrDie(&client.Config{Host: server.URL, Version: testapi.Version()})
b := binder{client}
if err := b.Bind(item.binding); err != nil {
t.Errorf("Unexpected error: %v", err)
continue
}
expectedBody := runtime.EncodeOrDie(testapi.Codec(), item.binding)
handler.ValidateRequest(t, "/api/"+testapi.Version()+"/bindings", "POST", &expectedBody)
}
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:26,代码来源:factory_test.go
示例14: buildResourcePath
// buildResourcePath is a convenience function for knowing if a namespace should be in a path param or not
func buildResourcePath(namespace, resource string) string {
if len(namespace) > 0 {
if !(testapi.Version() == "v1beta1" || testapi.Version() == "v1beta2") {
return path.Join("ns", namespace, resource)
}
}
return resource
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:9,代码来源:client_test.go
示例15: buildResourcePath
// buildResourcePath is a convenience function for knowing if a namespace should be in a path param or not
func buildResourcePath(prefix, namespace, resource string) string {
base := path.Join("/api", testapi.Version(), prefix)
if len(namespace) > 0 {
if !(testapi.Version() == "v1beta1" || testapi.Version() == "v1beta2") {
base = path.Join(base, "namespaces", namespace)
}
}
return path.Join(base, resource)
}
开发者ID:DreadPirateShawn,项目名称:heapster,代码行数:10,代码来源:listwatch_test.go
示例16: ValidateCommon
func (c *testClient) ValidateCommon(t *testing.T, err error) {
defer c.server.Close()
if c.Error {
if err == nil {
t.Errorf("error expected for %#v, got none", c.Request)
}
return
}
if err != nil {
t.Errorf("no error expected for %#v, got: %v", c.Request, err)
}
if c.handler.RequestReceived == nil {
t.Errorf("handler had an empty request, %#v", c)
return
}
requestBody := body(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)
// We check the query manually, so blank it out so that FakeHandler.ValidateRequest
// won't check it.
c.handler.RequestReceived.URL.RawQuery = ""
c.handler.ValidateRequest(t, path.Join(c.Request.Path), c.Request.Method, requestBody)
for key, values := range c.Request.Query {
validator, ok := c.QueryValidator[key]
if !ok {
switch key {
case api.LabelSelectorQueryParam(testapi.Version()):
validator = validateLabels
case api.FieldSelectorQueryParam(testapi.Version()):
validator = validateFields
default:
validator = func(a, b string) bool { return a == b }
}
}
observed := actualQuery.Get(key)
wanted := strings.Join(values, "")
if !validator(wanted, observed) {
t.Errorf("Unexpected query arg for key: %s. Expected %s, Received %s", key, wanted, observed)
}
}
if c.Request.Header != "" {
if c.handler.RequestReceived.Header.Get(c.Request.Header) == "" {
t.Errorf("header %q not found in request %#v", c.Request.Header, c.handler.RequestReceived)
}
}
if expected, received := requestBody, c.handler.RequestBody; expected != nil && *expected != received {
t.Errorf("bad body for request %#v: expected %s, got %s", c.Request, *expected, received)
}
}
开发者ID:Ima8,项目名称:kubernetes,代码行数:54,代码来源:client_test.go
示例17: TestRESTClientRequires
func TestRESTClientRequires(t *testing.T) {
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", Version: "", Codec: testapi.Codec()}); err == nil {
t.Errorf("unexpected non-error")
}
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", Version: testapi.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 {
t.Errorf("unexpected error: %v", err)
}
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:11,代码来源:restclient_test.go
示例18: makeNamespaceURL
func makeNamespaceURL(namespace, suffix string, isClient bool) string {
if !(testapi.Version() == "v1beta1" || testapi.Version() == "v1beta2") {
return makeURL("/ns/" + namespace + suffix)
}
// if this is a url the client should call, encode the url
if isClient {
return makeURL(suffix + "?namespace=" + namespace)
}
// its not a client url, so its what the server needs to listen on
return makeURL(suffix)
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:11,代码来源:factory_test.go
示例19: init
func init() {
scheme = runtime.NewScheme()
scheme.AddKnownTypes("", &TestResource{})
scheme.AddKnownTypes(testapi.Version(), &TestResource{})
codec = runtime.CodecFor(scheme, testapi.Version())
scheme.AddConversionFuncs(
func(in *TestResource, out *TestResource, s conversion.Scope) error {
*out = *in
return nil
},
)
}
开发者ID:mbforbes,项目名称:kubernetes,代码行数:12,代码来源:etcd_helper_test.go
示例20: TestRESTList
func TestRESTList(t *testing.T) {
reg, rest := NewTestREST()
eventA := &api.Event{
InvolvedObject: api.ObjectReference{
Kind: "Pod",
Name: "foo",
UID: "long uid string",
APIVersion: testapi.Version(),
ResourceVersion: "0",
FieldPath: "",
},
Reason: "ForTesting",
Source: api.EventSource{Component: "GoodSource"},
}
eventB := &api.Event{
InvolvedObject: api.ObjectReference{
Kind: "Pod",
Name: "bar",
UID: "other long uid string",
APIVersion: testapi.Version(),
ResourceVersion: "0",
FieldPath: "",
},
Reason: "ForTesting",
Source: api.EventSource{Component: "GoodSource"},
}
eventC := &api.Event{
InvolvedObject: api.ObjectReference{
Kind: "Pod",
Name: "baz",
UID: "yet another long uid string",
APIVersion: testapi.Version(),
ResourceVersion: "0",
FieldPath: "",
},
Reason: "ForTesting",
Source: api.EventSource{Component: "OtherSource"},
}
reg.ObjectList = &api.EventList{
Items: []api.Event{*eventA, *eventB, *eventC},
}
got, err := rest.List(api.NewContext(), labels.Everything(), fields.Set{"source": "GoodSource"}.AsSelector())
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
expect := &api.EventList{
Items: []api.Event{*eventA, *eventB},
}
if e, a := expect, got; !reflect.DeepEqual(e, a) {
t.Errorf("diff: %s", util.ObjectDiff(e, a))
}
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:52,代码来源:rest_test.go
注:本文中的github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi.Version函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论