Update for failing tests

This commit is contained in:
Dave Grizzanti 2019-04-05 16:06:12 -04:00
parent 81a3fde458
commit 668a557dea
3 changed files with 58 additions and 4 deletions

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2018 The Kubernetes Authors. Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ import (
type routeSource struct { type routeSource struct {
client *cfclient.Client client *cfclient.Client
config Config
} }
// NewRouteSource creates a new routeSource with the given config // NewRouteSource creates a new routeSource with the given config
@ -38,7 +39,7 @@ func NewRouteSource(cfClient *cfclient.Client) (Source, error) {
func (rs *routeSource) Endpoints() ([]*endpoint.Endpoint, error) { func (rs *routeSource) Endpoints() ([]*endpoint.Endpoint, error) {
endpoints := []*endpoint.Endpoint{} endpoints := []*endpoint.Endpoint{}
u, err := url.Parse(rs.client.Config.ApiAddress) u, err := url.Parse(rs.config.CFAPIEndpoint)
if err != nil { if err != nil {
panic(err) panic(err)
} }

42
source/route_test.go Normal file
View File

@ -0,0 +1,42 @@
/*
Copyright 2019 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 source
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
type RouteSuite struct {
suite.Suite
}
func (suite *RouteSuite) SetupTest() {
}
func TestRouteSource(t *testing.T) {
suite.Run(t, new(RouteSuite))
t.Run("Interface", testRouteSourceImplementsSource)
}
// testRouteSourceImplementsSource tests that routeSource is a valid Source.
func testRouteSourceImplementsSource(t *testing.T) {
require.Implements(t, (*Source)(nil), new(routeSource))
}

View File

@ -24,14 +24,16 @@ import (
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/fake"
cfclient "github.com/cloudfoundry-community/go-cfclient"
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
) )
type MockClientGenerator struct { type MockClientGenerator struct {
mock.Mock mock.Mock
kubeClient kubernetes.Interface kubeClient kubernetes.Interface
istioClient istiomodel.ConfigStore istioClient istiomodel.ConfigStore
cloudFoundryClient *cfclient.Client
} }
func (m *MockClientGenerator) KubeClient() (kubernetes.Interface, error) { func (m *MockClientGenerator) KubeClient() (kubernetes.Interface, error) {
@ -52,6 +54,15 @@ func (m *MockClientGenerator) IstioClient() (istiomodel.ConfigStore, error) {
return nil, args.Error(1) return nil, args.Error(1)
} }
func (m *MockClientGenerator) CloudFoundryClient(cfAPIEndpoint string, cfUsername string, cfPassword string) (*cfclient.Client, error) {
args := m.Called()
if args.Error(1) == nil {
m.cloudFoundryClient = args.Get(0).(*cfclient.Client)
return m.cloudFoundryClient, nil
}
return nil, args.Error(1)
}
type ByNamesTestSuite struct { type ByNamesTestSuite struct {
suite.Suite suite.Suite
} }