Repository navigation
Expand file tree
/
Copy pathidentifiers_test.go
More file actions
36 lines (29 loc) · 1.56 KB
/
Copy pathidentifiers_test.go
File metadata and controls
36 lines (29 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package common //nolint:revive // pkg/common is the module's core domain package (Recommendation, ProviderType, ...), imported by name (common.X) throughout this repo and by consumer-mcp; renaming would break every consumer import
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestIdempotentReservationID_DeterministicAndSafe(t *testing.T) {
t.Parallel()
token := DeriveIdempotencyToken("exec-1", 0)
a := IdempotentReservationID("rds-id-", token)
b := IdempotentReservationID("rds-id-", token)
assert.Equal(t, a, b, "same token must yield the same reservation ID")
assert.True(t, strings.HasPrefix(a, "rds-id-"), "must carry the prefix for console identifiability")
assert.NotContains(t, a, "--", "must not contain consecutive hyphens")
assert.False(t, strings.HasSuffix(a, "-"), "must not end with a hyphen")
// prefix (7) + 40 hex chars = 47, well under RDS's tightest ID length cap.
assert.LessOrEqual(t, len(a), 60, "must stay under the tightest AWS reservation-ID length cap")
}
func TestIdempotentReservationID_DistinctTokensDistinctIDs(t *testing.T) {
t.Parallel()
id0 := IdempotentReservationID("rds-id-", DeriveIdempotencyToken("exec-1", 0))
id1 := IdempotentReservationID("rds-id-", DeriveIdempotencyToken("exec-1", 1))
assert.NotEqual(t, id0, id1, "different recs in an execution must get different IDs")
}
func TestIdempotentReservationID_EmptyTokenReturnsEmpty(t *testing.T) {
t.Parallel()
assert.Equal(t, "", IdempotentReservationID("rds-id-", ""),
"empty token must yield empty so the caller keeps its non-idempotent fallback")
}