Skip to content

Commit

Permalink
Mock mapper in zone tests (#5209)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepikaDixit authored and Ilya Kislenko committed Mar 15, 2019
1 parent ca4f1e5 commit 6f456ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 31 deletions.
26 changes: 8 additions & 18 deletions pkg/blockstorage/awsebs/zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package awsebs

import (
"context"
"os"

. "gopkg.in/check.v1"

Expand Down Expand Up @@ -41,9 +40,8 @@ func (s ZoneSuite) TestZoneWithUnknownNodeZones(c *C) {
out: "us-west-2a",
},
} {
config := getConfigForTest(c, tc.region)
provider, err := NewProvider(config)
z, err := zone.WithUnknownNodeZones(ctx, provider.(zone.Mapper), tc.region, tc.in)
var t = &ebsTest{}
z, err := zone.WithUnknownNodeZones(ctx, t, tc.region, tc.in)
c.Assert(err, IsNil)
c.Assert(z, Not(Equals), "")
if tc.out != "" {
Expand All @@ -52,19 +50,11 @@ func (s ZoneSuite) TestZoneWithUnknownNodeZones(c *C) {
}
}

func getConfigForTest(c *C, region string) map[string]string {
config := make(map[string]string)
config[ConfigRegion] = region
accessKey, ok := os.LookupEnv(AccessKeyID)
if !ok {
c.Skip("The necessary env variable AWS_ACCESS_KEY_ID is not set.")
}
secretAccessKey, ok := os.LookupEnv(SecretAccessKey)
if !ok {
c.Skip("The necessary env variable AWS_SECRET_ACCESS_KEY is not set.")
}
config[AccessKeyID] = accessKey
config[SecretAccessKey] = secretAccessKey
var _ zone.Mapper = (*ebsTest)(nil)

type ebsTest struct{}

return config
func (et *ebsTest) FromRegion(ctx context.Context, region string) ([]string, error) {
// Fall back to using a static map.
return staticRegionToZones(region)
}
22 changes: 9 additions & 13 deletions pkg/blockstorage/gcepd/zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package gcepd

import (
"context"
"os"

. "gopkg.in/check.v1"

"github.com/kanisterio/kanister/pkg/blockstorage"
"github.com/kanisterio/kanister/pkg/blockstorage/zone"
)

Expand Down Expand Up @@ -42,9 +40,8 @@ func (s ZoneSuite) TestZoneWithUnknownNodeZones(c *C) {
out: "us-west2a",
},
} {
config := getConfigForTest(c)
provider, err := NewProvider(config)
z, err := zone.WithUnknownNodeZones(ctx, provider.(zone.Mapper), tc.region, tc.in)
var t = &gcpTest{}
z, err := zone.WithUnknownNodeZones(ctx, t, tc.region, tc.in)
c.Assert(err, IsNil)
c.Assert(z, Not(Equals), "")
if tc.out != "" {
Expand All @@ -53,12 +50,11 @@ func (s ZoneSuite) TestZoneWithUnknownNodeZones(c *C) {
}
}

func getConfigForTest(c *C) map[string]string {
config := make(map[string]string)
creds, ok := os.LookupEnv(blockstorage.GoogleCloudCreds)
if !ok {
c.Skip("The necessary env variable GOOGLE_APPLICATION_CREDENTIALS is not set.")
}
config[blockstorage.GoogleCloudCreds] = creds
return config
var _ zone.Mapper = (*gcpTest)(nil)

type gcpTest struct{}

func (gt *gcpTest) FromRegion(ctx context.Context, region string) ([]string, error) {
// Fall back to using a static map.
return staticRegionToZones(region)
}

0 comments on commit 6f456ec

Please sign in to comment.