github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/runtimeversion/account_mapping_test.go (about)

     1  package runtimeversion
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  const (
    12  	cmName             = "config"
    13  	namespace          = "foo"
    14  	versionForGA       = "1.14"
    15  	versionForSA       = "1.15-rc1"
    16  	fixGlobalAccountID = "628ee42b-bd1e-42b3-8a1d-c4726fd2ee62\n"
    17  	fixSubAccountID    = "e083d3a8-5139-4705-959f-8279c86f6fe7\n"
    18  )
    19  
    20  func TestAccountVersionMapping_Get(t *testing.T) {
    21  	t.Run("Should get version for SubAccount when both GlobalAccount and SubAccount are provided", func(t *testing.T) {
    22  		// given
    23  		svc := fixAccountVersionMapping(t, map[string]string{
    24  			fmt.Sprintf("%s%s", globalAccountPrefix, fixGlobalAccountID): versionForGA,
    25  			fmt.Sprintf("%s%s", subaccountPrefix, fixSubAccountID):       versionForSA,
    26  		})
    27  
    28  		// when
    29  		version, found, err := svc.Get(fixGlobalAccountID, fixSubAccountID)
    30  		require.NoError(t, err)
    31  
    32  		// then
    33  		assert.True(t, found)
    34  		assert.Equal(t, versionForSA, version)
    35  	})
    36  
    37  	t.Run("Should get version for GlobalAccount when only GlobalAccount is provided", func(t *testing.T) {
    38  		// given
    39  		svc := fixAccountVersionMapping(t, map[string]string{
    40  			fmt.Sprintf("%s%s", globalAccountPrefix, fixGlobalAccountID): versionForGA,
    41  		})
    42  
    43  		// when
    44  		version, found, err := svc.Get(fixGlobalAccountID, fixSubAccountID)
    45  		require.NoError(t, err)
    46  
    47  		// then
    48  		assert.True(t, found)
    49  		assert.Equal(t, versionForGA, version)
    50  	})
    51  
    52  	t.Run("Should get version for SubAccount when only SubAccount is provided", func(t *testing.T) {
    53  		// given
    54  		svc := fixAccountVersionMapping(t, map[string]string{
    55  			fmt.Sprintf("%s%s", subaccountPrefix, fixSubAccountID): versionForSA,
    56  		})
    57  
    58  		// when
    59  		version, found, err := svc.Get(fixGlobalAccountID, fixSubAccountID)
    60  		require.NoError(t, err)
    61  
    62  		// then
    63  		assert.True(t, found)
    64  		assert.Equal(t, versionForSA, version)
    65  	})
    66  
    67  	t.Run("Should not get version when nothing is provided", func(t *testing.T) {
    68  		// given
    69  		svc := fixAccountVersionMapping(t, map[string]string{})
    70  
    71  		// when
    72  		version, found, err := svc.Get(fixGlobalAccountID, fixSubAccountID)
    73  		require.NoError(t, err)
    74  
    75  		// then
    76  		assert.False(t, found)
    77  		assert.Empty(t, version)
    78  	})
    79  }