forked from hashicorp/consul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_entry_exports_test.go
106 lines (88 loc) · 2.47 KB
/
config_entry_exports_test.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package api
import (
"testing"
"github.com/hashicorp/consul/sdk/testutil"
"github.com/stretchr/testify/require"
)
func TestAPI_ConfigEntries_ExportedServices(t *testing.T) {
t.Parallel()
c, s := makeClient(t)
defer s.Stop()
entries := c.ConfigEntries()
testutil.RunStep(t, "set and get", func(t *testing.T) {
exports := &ExportedServicesConfigEntry{
Name: PartitionDefaultName,
Partition: defaultPartition,
Meta: map[string]string{
"gir": "zim",
},
}
_, wm, err := entries.Set(exports, nil)
require.NoError(t, err)
require.NotNil(t, wm)
require.NotEqual(t, 0, wm.RequestTime)
entry, qm, err := entries.Get(ExportedServices, PartitionDefaultName, nil)
require.NoError(t, err)
require.NotNil(t, qm)
require.NotEqual(t, 0, qm.RequestTime)
result, ok := entry.(*ExportedServicesConfigEntry)
require.True(t, ok)
// ignore indexes
result.CreateIndex = 0
result.ModifyIndex = 0
require.Equal(t, exports, result)
})
testutil.RunStep(t, "update", func(t *testing.T) {
updated := &ExportedServicesConfigEntry{
Name: PartitionDefaultName,
Services: []ExportedService{
{
Name: "db",
Namespace: defaultNamespace,
Consumers: []ServiceConsumer{
{
Peer: "alpha",
},
},
},
},
Meta: map[string]string{
"foo": "bar",
"gir": "zim",
},
Partition: defaultPartition,
}
_, wm, err := entries.Set(updated, nil)
require.NoError(t, err)
require.NotNil(t, wm)
require.NotEqual(t, 0, wm.RequestTime)
entry, qm, err := entries.Get(ExportedServices, PartitionDefaultName, nil)
require.NoError(t, err)
require.NotNil(t, qm)
require.NotEqual(t, 0, qm.RequestTime)
result, ok := entry.(*ExportedServicesConfigEntry)
require.True(t, ok)
// ignore indexes
result.CreateIndex = 0
result.ModifyIndex = 0
require.Equal(t, updated, result)
})
testutil.RunStep(t, "list", func(t *testing.T) {
entries, qm, err := entries.List(ExportedServices, nil)
require.NoError(t, err)
require.NotNil(t, qm)
require.NotEqual(t, 0, qm.RequestTime)
require.Len(t, entries, 1)
})
testutil.RunStep(t, "delete", func(t *testing.T) {
wm, err := entries.Delete(ExportedServices, PartitionDefaultName, nil)
require.NoError(t, err)
require.NotNil(t, wm)
require.NotEqual(t, 0, wm.RequestTime)
// verify deletion
_, _, err = entries.Get(MeshConfig, PartitionDefaultName, nil)
require.Error(t, err)
})
}