2014-08-05 23:19:32 +00:00
|
|
|
/*
|
|
|
|
Copyright 2014 Google Inc. 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 client
|
|
|
|
|
|
|
|
import (
|
2014-11-19 01:19:43 +00:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
|
2014-08-05 23:19:32 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
2014-11-19 01:19:43 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
2014-08-21 21:14:06 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
|
2014-08-05 23:19:32 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
|
|
|
)
|
|
|
|
|
2014-08-15 21:15:03 +00:00
|
|
|
type FakeAction struct {
|
|
|
|
Action string
|
|
|
|
Value interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fake implements Interface. Meant to be embedded into a struct to get a default
|
2014-08-05 23:19:32 +00:00
|
|
|
// implementation. This makes faking out just the method you want to test easier.
|
2014-08-15 21:15:03 +00:00
|
|
|
type Fake struct {
|
2014-08-29 02:31:41 +00:00
|
|
|
Actions []FakeAction
|
2014-10-23 19:13:29 +00:00
|
|
|
PodsList api.PodList
|
2014-08-29 02:31:41 +00:00
|
|
|
Ctrl api.ReplicationController
|
|
|
|
ServiceList api.ServiceList
|
|
|
|
EndpointsList api.EndpointsList
|
2014-10-23 19:13:29 +00:00
|
|
|
MinionsList api.MinionList
|
|
|
|
EventsList api.EventList
|
2014-08-29 02:31:41 +00:00
|
|
|
Err error
|
|
|
|
Watch watch.Interface
|
2014-08-05 23:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-10-23 19:13:29 +00:00
|
|
|
func (c *Fake) ReplicationControllers(namespace string) ReplicationControllerInterface {
|
|
|
|
return &FakeReplicationControllers{Fake: c, Namespace: namespace}
|
2014-08-05 23:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-10-23 19:13:29 +00:00
|
|
|
func (c *Fake) Minions() MinionInterface {
|
|
|
|
return &FakeMinions{Fake: c}
|
2014-08-05 23:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-11-14 03:09:03 +00:00
|
|
|
func (c *Fake) Events(namespace string) EventInterface {
|
2014-10-23 19:13:29 +00:00
|
|
|
return &FakeEvents{Fake: c}
|
2014-08-05 23:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-10-23 19:13:29 +00:00
|
|
|
func (c *Fake) Endpoints(namespace string) EndpointsInterface {
|
|
|
|
return &FakeEndpoints{Fake: c, Namespace: namespace}
|
2014-08-05 23:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-10-23 19:13:29 +00:00
|
|
|
func (c *Fake) Pods(namespace string) PodInterface {
|
|
|
|
return &FakePods{Fake: c, Namespace: namespace}
|
2014-08-05 23:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-10-23 19:13:29 +00:00
|
|
|
func (c *Fake) Services(namespace string) ServiceInterface {
|
|
|
|
return &FakeServices{Fake: c, Namespace: namespace}
|
2014-08-15 21:14:22 +00:00
|
|
|
}
|
|
|
|
|
2014-08-21 21:14:06 +00:00
|
|
|
func (c *Fake) ServerVersion() (*version.Info, error) {
|
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "get-version", Value: nil})
|
|
|
|
versionInfo := version.Get()
|
|
|
|
return &versionInfo, nil
|
|
|
|
}
|
2014-10-29 00:20:40 +00:00
|
|
|
|
2014-11-11 07:11:45 +00:00
|
|
|
func (c *Fake) ServerAPIVersions() (*api.APIVersions, error) {
|
2014-10-29 00:20:40 +00:00
|
|
|
c.Actions = append(c.Actions, FakeAction{Action: "get-apiversions", Value: nil})
|
2014-11-11 07:11:45 +00:00
|
|
|
return &api.APIVersions{Versions: []string{"v1beta1", "v1beta2"}}, nil
|
2014-10-29 00:20:40 +00:00
|
|
|
}
|
2014-11-19 01:19:43 +00:00
|
|
|
|
|
|
|
type HttpClientFunc func(*http.Request) (*http.Response, error)
|
|
|
|
|
|
|
|
func (f HttpClientFunc) Do(req *http.Request) (*http.Response, error) {
|
|
|
|
return f(req)
|
|
|
|
}
|
|
|
|
|
|
|
|
// FakeRESTClient provides a fake RESTClient interface.
|
|
|
|
type FakeRESTClient struct {
|
|
|
|
Client HTTPClient
|
|
|
|
Codec runtime.Codec
|
|
|
|
Req *http.Request
|
|
|
|
Resp *http.Response
|
|
|
|
Err error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *FakeRESTClient) Get() *Request {
|
|
|
|
return NewRequest(c, "GET", &url.URL{Host: "localhost"}, c.Codec)
|
|
|
|
}
|
|
|
|
func (c *FakeRESTClient) Put() *Request {
|
|
|
|
return NewRequest(c, "PUT", &url.URL{Host: "localhost"}, c.Codec)
|
|
|
|
}
|
|
|
|
func (c *FakeRESTClient) Post() *Request {
|
|
|
|
return NewRequest(c, "POST", &url.URL{Host: "localhost"}, c.Codec)
|
|
|
|
}
|
|
|
|
func (c *FakeRESTClient) Delete() *Request {
|
|
|
|
return NewRequest(c, "DELETE", &url.URL{Host: "localhost"}, c.Codec)
|
|
|
|
}
|
|
|
|
func (c *FakeRESTClient) Do(req *http.Request) (*http.Response, error) {
|
|
|
|
c.Req = req
|
|
|
|
if c.Client != HTTPClient(nil) {
|
|
|
|
return c.Client.Do(req)
|
|
|
|
}
|
|
|
|
return c.Resp, c.Err
|
|
|
|
}
|