This commit is contained in:
johannesknauft 2025-10-21 15:02:39 +02:00 committed by GitHub
commit ca71a5bfb5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package cluster
import ( import (
"context" "context"
"crypto/sha1"
"encoding/json" "encoding/json"
"fmt" "fmt"
"reflect" "reflect"
@ -330,7 +331,11 @@ func getOutboxTable(tableName string, idColumn *string) zalandov1.EventStreamTab
} }
func getSlotName(dbName, appId string) string { func getSlotName(dbName, appId string) string {
return fmt.Sprintf("%s_%s_%s", constants.EventStreamSourceSlotPrefix, dbName, strings.Replace(appId, "-", "_", -1)) name := fmt.Sprintf("%s_%s_%s", constants.EventStreamSourceSlotPrefix, dbName, strings.Replace(appId, "-", "_", -1))
if len(name) > 63 {
name = fmt.Sprintf("%s_%x", constants.EventStreamSourceSlotPrefix, sha1.Sum([]byte(name)))
}
return name
} }
func (c *Cluster) getStreamConnection(database, user, appId string) zalandov1.Connection { func (c *Cluster) getStreamConnection(database, user, appId string) zalandov1.Connection {

View File

@ -889,3 +889,27 @@ func TestDeleteStreams(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Equalf(t, 0, len(streams.Items), "unexpected number of streams found: got %d, but expected none", len(streams.Items)) assert.Equalf(t, 0, len(streams.Items), "unexpected number of streams found: got %d, but expected none", len(streams.Items))
} }
func TestSlotNameWithinMaxLength(t *testing.T) {
dbName := "testdb"
appId := "test-app"
expected := constants.EventStreamSourceSlotPrefix + "_testdb_test_app"
result := getSlotName(dbName, appId)
assert.Equal(t, expected, result)
}
func TestSlotNameExceedsMaxLength(t *testing.T) {
dbName := "testdb"
appId := "this-is-a-very-long-application-id-that-will-exceed-the-maximum-length"
expected := constants.EventStreamSourceSlotPrefix + "_5a300d179c894b672b35bac212eab875d4c4145a"
result := getSlotName(dbName, appId)
assert.Equal(t, expected, result)
}
func TestSlotNameWithHyphens(t *testing.T) {
dbName := "testdb"
appId := "test-app-with-hyphens"
expected := constants.EventStreamSourceSlotPrefix + "_testdb_test_app_with_hyphens"
result := getSlotName(dbName, appId)
assert.Equal(t, expected, result)
}