|
| 1 | +package utils |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + ecs20140526 "github.com/alibabacloud-go/ecs-20140526/v7/client" |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | + "k8s.io/utils/ptr" |
| 9 | +) |
| 10 | + |
| 11 | +func TestEcsEndpoint(t *testing.T) { |
| 12 | + // All regions that has VPC endpoint from https://api.aliyun.com/api/Ecs/2014-05-26 (Regions at top-left) |
| 13 | + vpcRegions := []string{ |
| 14 | + "cn-qingdao", |
| 15 | + "cn-beijing-finance-1", |
| 16 | + "cn-beijing", |
| 17 | + "cn-zhangjiakou", |
| 18 | + "cn-huhehaote", |
| 19 | + "cn-wulanchabu", |
| 20 | + "cn-hangzhou", |
| 21 | + "cn-shanghai-finance-1", |
| 22 | + "cn-shanghai", |
| 23 | + "cn-nanjing", |
| 24 | + "cn-fuzhou", |
| 25 | + "cn-shenzhen-finance-1", |
| 26 | + "cn-shenzhen", |
| 27 | + "cn-heyuan", |
| 28 | + "cn-guangzhou", |
| 29 | + "cn-wuhan-lr", |
| 30 | + "me-east-1", |
| 31 | + "ap-southeast-2", |
| 32 | + "eu-central-1", |
| 33 | + "ap-southeast-6", |
| 34 | + "ap-northeast-2", |
| 35 | + "cn-heyuan-acdr-1", |
| 36 | + "ap-southeast-3", |
| 37 | + "us-east-1", |
| 38 | + "us-west-1", |
| 39 | + "us-southeast-1", |
| 40 | + "na-south-1", |
| 41 | + "ap-northeast-1", |
| 42 | + "me-central-1", |
| 43 | + "ap-southeast-7", |
| 44 | + "cn-zhongwei", |
| 45 | + "cn-chengdu", |
| 46 | + "ap-southeast-1", |
| 47 | + "ap-south-1", |
| 48 | + "ap-southeast-5", |
| 49 | + "eu-west-1", |
| 50 | + "cn-zhengzhou-jva", |
| 51 | + "cn-hongkong", |
| 52 | + } |
| 53 | + testEp := func(t *testing.T, region, ep string) { |
| 54 | + t.Run(region, func(t *testing.T) { |
| 55 | + cfg := GetEcsConfig(region) |
| 56 | + cfg.AccessKeyId = ptr.To("foo") |
| 57 | + cfg.AccessKeySecret = ptr.To("bar") |
| 58 | + |
| 59 | + client, err := ecs20140526.NewClient(cfg) |
| 60 | + assert.NoError(t, err) |
| 61 | + assert.Equal(t, ep, *client.Endpoint) |
| 62 | + }) |
| 63 | + } |
| 64 | + testEp(t, "cn-hangzhou", "ecs-cn-hangzhou.aliyuncs.com") // use SDK defaults by default |
| 65 | + |
| 66 | + t.Run("vpc", func(t *testing.T) { |
| 67 | + t.Setenv("ALIBABA_CLOUD_NETWORK_TYPE", "vpc") |
| 68 | + for _, region := range vpcRegions { |
| 69 | + testEp(t, region, "ecs-vpc."+region+".aliyuncs.com") |
| 70 | + } |
| 71 | + // The only region in public cloud that don't have VPC endpoint |
| 72 | + testEp(t, "cn-hangzhou-finance", "ecs.aliyuncs.com") |
| 73 | + }) |
| 74 | + |
| 75 | + t.Run("public", func(t *testing.T) { |
| 76 | + t.Setenv("ALIBABA_CLOUD_NETWORK_TYPE", "public") |
| 77 | + for _, region := range vpcRegions { |
| 78 | + testEp(t, region, "ecs."+region+".aliyuncs.com") |
| 79 | + } |
| 80 | + // Also don't have regional public endpoint |
| 81 | + testEp(t, "cn-hangzhou-finance", "ecs.aliyuncs.com") |
| 82 | + }) |
| 83 | +} |
0 commit comments