github.com/TBD54566975/ftl@v0.219.0/internal/model/deployment_key_test.go (about)

     1  package model
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/alecthomas/assert/v2"
     7  )
     8  
     9  func TestDeploymentKey(t *testing.T) {
    10  	ensureDeterministicRand(t)
    11  	for _, test := range []struct {
    12  		key         DeploymentKey
    13  		str         string
    14  		expected    DeploymentKey
    15  		expectedErr string
    16  	}{
    17  		{key: NewDeploymentKey("time"),
    18  			expected: DeploymentKey{
    19  				Payload: DeploymentPayload{Module: "time"},
    20  				Suffix:  []byte("\x01\x94\xfd\xc2\xfa/\xfc\xc0A\xd3"),
    21  			},
    22  		},
    23  		{key: NewDeploymentKey("time"),
    24  			expected: DeploymentKey{
    25  				Payload: DeploymentPayload{Module: "time"},
    26  				Suffix:  []byte("\xff\x12\x04[s\xc8nO\xf9_"),
    27  			},
    28  		},
    29  		{str: "-0011223344", expectedErr: `expected prefix "dpl" for key "-0011223344"`},
    30  		{key: NewDeploymentKey("module-with-hyphens"), expected: DeploymentKey{
    31  			Payload: DeploymentPayload{Module: "module-with-hyphens"},
    32  			Suffix:  []byte("\xf6b\xa5\xee\xe8*\xbd\xf4J-"),
    33  		},
    34  		},
    35  		// {str: "-", decodeErr: true},
    36  	} {
    37  		keyStr := test.str
    38  		if keyStr == "" {
    39  			keyStr = test.key.String()
    40  		}
    41  		t.Run(keyStr, func(t *testing.T) {
    42  			decoded, err := ParseDeploymentKey(keyStr)
    43  			if test.expectedErr != "" {
    44  				assert.EqualError(t, err, test.expectedErr)
    45  			} else {
    46  				assert.NoError(t, err)
    47  			}
    48  
    49  			assert.Equal(t, test.expected, decoded)
    50  		})
    51  	}
    52  }
    53  
    54  func TestZeroDeploymentKey(t *testing.T) {
    55  	_, err := ParseDeploymentKey("")
    56  	assert.EqualError(t, err, "expected prefix \"dpl\" for key \"\"")
    57  }