mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 06:54:01 +00:00
Move FakeCloud into its own pkg
This commit is contained in:
parent
953cd923f1
commit
95e0be9a63
@ -14,11 +14,13 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package cloudprovider
|
package fake_cloud
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FakeCloud is a test-double implementation of Interface, TCPLoadBalancer and Instances. It is useful for testing.
|
// FakeCloud is a test-double implementation of Interface, TCPLoadBalancer and Instances. It is useful for testing.
|
||||||
@ -28,7 +30,7 @@ type FakeCloud struct {
|
|||||||
Calls []string
|
Calls []string
|
||||||
IP net.IP
|
IP net.IP
|
||||||
Machines []string
|
Machines []string
|
||||||
Zone
|
cloudprovider.Zone
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FakeCloud) addCall(desc string) {
|
func (f *FakeCloud) addCall(desc string) {
|
||||||
@ -43,18 +45,18 @@ func (f *FakeCloud) ClearCalls() {
|
|||||||
// TCPLoadBalancer returns a fake implementation of TCPLoadBalancer.
|
// TCPLoadBalancer returns a fake implementation of TCPLoadBalancer.
|
||||||
//
|
//
|
||||||
// Actually it just returns f itself.
|
// Actually it just returns f itself.
|
||||||
func (f *FakeCloud) TCPLoadBalancer() (TCPLoadBalancer, bool) {
|
func (f *FakeCloud) TCPLoadBalancer() (cloudprovider.TCPLoadBalancer, bool) {
|
||||||
return f, true
|
return f, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instances returns a fake implementation of Instances.
|
// Instances returns a fake implementation of Instances.
|
||||||
//
|
//
|
||||||
// Actually it just returns f itself.
|
// Actually it just returns f itself.
|
||||||
func (f *FakeCloud) Instances() (Instances, bool) {
|
func (f *FakeCloud) Instances() (cloudprovider.Instances, bool) {
|
||||||
return f, true
|
return f, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FakeCloud) Zones() (Zones, bool) {
|
func (f *FakeCloud) Zones() (cloudprovider.Zones, bool) {
|
||||||
return f, true
|
return f, true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +106,7 @@ func (f *FakeCloud) List(filter string) ([]string, error) {
|
|||||||
return result, f.Err
|
return result, f.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FakeCloud) GetZone() (Zone, error) {
|
func (f *FakeCloud) GetZone() (cloudprovider.Zone, error) {
|
||||||
f.addCall("get-zone")
|
f.addCall("get-zone")
|
||||||
return f.Zone, f.Err
|
return f.Zone, f.Err
|
||||||
}
|
}
|
@ -20,12 +20,12 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/fake"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCloudList(t *testing.T) {
|
func TestCloudList(t *testing.T) {
|
||||||
instances := []string{"m1", "m2"}
|
instances := []string{"m1", "m2"}
|
||||||
fakeCloud := cloudprovider.FakeCloud{
|
fakeCloud := fake_cloud.FakeCloud{
|
||||||
Machines: instances,
|
Machines: instances,
|
||||||
}
|
}
|
||||||
registry, err := NewCloudRegistry(&fakeCloud, ".*")
|
registry, err := NewCloudRegistry(&fakeCloud, ".*")
|
||||||
@ -45,7 +45,7 @@ func TestCloudList(t *testing.T) {
|
|||||||
|
|
||||||
func TestCloudContains(t *testing.T) {
|
func TestCloudContains(t *testing.T) {
|
||||||
instances := []string{"m1", "m2"}
|
instances := []string{"m1", "m2"}
|
||||||
fakeCloud := cloudprovider.FakeCloud{
|
fakeCloud := fake_cloud.FakeCloud{
|
||||||
Machines: instances,
|
Machines: instances,
|
||||||
}
|
}
|
||||||
registry, err := NewCloudRegistry(&fakeCloud, ".*")
|
registry, err := NewCloudRegistry(&fakeCloud, ".*")
|
||||||
@ -74,7 +74,7 @@ func TestCloudContains(t *testing.T) {
|
|||||||
|
|
||||||
func TestCloudListRegexp(t *testing.T) {
|
func TestCloudListRegexp(t *testing.T) {
|
||||||
instances := []string{"m1", "m2", "n1", "n2"}
|
instances := []string{"m1", "m2", "n1", "n2"}
|
||||||
fakeCloud := cloudprovider.FakeCloud{
|
fakeCloud := fake_cloud.FakeCloud{
|
||||||
Machines: instances,
|
Machines: instances,
|
||||||
}
|
}
|
||||||
registry, err := NewCloudRegistry(&fakeCloud, "m[0-9]+")
|
registry, err := NewCloudRegistry(&fakeCloud, "m[0-9]+")
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/fake"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/minion"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/minion"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
|
||||||
@ -228,7 +228,7 @@ func TestGetPod(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetPodCloud(t *testing.T) {
|
func TestGetPodCloud(t *testing.T) {
|
||||||
fakeCloud := &cloudprovider.FakeCloud{}
|
fakeCloud := &fake_cloud.FakeCloud{}
|
||||||
podRegistry := registrytest.NewPodRegistry(nil)
|
podRegistry := registrytest.NewPodRegistry(nil)
|
||||||
podRegistry.Pod = &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
|
podRegistry.Pod = &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
|
||||||
storage := RegistryStorage{
|
storage := RegistryStorage{
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/fake"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/minion"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/minion"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
|
||||||
@ -30,7 +30,7 @@ import (
|
|||||||
|
|
||||||
func TestServiceRegistryCreate(t *testing.T) {
|
func TestServiceRegistryCreate(t *testing.T) {
|
||||||
registry := registrytest.NewServiceRegistry()
|
registry := registrytest.NewServiceRegistry()
|
||||||
fakeCloud := &cloudprovider.FakeCloud{}
|
fakeCloud := &fake_cloud.FakeCloud{}
|
||||||
machines := []string{"foo", "bar", "baz"}
|
machines := []string{"foo", "bar", "baz"}
|
||||||
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
|
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
|
||||||
svc := &api.Service{
|
svc := &api.Service{
|
||||||
@ -136,7 +136,7 @@ func TestServiceStorageValidatesUpdate(t *testing.T) {
|
|||||||
|
|
||||||
func TestServiceRegistryExternalService(t *testing.T) {
|
func TestServiceRegistryExternalService(t *testing.T) {
|
||||||
registry := registrytest.NewServiceRegistry()
|
registry := registrytest.NewServiceRegistry()
|
||||||
fakeCloud := &cloudprovider.FakeCloud{}
|
fakeCloud := &fake_cloud.FakeCloud{}
|
||||||
machines := []string{"foo", "bar", "baz"}
|
machines := []string{"foo", "bar", "baz"}
|
||||||
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
|
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
|
||||||
svc := &api.Service{
|
svc := &api.Service{
|
||||||
@ -160,7 +160,7 @@ func TestServiceRegistryExternalService(t *testing.T) {
|
|||||||
|
|
||||||
func TestServiceRegistryExternalServiceError(t *testing.T) {
|
func TestServiceRegistryExternalServiceError(t *testing.T) {
|
||||||
registry := registrytest.NewServiceRegistry()
|
registry := registrytest.NewServiceRegistry()
|
||||||
fakeCloud := &cloudprovider.FakeCloud{
|
fakeCloud := &fake_cloud.FakeCloud{
|
||||||
Err: fmt.Errorf("test error"),
|
Err: fmt.Errorf("test error"),
|
||||||
}
|
}
|
||||||
machines := []string{"foo", "bar", "baz"}
|
machines := []string{"foo", "bar", "baz"}
|
||||||
@ -182,7 +182,7 @@ func TestServiceRegistryExternalServiceError(t *testing.T) {
|
|||||||
|
|
||||||
func TestServiceRegistryDelete(t *testing.T) {
|
func TestServiceRegistryDelete(t *testing.T) {
|
||||||
registry := registrytest.NewServiceRegistry()
|
registry := registrytest.NewServiceRegistry()
|
||||||
fakeCloud := &cloudprovider.FakeCloud{}
|
fakeCloud := &fake_cloud.FakeCloud{}
|
||||||
machines := []string{"foo", "bar", "baz"}
|
machines := []string{"foo", "bar", "baz"}
|
||||||
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
|
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
|
||||||
svc := api.Service{
|
svc := api.Service{
|
||||||
@ -202,7 +202,7 @@ func TestServiceRegistryDelete(t *testing.T) {
|
|||||||
|
|
||||||
func TestServiceRegistryDeleteExternal(t *testing.T) {
|
func TestServiceRegistryDeleteExternal(t *testing.T) {
|
||||||
registry := registrytest.NewServiceRegistry()
|
registry := registrytest.NewServiceRegistry()
|
||||||
fakeCloud := &cloudprovider.FakeCloud{}
|
fakeCloud := &fake_cloud.FakeCloud{}
|
||||||
machines := []string{"foo", "bar", "baz"}
|
machines := []string{"foo", "bar", "baz"}
|
||||||
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
|
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
|
||||||
svc := api.Service{
|
svc := api.Service{
|
||||||
@ -245,7 +245,7 @@ func TestServiceRegistryMakeLinkVariables(t *testing.T) {
|
|||||||
|
|
||||||
func TestServiceRegistryGet(t *testing.T) {
|
func TestServiceRegistryGet(t *testing.T) {
|
||||||
registry := registrytest.NewServiceRegistry()
|
registry := registrytest.NewServiceRegistry()
|
||||||
fakeCloud := &cloudprovider.FakeCloud{}
|
fakeCloud := &fake_cloud.FakeCloud{}
|
||||||
machines := []string{"foo", "bar", "baz"}
|
machines := []string{"foo", "bar", "baz"}
|
||||||
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
|
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
|
||||||
registry.CreateService(api.Service{
|
registry.CreateService(api.Service{
|
||||||
@ -263,7 +263,7 @@ func TestServiceRegistryGet(t *testing.T) {
|
|||||||
|
|
||||||
func TestServiceRegistryList(t *testing.T) {
|
func TestServiceRegistryList(t *testing.T) {
|
||||||
registry := registrytest.NewServiceRegistry()
|
registry := registrytest.NewServiceRegistry()
|
||||||
fakeCloud := &cloudprovider.FakeCloud{}
|
fakeCloud := &fake_cloud.FakeCloud{}
|
||||||
machines := []string{"foo", "bar", "baz"}
|
machines := []string{"foo", "bar", "baz"}
|
||||||
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
|
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
|
||||||
registry.CreateService(api.Service{
|
registry.CreateService(api.Service{
|
||||||
|
Loading…
Reference in New Issue
Block a user