sigs.k8s.io/cluster-api-provider-azure@v1.14.3/azure/regional_baseuri_test.go (about)

     1  /*
     2  Copyright 2021 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package azure
    18  
    19  import (
    20  	"testing"
    21  
    22  	. "github.com/onsi/gomega"
    23  	"go.uber.org/mock/gomock"
    24  	"sigs.k8s.io/cluster-api-provider-azure/azure/mock_azure"
    25  )
    26  
    27  func TestWithRegionalBaseURI(t *testing.T) {
    28  	cases := []struct {
    29  		Name              string
    30  		AuthorizerFactory func(authMock *mock_azure.MockAuthorizer) Authorizer
    31  		Region            string
    32  		Result            string
    33  	}{
    34  		{
    35  			Name: "with a region",
    36  			AuthorizerFactory: func(authMock *mock_azure.MockAuthorizer) Authorizer {
    37  				authMock.EXPECT().BaseURI().Return("http://foo.bar").AnyTimes()
    38  				return authMock
    39  			},
    40  			Region: "bazz",
    41  			Result: "http://bazz.foo.bar",
    42  		},
    43  		{
    44  			Name: "with no region",
    45  			AuthorizerFactory: func(authMock *mock_azure.MockAuthorizer) Authorizer {
    46  				authMock.EXPECT().BaseURI().Return("http://foo.bar").AnyTimes()
    47  				return authMock
    48  			},
    49  			Result: "http://foo.bar",
    50  		},
    51  		{
    52  			Name: "with a region and path",
    53  			AuthorizerFactory: func(authMock *mock_azure.MockAuthorizer) Authorizer {
    54  				authMock.EXPECT().BaseURI().Return("http://foo.bar/something/id").AnyTimes()
    55  				return authMock
    56  			},
    57  			Region: "bazz",
    58  			Result: "http://bazz.foo.bar/something/id",
    59  		},
    60  	}
    61  
    62  	for _, c := range cases {
    63  		c := c
    64  		t.Run(c.Name, func(t *testing.T) {
    65  			g := NewWithT(t)
    66  			mockCtrl := gomock.NewController(t)
    67  			defer mockCtrl.Finish()
    68  			authMock := mock_azure.NewMockAuthorizer(mockCtrl)
    69  			regionalAuth, err := WithRegionalBaseURI(c.AuthorizerFactory(authMock), c.Region)
    70  			g.Expect(err).NotTo(HaveOccurred())
    71  			g.Expect(regionalAuth.BaseURI()).To(Equal(c.Result))
    72  		})
    73  	}
    74  }