github.com/grahambrereton-form3/tilt@v0.10.18/internal/container/default_registry_test.go (about)

     1  package container
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  var namedTaggedTestCases = []struct {
    11  	defaultRegistry Registry
    12  	name            string
    13  	expected        string
    14  }{
    15  	{"myreg.com", "gcr.io/foo/bar:deadbeef", "myreg.com/gcr.io_foo_bar"},
    16  	{"aws_account_id.dkr.ecr.region.amazonaws.com/bar", "gcr.io/baz/foo/bar:deadbeef", "aws_account_id.dkr.ecr.region.amazonaws.com/bar/gcr.io_baz_foo_bar"},
    17  }
    18  
    19  var namedTestCases = []struct {
    20  	defaultRegistry Registry
    21  	name            string
    22  	expected        string
    23  }{
    24  	{"myreg.com", "gcr.io/foo/bar", "myreg.com/gcr.io_foo_bar"},
    25  	{"myreg.com", "gcr.io/foo/bar", "myreg.com/gcr.io_foo_bar"},
    26  	{"aws_account_id.dkr.ecr.region.amazonaws.com/bar", "gcr.io/baz/foo/bar", "aws_account_id.dkr.ecr.region.amazonaws.com/bar/gcr.io_baz_foo_bar"},
    27  	{"gcr.io/foo", "docker.io/library/busybox", "gcr.io/foo/busybox"},
    28  	{"gcr.io/foo", "bar", "gcr.io/foo/bar"},
    29  }
    30  
    31  func TestReplaceTaggedRefDomain(t *testing.T) {
    32  	for i, tc := range namedTaggedTestCases {
    33  		t.Run(fmt.Sprintf("Test Case #%d", i), func(t *testing.T) {
    34  			rs := NewRefSelector(MustParseNamedTagged(tc.name))
    35  			actual, err := ReplaceRegistry(tc.defaultRegistry, rs)
    36  			assert.NoError(t, err)
    37  			assert.Equal(t, tc.expected, actual.String())
    38  		})
    39  	}
    40  }
    41  
    42  func TestReplaceNamed(t *testing.T) {
    43  	for i, tc := range namedTestCases {
    44  		t.Run(fmt.Sprintf("Test case #%d", i), func(t *testing.T) {
    45  			rs := NewRefSelector(MustParseNamed(tc.name))
    46  			actual, err := ReplaceRegistry(tc.defaultRegistry, rs)
    47  			assert.NoError(t, err)
    48  			assert.Equal(t, tc.expected, actual.String())
    49  		})
    50  	}
    51  }