Make ELB somewhat mockable

This commit is contained in:
Arto Jantunen 2017-11-28 10:19:39 +02:00
parent 048a3ef770
commit 53669b8217
5 changed files with 44 additions and 6 deletions

View File

@ -0,0 +1,30 @@
/*
Copyright 2016 The Kubernetes Authors.
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 mockelb
import (
"github.com/aws/aws-sdk-go/service/elb"
"github.com/aws/aws-sdk-go/service/elb/elbiface"
)
type MockELB struct {
elbiface.ELBAPI
}
func (*MockELB) DescribeLoadBalancersPages(input *elb.DescribeLoadBalancersInput, fn func(p *elb.DescribeLoadBalancersOutput, lastPage bool) (shouldContinue bool)) error {
return nil
}

View File

@ -5,6 +5,7 @@ k8s.io/kops/channels/pkg/channels
k8s.io/kops/channels/pkg/cmd k8s.io/kops/channels/pkg/cmd
k8s.io/kops/cloudmock/aws/mockautoscaling k8s.io/kops/cloudmock/aws/mockautoscaling
k8s.io/kops/cloudmock/aws/mockec2 k8s.io/kops/cloudmock/aws/mockec2
k8s.io/kops/cloudmock/aws/mockelb
k8s.io/kops/cloudmock/aws/mockroute53 k8s.io/kops/cloudmock/aws/mockroute53
k8s.io/kops/cmd/kops k8s.io/kops/cmd/kops
k8s.io/kops/cmd/kops/util k8s.io/kops/cmd/kops/util

View File

@ -29,6 +29,7 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
kopsroot "k8s.io/kops" kopsroot "k8s.io/kops"
"k8s.io/kops/cloudmock/aws/mockec2" "k8s.io/kops/cloudmock/aws/mockec2"
"k8s.io/kops/cloudmock/aws/mockelb"
"k8s.io/kops/cloudmock/aws/mockroute53" "k8s.io/kops/cloudmock/aws/mockroute53"
"k8s.io/kops/pkg/apis/kops" "k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/upup/pkg/fi/cloudup/awsup" "k8s.io/kops/upup/pkg/fi/cloudup/awsup"
@ -98,6 +99,8 @@ func (h *IntegrationTestHarness) SetupMockAWS() {
cloud.MockEC2 = mockEC2 cloud.MockEC2 = mockEC2
mockRoute53 := &mockroute53.MockRoute53{} mockRoute53 := &mockroute53.MockRoute53{}
cloud.MockRoute53 = mockRoute53 cloud.MockRoute53 = mockRoute53
mockELB := &mockelb.MockELB{}
cloud.MockELB = mockELB
mockRoute53.MockCreateZone(&route53.HostedZone{ mockRoute53.MockCreateZone(&route53.HostedZone{
Id: aws.String("/hostedzone/Z1AFAKE1ZON3YO"), Id: aws.String("/hostedzone/Z1AFAKE1ZON3YO"),

View File

@ -32,6 +32,7 @@ import (
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ec2/ec2iface" "github.com/aws/aws-sdk-go/service/ec2/ec2iface"
"github.com/aws/aws-sdk-go/service/elb" "github.com/aws/aws-sdk-go/service/elb"
"github.com/aws/aws-sdk-go/service/elb/elbiface"
"github.com/aws/aws-sdk-go/service/iam" "github.com/aws/aws-sdk-go/service/iam"
"github.com/aws/aws-sdk-go/service/route53" "github.com/aws/aws-sdk-go/service/route53"
"github.com/aws/aws-sdk-go/service/route53/route53iface" "github.com/aws/aws-sdk-go/service/route53/route53iface"
@ -86,7 +87,7 @@ type AWSCloud interface {
CloudFormation() *cloudformation.CloudFormation CloudFormation() *cloudformation.CloudFormation
EC2() ec2iface.EC2API EC2() ec2iface.EC2API
IAM() *iam.IAM IAM() *iam.IAM
ELB() *elb.ELB ELB() elbiface.ELBAPI
Autoscaling() autoscalingiface.AutoScalingAPI Autoscaling() autoscalingiface.AutoScalingAPI
Route53() route53iface.Route53API Route53() route53iface.Route53API
@ -1021,7 +1022,7 @@ func (c *awsCloudImplementation) IAM() *iam.IAM {
return c.iam return c.iam
} }
func (c *awsCloudImplementation) ELB() *elb.ELB { func (c *awsCloudImplementation) ELB() elbiface.ELBAPI {
return c.elb return c.elb
} }

View File

@ -24,7 +24,7 @@ import (
"github.com/aws/aws-sdk-go/service/cloudformation" "github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ec2/ec2iface" "github.com/aws/aws-sdk-go/service/ec2/ec2iface"
"github.com/aws/aws-sdk-go/service/elb" "github.com/aws/aws-sdk-go/service/elb/elbiface"
"github.com/aws/aws-sdk-go/service/iam" "github.com/aws/aws-sdk-go/service/iam"
"github.com/aws/aws-sdk-go/service/route53/route53iface" "github.com/aws/aws-sdk-go/service/route53/route53iface"
"github.com/golang/glog" "github.com/golang/glog"
@ -74,6 +74,7 @@ type MockCloud struct {
MockCloudFormation *cloudformation.CloudFormation MockCloudFormation *cloudformation.CloudFormation
MockEC2 ec2iface.EC2API MockEC2 ec2iface.EC2API
MockRoute53 route53iface.Route53API MockRoute53 route53iface.Route53API
MockELB elbiface.ELBAPI
} }
func (c *MockAWSCloud) DeleteGroup(g *cloudinstances.CloudInstanceGroup) error { func (c *MockAWSCloud) DeleteGroup(g *cloudinstances.CloudInstanceGroup) error {
@ -194,9 +195,11 @@ func (c *MockAWSCloud) IAM() *iam.IAM {
return nil return nil
} }
func (c *MockAWSCloud) ELB() *elb.ELB { func (c *MockAWSCloud) ELB() elbiface.ELBAPI {
glog.Fatalf("MockAWSCloud ELB not implemented") if c.MockELB == nil {
return nil glog.Fatalf("MockAWSCloud MockELB not set")
}
return c.MockELB
} }
func (c *MockAWSCloud) Autoscaling() autoscalingiface.AutoScalingAPI { func (c *MockAWSCloud) Autoscaling() autoscalingiface.AutoScalingAPI {