MCPcopy
hub / github.com/akuity/kargo / TestConfig_DeepCopy

Function TestConfig_DeepCopy

pkg/promotion/config_test.go:9–88  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestConfig_DeepCopy(t *testing.T) {
10 tests := []struct {
11 name string
12 config Config
13 assertions func(*testing.T, Config, Config)
14 }{
15 {
16 name: "nil config",
17 config: nil,
18 assertions: func(t *testing.T, _, copied Config) {
19 assert.Nil(t, copied, "Expected nil result for nil input")
20 },
21 },
22 {
23 name: "empty config",
24 config: Config{},
25 assertions: func(t *testing.T, original, copied Config) {
26 assert.Empty(t, copied, "Expected empty result for empty input")
27 assert.NotSame(t, &original, &copied, "Expected a new instance, not the same reference")
28 },
29 },
30 {
31 name: "simple config",
32 config: Config{
33 "key1": "value1",
34 "key2": int64(42),
35 "key3": true,
36 },
37 assertions: func(t *testing.T, original, copied Config) {
38 assert.Equal(t, original, copied, "Expected equal content")
39 assert.NotSame(t, &original, &copied, "Expected a new instance, not the same reference")
40
41 // Modify original to ensure deep copy
42 original["key1"] = "modified"
43 assert.NotEqual(t, original, copied, "Modifying original should not affect the copy")
44 },
45 },
46 {
47 name: "nested config",
48 config: Config{
49 "key1": "value1",
50 "key2": map[string]any{
51 "nested1": "nestedValue1",
52 "nested2": int64(99),
53 },
54 "key3": []any{int64(1), int64(2), int64(3)},
55 },
56 assertions: func(t *testing.T, original, copied Config) {
57 assert.Equal(t, original, copied, "Expected equal content")
58 assert.NotSame(t, &original, &copied, "Expected a new instance, not the same reference")
59
60 // Check nested map
61 originalNested := original["key2"].(map[string]any) // nolint: forcetypeassert
62 copiedNested := copied["key2"].(map[string]any) // nolint: forcetypeassert
63 assert.Equal(t, originalNested, copiedNested, "Expected equal nested content")
64 assert.NotSame(t, &originalNested, &copiedNested, "Expected a new instance for nested map")
65
66 // Modify original nested map

Callers

nothing calls this directly

Calls 2

RunMethod · 0.65
DeepCopyMethod · 0.65

Tested by

no test coverage detected