github.com/coreos/rocket@v1.30.1-0.20200224141603-171c416fac02/rkt/config/auth_test.go (about)

     1  // Copyright 2015 The rkt Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package config
    16  
    17  import (
    18  	"testing"
    19  )
    20  
    21  func TestGuessAWSRegion(t *testing.T) {
    22  	tests := []struct {
    23  		host   string
    24  		region string
    25  	}{
    26  		{"foo.s3.amazonaws.com", "us-east-1"},
    27  		{"foo.s3-external-1.amazonaws.com", "us-east-1"},
    28  		{"foo.bar.s3.amazonaws.com", "us-east-1"},
    29  		{"foo.s3-us-west-1.amazonaws.com", "us-west-1"},
    30  		{"foo.bar.baz.s3-us-west-2.amazonaws.com", "us-west-2"},
    31  		{"foo.s3-eu-west-1.amazonaws.com", "eu-west-1"},
    32  		{"foo.s3.eu-central-1.amazonaws.com", "eu-central-1"},
    33  		{"foo.bar.s3.eu-central-1.amazonaws.com", "eu-central-1"},
    34  		{"foo.s3-eu-central-1.amazonaws.com", "eu-central-1"},
    35  		{"foo.s3-ap-northeast-1.amazonaws.com", "ap-northeast-1"},
    36  		{"foo.s3.ap-northeast-2.amazonaws.com", "ap-northeast-2"},
    37  		{"foo.s3-ap-northeast-2.amazonaws.com", "ap-northeast-2"},
    38  		{"foo.bar.s3-ap-northeast-2.amazonaws.com", "ap-northeast-2"},
    39  		{"foo.s3-ap-southeast-1.amazonaws.com", "ap-southeast-1"},
    40  		{"foo.bar.baz.s3-ap-southeast-2.amazonaws.com", "ap-southeast-2"},
    41  		{"foo.s3-sa-east-1.amazonaws.com", "sa-east-1"},
    42  		{"foo.s3-ap-southeast-1.amazonaws.com:443", "ap-southeast-1"},
    43  		{"foo.bar.baz.s3-us-west-2.amazonaws.com:80", "us-west-2"},
    44  		{"foo.s3.eu-central-1.amazonaws.com:443", "eu-central-1"},
    45  		{"entirely.unrecognized.url", defaultAWSRegion},
    46  	}
    47  
    48  	for _, tt := range tests {
    49  		region := guessAWSRegion(tt.host)
    50  		if region != tt.region {
    51  			t.Errorf("Got unexpected result for %s: %s (expected: %s)", tt.host, region, tt.region)
    52  		}
    53  	}
    54  }