...

Source file src/github.com/aws/aws-sdk-go-v2/service/ecrpublic/endpoints_test.go

Documentation: github.com/aws/aws-sdk-go-v2/service/ecrpublic

     1  // Code generated by smithy-go-codegen DO NOT EDIT.
     2  
     3  package ecrpublic
     4  
     5  import (
     6  	"context"
     7  	smithy "github.com/aws/smithy-go"
     8  	smithyendpoints "github.com/aws/smithy-go/endpoints"
     9  	"github.com/aws/smithy-go/ptr"
    10  	"github.com/google/go-cmp/cmp"
    11  	"net/http"
    12  	"net/url"
    13  	"strings"
    14  	"testing"
    15  )
    16  
    17  // For region us-east-1 with FIPS enabled and DualStack enabled
    18  func TestEndpointCase0(t *testing.T) {
    19  	var params = EndpointParameters{
    20  		Region:       ptr.String("us-east-1"),
    21  		UseFIPS:      ptr.Bool(true),
    22  		UseDualStack: ptr.Bool(true),
    23  	}
    24  
    25  	resolver := NewDefaultEndpointResolverV2()
    26  	result, err := resolver.ResolveEndpoint(context.Background(), params)
    27  	_, _ = result, err
    28  
    29  	if err != nil {
    30  		t.Fatalf("expect no error, got %v", err)
    31  	}
    32  
    33  	uri, _ := url.Parse("https://api.ecr-public-fips.us-east-1.api.aws")
    34  
    35  	expectEndpoint := smithyendpoints.Endpoint{
    36  		URI:        *uri,
    37  		Headers:    http.Header{},
    38  		Properties: smithy.Properties{},
    39  	}
    40  
    41  	if e, a := expectEndpoint.URI, result.URI; e != a {
    42  		t.Errorf("expect %v URI, got %v", e, a)
    43  	}
    44  
    45  	if diff := cmp.Diff(expectEndpoint.Headers, result.Headers); diff != "" {
    46  		t.Errorf("expect headers to match\n%s", diff)
    47  	}
    48  
    49  	if diff := cmp.Diff(expectEndpoint.Properties, result.Properties,
    50  		cmp.AllowUnexported(smithy.Properties{}),
    51  	); diff != "" {
    52  		t.Errorf("expect properties to match\n%s", diff)
    53  	}
    54  }
    55  
    56  // For region us-east-1 with FIPS enabled and DualStack disabled
    57  func TestEndpointCase1(t *testing.T) {
    58  	var params = EndpointParameters{
    59  		Region:       ptr.String("us-east-1"),
    60  		UseFIPS:      ptr.Bool(true),
    61  		UseDualStack: ptr.Bool(false),
    62  	}
    63  
    64  	resolver := NewDefaultEndpointResolverV2()
    65  	result, err := resolver.ResolveEndpoint(context.Background(), params)
    66  	_, _ = result, err
    67  
    68  	if err != nil {
    69  		t.Fatalf("expect no error, got %v", err)
    70  	}
    71  
    72  	uri, _ := url.Parse("https://api.ecr-public-fips.us-east-1.amazonaws.com")
    73  
    74  	expectEndpoint := smithyendpoints.Endpoint{
    75  		URI:        *uri,
    76  		Headers:    http.Header{},
    77  		Properties: smithy.Properties{},
    78  	}
    79  
    80  	if e, a := expectEndpoint.URI, result.URI; e != a {
    81  		t.Errorf("expect %v URI, got %v", e, a)
    82  	}
    83  
    84  	if diff := cmp.Diff(expectEndpoint.Headers, result.Headers); diff != "" {
    85  		t.Errorf("expect headers to match\n%s", diff)
    86  	}
    87  
    88  	if diff := cmp.Diff(expectEndpoint.Properties, result.Properties,
    89  		cmp.AllowUnexported(smithy.Properties{}),
    90  	); diff != "" {
    91  		t.Errorf("expect properties to match\n%s", diff)
    92  	}
    93  }
    94  
    95  // For region us-east-1 with FIPS disabled and DualStack enabled
    96  func TestEndpointCase2(t *testing.T) {
    97  	var params = EndpointParameters{
    98  		Region:       ptr.String("us-east-1"),
    99  		UseFIPS:      ptr.Bool(false),
   100  		UseDualStack: ptr.Bool(true),
   101  	}
   102  
   103  	resolver := NewDefaultEndpointResolverV2()
   104  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   105  	_, _ = result, err
   106  
   107  	if err != nil {
   108  		t.Fatalf("expect no error, got %v", err)
   109  	}
   110  
   111  	uri, _ := url.Parse("https://api.ecr-public.us-east-1.api.aws")
   112  
   113  	expectEndpoint := smithyendpoints.Endpoint{
   114  		URI:        *uri,
   115  		Headers:    http.Header{},
   116  		Properties: smithy.Properties{},
   117  	}
   118  
   119  	if e, a := expectEndpoint.URI, result.URI; e != a {
   120  		t.Errorf("expect %v URI, got %v", e, a)
   121  	}
   122  
   123  	if diff := cmp.Diff(expectEndpoint.Headers, result.Headers); diff != "" {
   124  		t.Errorf("expect headers to match\n%s", diff)
   125  	}
   126  
   127  	if diff := cmp.Diff(expectEndpoint.Properties, result.Properties,
   128  		cmp.AllowUnexported(smithy.Properties{}),
   129  	); diff != "" {
   130  		t.Errorf("expect properties to match\n%s", diff)
   131  	}
   132  }
   133  
   134  // For region us-east-1 with FIPS disabled and DualStack disabled
   135  func TestEndpointCase3(t *testing.T) {
   136  	var params = EndpointParameters{
   137  		Region:       ptr.String("us-east-1"),
   138  		UseFIPS:      ptr.Bool(false),
   139  		UseDualStack: ptr.Bool(false),
   140  	}
   141  
   142  	resolver := NewDefaultEndpointResolverV2()
   143  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   144  	_, _ = result, err
   145  
   146  	if err != nil {
   147  		t.Fatalf("expect no error, got %v", err)
   148  	}
   149  
   150  	uri, _ := url.Parse("https://api.ecr-public.us-east-1.amazonaws.com")
   151  
   152  	expectEndpoint := smithyendpoints.Endpoint{
   153  		URI:        *uri,
   154  		Headers:    http.Header{},
   155  		Properties: smithy.Properties{},
   156  	}
   157  
   158  	if e, a := expectEndpoint.URI, result.URI; e != a {
   159  		t.Errorf("expect %v URI, got %v", e, a)
   160  	}
   161  
   162  	if diff := cmp.Diff(expectEndpoint.Headers, result.Headers); diff != "" {
   163  		t.Errorf("expect headers to match\n%s", diff)
   164  	}
   165  
   166  	if diff := cmp.Diff(expectEndpoint.Properties, result.Properties,
   167  		cmp.AllowUnexported(smithy.Properties{}),
   168  	); diff != "" {
   169  		t.Errorf("expect properties to match\n%s", diff)
   170  	}
   171  }
   172  
   173  // For region cn-north-1 with FIPS enabled and DualStack enabled
   174  func TestEndpointCase4(t *testing.T) {
   175  	var params = EndpointParameters{
   176  		Region:       ptr.String("cn-north-1"),
   177  		UseFIPS:      ptr.Bool(true),
   178  		UseDualStack: ptr.Bool(true),
   179  	}
   180  
   181  	resolver := NewDefaultEndpointResolverV2()
   182  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   183  	_, _ = result, err
   184  
   185  	if err != nil {
   186  		t.Fatalf("expect no error, got %v", err)
   187  	}
   188  
   189  	uri, _ := url.Parse("https://api.ecr-public-fips.cn-north-1.api.amazonwebservices.com.cn")
   190  
   191  	expectEndpoint := smithyendpoints.Endpoint{
   192  		URI:        *uri,
   193  		Headers:    http.Header{},
   194  		Properties: smithy.Properties{},
   195  	}
   196  
   197  	if e, a := expectEndpoint.URI, result.URI; e != a {
   198  		t.Errorf("expect %v URI, got %v", e, a)
   199  	}
   200  
   201  	if diff := cmp.Diff(expectEndpoint.Headers, result.Headers); diff != "" {
   202  		t.Errorf("expect headers to match\n%s", diff)
   203  	}
   204  
   205  	if diff := cmp.Diff(expectEndpoint.Properties, result.Properties,
   206  		cmp.AllowUnexported(smithy.Properties{}),
   207  	); diff != "" {
   208  		t.Errorf("expect properties to match\n%s", diff)
   209  	}
   210  }
   211  
   212  // For region cn-north-1 with FIPS enabled and DualStack disabled
   213  func TestEndpointCase5(t *testing.T) {
   214  	var params = EndpointParameters{
   215  		Region:       ptr.String("cn-north-1"),
   216  		UseFIPS:      ptr.Bool(true),
   217  		UseDualStack: ptr.Bool(false),
   218  	}
   219  
   220  	resolver := NewDefaultEndpointResolverV2()
   221  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   222  	_, _ = result, err
   223  
   224  	if err != nil {
   225  		t.Fatalf("expect no error, got %v", err)
   226  	}
   227  
   228  	uri, _ := url.Parse("https://api.ecr-public-fips.cn-north-1.amazonaws.com.cn")
   229  
   230  	expectEndpoint := smithyendpoints.Endpoint{
   231  		URI:        *uri,
   232  		Headers:    http.Header{},
   233  		Properties: smithy.Properties{},
   234  	}
   235  
   236  	if e, a := expectEndpoint.URI, result.URI; e != a {
   237  		t.Errorf("expect %v URI, got %v", e, a)
   238  	}
   239  
   240  	if diff := cmp.Diff(expectEndpoint.Headers, result.Headers); diff != "" {
   241  		t.Errorf("expect headers to match\n%s", diff)
   242  	}
   243  
   244  	if diff := cmp.Diff(expectEndpoint.Properties, result.Properties,
   245  		cmp.AllowUnexported(smithy.Properties{}),
   246  	); diff != "" {
   247  		t.Errorf("expect properties to match\n%s", diff)
   248  	}
   249  }
   250  
   251  // For region cn-north-1 with FIPS disabled and DualStack enabled
   252  func TestEndpointCase6(t *testing.T) {
   253  	var params = EndpointParameters{
   254  		Region:       ptr.String("cn-north-1"),
   255  		UseFIPS:      ptr.Bool(false),
   256  		UseDualStack: ptr.Bool(true),
   257  	}
   258  
   259  	resolver := NewDefaultEndpointResolverV2()
   260  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   261  	_, _ = result, err
   262  
   263  	if err != nil {
   264  		t.Fatalf("expect no error, got %v", err)
   265  	}
   266  
   267  	uri, _ := url.Parse("https://api.ecr-public.cn-north-1.api.amazonwebservices.com.cn")
   268  
   269  	expectEndpoint := smithyendpoints.Endpoint{
   270  		URI:        *uri,
   271  		Headers:    http.Header{},
   272  		Properties: smithy.Properties{},
   273  	}
   274  
   275  	if e, a := expectEndpoint.URI, result.URI; e != a {
   276  		t.Errorf("expect %v URI, got %v", e, a)
   277  	}
   278  
   279  	if diff := cmp.Diff(expectEndpoint.Headers, result.Headers); diff != "" {
   280  		t.Errorf("expect headers to match\n%s", diff)
   281  	}
   282  
   283  	if diff := cmp.Diff(expectEndpoint.Properties, result.Properties,
   284  		cmp.AllowUnexported(smithy.Properties{}),
   285  	); diff != "" {
   286  		t.Errorf("expect properties to match\n%s", diff)
   287  	}
   288  }
   289  
   290  // For region cn-north-1 with FIPS disabled and DualStack disabled
   291  func TestEndpointCase7(t *testing.T) {
   292  	var params = EndpointParameters{
   293  		Region:       ptr.String("cn-north-1"),
   294  		UseFIPS:      ptr.Bool(false),
   295  		UseDualStack: ptr.Bool(false),
   296  	}
   297  
   298  	resolver := NewDefaultEndpointResolverV2()
   299  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   300  	_, _ = result, err
   301  
   302  	if err != nil {
   303  		t.Fatalf("expect no error, got %v", err)
   304  	}
   305  
   306  	uri, _ := url.Parse("https://api.ecr-public.cn-north-1.amazonaws.com.cn")
   307  
   308  	expectEndpoint := smithyendpoints.Endpoint{
   309  		URI:        *uri,
   310  		Headers:    http.Header{},
   311  		Properties: smithy.Properties{},
   312  	}
   313  
   314  	if e, a := expectEndpoint.URI, result.URI; e != a {
   315  		t.Errorf("expect %v URI, got %v", e, a)
   316  	}
   317  
   318  	if diff := cmp.Diff(expectEndpoint.Headers, result.Headers); diff != "" {
   319  		t.Errorf("expect headers to match\n%s", diff)
   320  	}
   321  
   322  	if diff := cmp.Diff(expectEndpoint.Properties, result.Properties,
   323  		cmp.AllowUnexported(smithy.Properties{}),
   324  	); diff != "" {
   325  		t.Errorf("expect properties to match\n%s", diff)
   326  	}
   327  }
   328  
   329  // For region us-gov-east-1 with FIPS enabled and DualStack enabled
   330  func TestEndpointCase8(t *testing.T) {
   331  	var params = EndpointParameters{
   332  		Region:       ptr.String("us-gov-east-1"),
   333  		UseFIPS:      ptr.Bool(true),
   334  		UseDualStack: ptr.Bool(true),
   335  	}
   336  
   337  	resolver := NewDefaultEndpointResolverV2()
   338  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   339  	_, _ = result, err
   340  
   341  	if err != nil {
   342  		t.Fatalf("expect no error, got %v", err)
   343  	}
   344  
   345  	uri, _ := url.Parse("https://api.ecr-public-fips.us-gov-east-1.api.aws")
   346  
   347  	expectEndpoint := smithyendpoints.Endpoint{
   348  		URI:        *uri,
   349  		Headers:    http.Header{},
   350  		Properties: smithy.Properties{},
   351  	}
   352  
   353  	if e, a := expectEndpoint.URI, result.URI; e != a {
   354  		t.Errorf("expect %v URI, got %v", e, a)
   355  	}
   356  
   357  	if diff := cmp.Diff(expectEndpoint.Headers, result.Headers); diff != "" {
   358  		t.Errorf("expect headers to match\n%s", diff)
   359  	}
   360  
   361  	if diff := cmp.Diff(expectEndpoint.Properties, result.Properties,
   362  		cmp.AllowUnexported(smithy.Properties{}),
   363  	); diff != "" {
   364  		t.Errorf("expect properties to match\n%s", diff)
   365  	}
   366  }
   367  
   368  // For region us-gov-east-1 with FIPS enabled and DualStack disabled
   369  func TestEndpointCase9(t *testing.T) {
   370  	var params = EndpointParameters{
   371  		Region:       ptr.String("us-gov-east-1"),
   372  		UseFIPS:      ptr.Bool(true),
   373  		UseDualStack: ptr.Bool(false),
   374  	}
   375  
   376  	resolver := NewDefaultEndpointResolverV2()
   377  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   378  	_, _ = result, err
   379  
   380  	if err != nil {
   381  		t.Fatalf("expect no error, got %v", err)
   382  	}
   383  
   384  	uri, _ := url.Parse("https://api.ecr-public-fips.us-gov-east-1.amazonaws.com")
   385  
   386  	expectEndpoint := smithyendpoints.Endpoint{
   387  		URI:        *uri,
   388  		Headers:    http.Header{},
   389  		Properties: smithy.Properties{},
   390  	}
   391  
   392  	if e, a := expectEndpoint.URI, result.URI; e != a {
   393  		t.Errorf("expect %v URI, got %v", e, a)
   394  	}
   395  
   396  	if diff := cmp.Diff(expectEndpoint.Headers, result.Headers); diff != "" {
   397  		t.Errorf("expect headers to match\n%s", diff)
   398  	}
   399  
   400  	if diff := cmp.Diff(expectEndpoint.Properties, result.Properties,
   401  		cmp.AllowUnexported(smithy.Properties{}),
   402  	); diff != "" {
   403  		t.Errorf("expect properties to match\n%s", diff)
   404  	}
   405  }
   406  
   407  // For region us-gov-east-1 with FIPS disabled and DualStack enabled
   408  func TestEndpointCase10(t *testing.T) {
   409  	var params = EndpointParameters{
   410  		Region:       ptr.String("us-gov-east-1"),
   411  		UseFIPS:      ptr.Bool(false),
   412  		UseDualStack: ptr.Bool(true),
   413  	}
   414  
   415  	resolver := NewDefaultEndpointResolverV2()
   416  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   417  	_, _ = result, err
   418  
   419  	if err != nil {
   420  		t.Fatalf("expect no error, got %v", err)
   421  	}
   422  
   423  	uri, _ := url.Parse("https://api.ecr-public.us-gov-east-1.api.aws")
   424  
   425  	expectEndpoint := smithyendpoints.Endpoint{
   426  		URI:        *uri,
   427  		Headers:    http.Header{},
   428  		Properties: smithy.Properties{},
   429  	}
   430  
   431  	if e, a := expectEndpoint.URI, result.URI; e != a {
   432  		t.Errorf("expect %v URI, got %v", e, a)
   433  	}
   434  
   435  	if diff := cmp.Diff(expectEndpoint.Headers, result.Headers); diff != "" {
   436  		t.Errorf("expect headers to match\n%s", diff)
   437  	}
   438  
   439  	if diff := cmp.Diff(expectEndpoint.Properties, result.Properties,
   440  		cmp.AllowUnexported(smithy.Properties{}),
   441  	); diff != "" {
   442  		t.Errorf("expect properties to match\n%s", diff)
   443  	}
   444  }
   445  
   446  // For region us-gov-east-1 with FIPS disabled and DualStack disabled
   447  func TestEndpointCase11(t *testing.T) {
   448  	var params = EndpointParameters{
   449  		Region:       ptr.String("us-gov-east-1"),
   450  		UseFIPS:      ptr.Bool(false),
   451  		UseDualStack: ptr.Bool(false),
   452  	}
   453  
   454  	resolver := NewDefaultEndpointResolverV2()
   455  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   456  	_, _ = result, err
   457  
   458  	if err != nil {
   459  		t.Fatalf("expect no error, got %v", err)
   460  	}
   461  
   462  	uri, _ := url.Parse("https://api.ecr-public.us-gov-east-1.amazonaws.com")
   463  
   464  	expectEndpoint := smithyendpoints.Endpoint{
   465  		URI:        *uri,
   466  		Headers:    http.Header{},
   467  		Properties: smithy.Properties{},
   468  	}
   469  
   470  	if e, a := expectEndpoint.URI, result.URI; e != a {
   471  		t.Errorf("expect %v URI, got %v", e, a)
   472  	}
   473  
   474  	if diff := cmp.Diff(expectEndpoint.Headers, result.Headers); diff != "" {
   475  		t.Errorf("expect headers to match\n%s", diff)
   476  	}
   477  
   478  	if diff := cmp.Diff(expectEndpoint.Properties, result.Properties,
   479  		cmp.AllowUnexported(smithy.Properties{}),
   480  	); diff != "" {
   481  		t.Errorf("expect properties to match\n%s", diff)
   482  	}
   483  }
   484  
   485  // For region us-iso-east-1 with FIPS enabled and DualStack enabled
   486  func TestEndpointCase12(t *testing.T) {
   487  	var params = EndpointParameters{
   488  		Region:       ptr.String("us-iso-east-1"),
   489  		UseFIPS:      ptr.Bool(true),
   490  		UseDualStack: ptr.Bool(true),
   491  	}
   492  
   493  	resolver := NewDefaultEndpointResolverV2()
   494  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   495  	_, _ = result, err
   496  
   497  	if err == nil {
   498  		t.Fatalf("expect error, got none")
   499  	}
   500  	if e, a := "FIPS and DualStack are enabled, but this partition does not support one or both", err.Error(); !strings.Contains(a, e) {
   501  		t.Errorf("expect %v error in %v", e, a)
   502  	}
   503  }
   504  
   505  // For region us-iso-east-1 with FIPS enabled and DualStack disabled
   506  func TestEndpointCase13(t *testing.T) {
   507  	var params = EndpointParameters{
   508  		Region:       ptr.String("us-iso-east-1"),
   509  		UseFIPS:      ptr.Bool(true),
   510  		UseDualStack: ptr.Bool(false),
   511  	}
   512  
   513  	resolver := NewDefaultEndpointResolverV2()
   514  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   515  	_, _ = result, err
   516  
   517  	if err != nil {
   518  		t.Fatalf("expect no error, got %v", err)
   519  	}
   520  
   521  	uri, _ := url.Parse("https://api.ecr-public-fips.us-iso-east-1.c2s.ic.gov")
   522  
   523  	expectEndpoint := smithyendpoints.Endpoint{
   524  		URI:        *uri,
   525  		Headers:    http.Header{},
   526  		Properties: smithy.Properties{},
   527  	}
   528  
   529  	if e, a := expectEndpoint.URI, result.URI; e != a {
   530  		t.Errorf("expect %v URI, got %v", e, a)
   531  	}
   532  
   533  	if diff := cmp.Diff(expectEndpoint.Headers, result.Headers); diff != "" {
   534  		t.Errorf("expect headers to match\n%s", diff)
   535  	}
   536  
   537  	if diff := cmp.Diff(expectEndpoint.Properties, result.Properties,
   538  		cmp.AllowUnexported(smithy.Properties{}),
   539  	); diff != "" {
   540  		t.Errorf("expect properties to match\n%s", diff)
   541  	}
   542  }
   543  
   544  // For region us-iso-east-1 with FIPS disabled and DualStack enabled
   545  func TestEndpointCase14(t *testing.T) {
   546  	var params = EndpointParameters{
   547  		Region:       ptr.String("us-iso-east-1"),
   548  		UseFIPS:      ptr.Bool(false),
   549  		UseDualStack: ptr.Bool(true),
   550  	}
   551  
   552  	resolver := NewDefaultEndpointResolverV2()
   553  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   554  	_, _ = result, err
   555  
   556  	if err == nil {
   557  		t.Fatalf("expect error, got none")
   558  	}
   559  	if e, a := "DualStack is enabled but this partition does not support DualStack", err.Error(); !strings.Contains(a, e) {
   560  		t.Errorf("expect %v error in %v", e, a)
   561  	}
   562  }
   563  
   564  // For region us-iso-east-1 with FIPS disabled and DualStack disabled
   565  func TestEndpointCase15(t *testing.T) {
   566  	var params = EndpointParameters{
   567  		Region:       ptr.String("us-iso-east-1"),
   568  		UseFIPS:      ptr.Bool(false),
   569  		UseDualStack: ptr.Bool(false),
   570  	}
   571  
   572  	resolver := NewDefaultEndpointResolverV2()
   573  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   574  	_, _ = result, err
   575  
   576  	if err != nil {
   577  		t.Fatalf("expect no error, got %v", err)
   578  	}
   579  
   580  	uri, _ := url.Parse("https://api.ecr-public.us-iso-east-1.c2s.ic.gov")
   581  
   582  	expectEndpoint := smithyendpoints.Endpoint{
   583  		URI:        *uri,
   584  		Headers:    http.Header{},
   585  		Properties: smithy.Properties{},
   586  	}
   587  
   588  	if e, a := expectEndpoint.URI, result.URI; e != a {
   589  		t.Errorf("expect %v URI, got %v", e, a)
   590  	}
   591  
   592  	if diff := cmp.Diff(expectEndpoint.Headers, result.Headers); diff != "" {
   593  		t.Errorf("expect headers to match\n%s", diff)
   594  	}
   595  
   596  	if diff := cmp.Diff(expectEndpoint.Properties, result.Properties,
   597  		cmp.AllowUnexported(smithy.Properties{}),
   598  	); diff != "" {
   599  		t.Errorf("expect properties to match\n%s", diff)
   600  	}
   601  }
   602  
   603  // For region us-isob-east-1 with FIPS enabled and DualStack enabled
   604  func TestEndpointCase16(t *testing.T) {
   605  	var params = EndpointParameters{
   606  		Region:       ptr.String("us-isob-east-1"),
   607  		UseFIPS:      ptr.Bool(true),
   608  		UseDualStack: ptr.Bool(true),
   609  	}
   610  
   611  	resolver := NewDefaultEndpointResolverV2()
   612  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   613  	_, _ = result, err
   614  
   615  	if err == nil {
   616  		t.Fatalf("expect error, got none")
   617  	}
   618  	if e, a := "FIPS and DualStack are enabled, but this partition does not support one or both", err.Error(); !strings.Contains(a, e) {
   619  		t.Errorf("expect %v error in %v", e, a)
   620  	}
   621  }
   622  
   623  // For region us-isob-east-1 with FIPS enabled and DualStack disabled
   624  func TestEndpointCase17(t *testing.T) {
   625  	var params = EndpointParameters{
   626  		Region:       ptr.String("us-isob-east-1"),
   627  		UseFIPS:      ptr.Bool(true),
   628  		UseDualStack: ptr.Bool(false),
   629  	}
   630  
   631  	resolver := NewDefaultEndpointResolverV2()
   632  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   633  	_, _ = result, err
   634  
   635  	if err != nil {
   636  		t.Fatalf("expect no error, got %v", err)
   637  	}
   638  
   639  	uri, _ := url.Parse("https://api.ecr-public-fips.us-isob-east-1.sc2s.sgov.gov")
   640  
   641  	expectEndpoint := smithyendpoints.Endpoint{
   642  		URI:        *uri,
   643  		Headers:    http.Header{},
   644  		Properties: smithy.Properties{},
   645  	}
   646  
   647  	if e, a := expectEndpoint.URI, result.URI; e != a {
   648  		t.Errorf("expect %v URI, got %v", e, a)
   649  	}
   650  
   651  	if diff := cmp.Diff(expectEndpoint.Headers, result.Headers); diff != "" {
   652  		t.Errorf("expect headers to match\n%s", diff)
   653  	}
   654  
   655  	if diff := cmp.Diff(expectEndpoint.Properties, result.Properties,
   656  		cmp.AllowUnexported(smithy.Properties{}),
   657  	); diff != "" {
   658  		t.Errorf("expect properties to match\n%s", diff)
   659  	}
   660  }
   661  
   662  // For region us-isob-east-1 with FIPS disabled and DualStack enabled
   663  func TestEndpointCase18(t *testing.T) {
   664  	var params = EndpointParameters{
   665  		Region:       ptr.String("us-isob-east-1"),
   666  		UseFIPS:      ptr.Bool(false),
   667  		UseDualStack: ptr.Bool(true),
   668  	}
   669  
   670  	resolver := NewDefaultEndpointResolverV2()
   671  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   672  	_, _ = result, err
   673  
   674  	if err == nil {
   675  		t.Fatalf("expect error, got none")
   676  	}
   677  	if e, a := "DualStack is enabled but this partition does not support DualStack", err.Error(); !strings.Contains(a, e) {
   678  		t.Errorf("expect %v error in %v", e, a)
   679  	}
   680  }
   681  
   682  // For region us-isob-east-1 with FIPS disabled and DualStack disabled
   683  func TestEndpointCase19(t *testing.T) {
   684  	var params = EndpointParameters{
   685  		Region:       ptr.String("us-isob-east-1"),
   686  		UseFIPS:      ptr.Bool(false),
   687  		UseDualStack: ptr.Bool(false),
   688  	}
   689  
   690  	resolver := NewDefaultEndpointResolverV2()
   691  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   692  	_, _ = result, err
   693  
   694  	if err != nil {
   695  		t.Fatalf("expect no error, got %v", err)
   696  	}
   697  
   698  	uri, _ := url.Parse("https://api.ecr-public.us-isob-east-1.sc2s.sgov.gov")
   699  
   700  	expectEndpoint := smithyendpoints.Endpoint{
   701  		URI:        *uri,
   702  		Headers:    http.Header{},
   703  		Properties: smithy.Properties{},
   704  	}
   705  
   706  	if e, a := expectEndpoint.URI, result.URI; e != a {
   707  		t.Errorf("expect %v URI, got %v", e, a)
   708  	}
   709  
   710  	if diff := cmp.Diff(expectEndpoint.Headers, result.Headers); diff != "" {
   711  		t.Errorf("expect headers to match\n%s", diff)
   712  	}
   713  
   714  	if diff := cmp.Diff(expectEndpoint.Properties, result.Properties,
   715  		cmp.AllowUnexported(smithy.Properties{}),
   716  	); diff != "" {
   717  		t.Errorf("expect properties to match\n%s", diff)
   718  	}
   719  }
   720  
   721  // For custom endpoint with region set and fips disabled and dualstack disabled
   722  func TestEndpointCase20(t *testing.T) {
   723  	var params = EndpointParameters{
   724  		Region:       ptr.String("us-east-1"),
   725  		UseFIPS:      ptr.Bool(false),
   726  		UseDualStack: ptr.Bool(false),
   727  		Endpoint:     ptr.String("https://example.com"),
   728  	}
   729  
   730  	resolver := NewDefaultEndpointResolverV2()
   731  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   732  	_, _ = result, err
   733  
   734  	if err != nil {
   735  		t.Fatalf("expect no error, got %v", err)
   736  	}
   737  
   738  	uri, _ := url.Parse("https://example.com")
   739  
   740  	expectEndpoint := smithyendpoints.Endpoint{
   741  		URI:        *uri,
   742  		Headers:    http.Header{},
   743  		Properties: smithy.Properties{},
   744  	}
   745  
   746  	if e, a := expectEndpoint.URI, result.URI; e != a {
   747  		t.Errorf("expect %v URI, got %v", e, a)
   748  	}
   749  
   750  	if diff := cmp.Diff(expectEndpoint.Headers, result.Headers); diff != "" {
   751  		t.Errorf("expect headers to match\n%s", diff)
   752  	}
   753  
   754  	if diff := cmp.Diff(expectEndpoint.Properties, result.Properties,
   755  		cmp.AllowUnexported(smithy.Properties{}),
   756  	); diff != "" {
   757  		t.Errorf("expect properties to match\n%s", diff)
   758  	}
   759  }
   760  
   761  // For custom endpoint with region not set and fips disabled and dualstack disabled
   762  func TestEndpointCase21(t *testing.T) {
   763  	var params = EndpointParameters{
   764  		UseFIPS:      ptr.Bool(false),
   765  		UseDualStack: ptr.Bool(false),
   766  		Endpoint:     ptr.String("https://example.com"),
   767  	}
   768  
   769  	resolver := NewDefaultEndpointResolverV2()
   770  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   771  	_, _ = result, err
   772  
   773  	if err != nil {
   774  		t.Fatalf("expect no error, got %v", err)
   775  	}
   776  
   777  	uri, _ := url.Parse("https://example.com")
   778  
   779  	expectEndpoint := smithyendpoints.Endpoint{
   780  		URI:        *uri,
   781  		Headers:    http.Header{},
   782  		Properties: smithy.Properties{},
   783  	}
   784  
   785  	if e, a := expectEndpoint.URI, result.URI; e != a {
   786  		t.Errorf("expect %v URI, got %v", e, a)
   787  	}
   788  
   789  	if diff := cmp.Diff(expectEndpoint.Headers, result.Headers); diff != "" {
   790  		t.Errorf("expect headers to match\n%s", diff)
   791  	}
   792  
   793  	if diff := cmp.Diff(expectEndpoint.Properties, result.Properties,
   794  		cmp.AllowUnexported(smithy.Properties{}),
   795  	); diff != "" {
   796  		t.Errorf("expect properties to match\n%s", diff)
   797  	}
   798  }
   799  
   800  // For custom endpoint with fips enabled and dualstack disabled
   801  func TestEndpointCase22(t *testing.T) {
   802  	var params = EndpointParameters{
   803  		Region:       ptr.String("us-east-1"),
   804  		UseFIPS:      ptr.Bool(true),
   805  		UseDualStack: ptr.Bool(false),
   806  		Endpoint:     ptr.String("https://example.com"),
   807  	}
   808  
   809  	resolver := NewDefaultEndpointResolverV2()
   810  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   811  	_, _ = result, err
   812  
   813  	if err == nil {
   814  		t.Fatalf("expect error, got none")
   815  	}
   816  	if e, a := "Invalid Configuration: FIPS and custom endpoint are not supported", err.Error(); !strings.Contains(a, e) {
   817  		t.Errorf("expect %v error in %v", e, a)
   818  	}
   819  }
   820  
   821  // For custom endpoint with fips disabled and dualstack enabled
   822  func TestEndpointCase23(t *testing.T) {
   823  	var params = EndpointParameters{
   824  		Region:       ptr.String("us-east-1"),
   825  		UseFIPS:      ptr.Bool(false),
   826  		UseDualStack: ptr.Bool(true),
   827  		Endpoint:     ptr.String("https://example.com"),
   828  	}
   829  
   830  	resolver := NewDefaultEndpointResolverV2()
   831  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   832  	_, _ = result, err
   833  
   834  	if err == nil {
   835  		t.Fatalf("expect error, got none")
   836  	}
   837  	if e, a := "Invalid Configuration: Dualstack and custom endpoint are not supported", err.Error(); !strings.Contains(a, e) {
   838  		t.Errorf("expect %v error in %v", e, a)
   839  	}
   840  }
   841  
   842  // Missing region
   843  func TestEndpointCase24(t *testing.T) {
   844  	var params = EndpointParameters{}
   845  
   846  	resolver := NewDefaultEndpointResolverV2()
   847  	result, err := resolver.ResolveEndpoint(context.Background(), params)
   848  	_, _ = result, err
   849  
   850  	if err == nil {
   851  		t.Fatalf("expect error, got none")
   852  	}
   853  	if e, a := "Invalid Configuration: Missing Region", err.Error(); !strings.Contains(a, e) {
   854  		t.Errorf("expect %v error in %v", e, a)
   855  	}
   856  }
   857  

View as plain text