forked from agntcy/dir
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirctl_network_sync_test.go
More file actions
148 lines (115 loc) · 5.17 KB
/
Copy pathdirctl_network_sync_test.go
File metadata and controls
148 lines (115 loc) · 5.17 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright AGNTCY Contributors (https://github.com/agntcy)
// SPDX-License-Identifier: Apache-2.0
package e2e
import (
_ "embed"
"strings"
"time"
"github.com/agntcy/dir/e2e/config"
"github.com/agntcy/dir/e2e/utils"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
)
// Using peer addresses from utils.constants
//go:embed testdata/agent_v2.json
var expectedAgentV2JSON []byte
var _ = ginkgo.Describe("Running dirctl end-to-end tests for sync commands", func() {
var cli *utils.CLI
ginkgo.BeforeEach(func() {
if cfg.DeploymentMode != config.DeploymentModeNetwork {
ginkgo.Skip("Skipping test, not in network mode")
}
// Initialize CLI helper
cli = utils.NewCLI()
})
var syncID string
ginkgo.Context("create command", func() {
ginkgo.It("should accept valid remote URL format", func() {
output := cli.Sync().Create("https://directory.example.com").OnServer(utils.Peer1Addr).ShouldSucceed()
gomega.Expect(output).To(gomega.ContainSubstring("Sync created with ID: "))
syncID = strings.TrimPrefix(output, "Sync created with ID: ")
})
})
ginkgo.Context("list command", func() {
ginkgo.It("should execute without arguments and return a list with the created sync", func() {
output := cli.Sync().List().OnServer(utils.Peer1Addr).ShouldSucceed()
gomega.Expect(output).To(gomega.ContainSubstring(syncID))
gomega.Expect(output).To(gomega.ContainSubstring("https://directory.example.com"))
gomega.Expect(output).To(gomega.ContainSubstring("PENDING"))
})
})
ginkgo.Context("status command", func() {
ginkgo.It("should accept a sync ID argument and return the sync status", func() {
output := cli.Sync().Status(syncID).OnServer(utils.Peer1Addr).ShouldSucceed()
gomega.Expect(output).To(gomega.ContainSubstring(syncID))
gomega.Expect(output).To(gomega.ContainSubstring("PENDING"))
})
})
ginkgo.Context("delete command", func() {
ginkgo.It("should accept a sync ID argument and delete the sync", func() {
// Command may fail due to network/auth issues, but argument parsing should work
_, err := cli.Sync().Delete(syncID).OnServer(utils.Peer1Addr).Execute()
if err != nil {
gomega.Expect(err.Error()).NotTo(gomega.ContainSubstring("required"))
}
})
ginkgo.It("should return deleted status", func() {
cli.Sync().List().OnServer(utils.Peer1Addr).ShouldContain("DELETE")
})
})
ginkgo.Context("sync functionality", func() {
var agentCID string
ginkgo.It("should push agent_v2.json to peer 1", func() {
agentCID = cli.Push("./testdata/agent_v2.json").OnServer(utils.Peer1Addr).ShouldSucceed()
// Validate that the returned CID correctly represents the pushed data
utils.LoadAndValidateCID(agentCID, "./testdata/agent_v2.json")
})
ginkgo.It("should fail to pull agent_v2.json from peer 2", func() {
_ = cli.Pull(agentCID).OnServer(utils.Peer2Addr).ShouldFail()
})
ginkgo.It("should create sync from peer 1 to peer 2", func() {
output := cli.Sync().Create(utils.Peer1InternalAddr).OnServer(utils.Peer2Addr).ShouldSucceed()
gomega.Expect(output).To(gomega.ContainSubstring("Sync created with ID: "))
syncID = strings.TrimPrefix(output, "Sync created with ID: ")
})
ginkgo.It("should list the sync", func() {
output := cli.Sync().List().OnServer(utils.Peer2Addr).ShouldSucceed()
gomega.Expect(output).To(gomega.ContainSubstring(syncID))
gomega.Expect(output).To(gomega.ContainSubstring(utils.Peer1InternalAddr))
gomega.Expect(output).To(gomega.ContainSubstring("PENDING"))
})
// Wait for sync to complete
ginkgo.It("should wait for sync to complete", func() {
// Poll sync status until it changes from PENDING to IN_PROGRESS
output := cli.Sync().Status(syncID).OnServer(utils.Peer2Addr).ShouldEventuallyContain("IN_PROGRESS", 120*time.Second)
ginkgo.GinkgoWriter.Printf("Current sync status: %s", output)
})
ginkgo.It("should succeed to pull agent_v2.json from peer 2 after sync", func() {
output := cli.Pull(agentCID).OnServer(utils.Peer2Addr).ShouldSucceed()
// Compare the output with the expected JSON
equal, err := utils.CompareJSONAgents([]byte(output), expectedAgentV2JSON)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(equal).To(gomega.BeTrue())
})
// Delete sync from peer 2
ginkgo.It("should delete sync from peer 2", func() {
cli.Sync().Delete(syncID).OnServer(utils.Peer2Addr).ShouldSucceed()
})
// Wait for sync to complete
ginkgo.It("should wait for delete to complete", func() {
// Poll sync status until it changes from DELETE_PENDING to DELETED
output := cli.Sync().Status(syncID).OnServer(utils.Peer2Addr).ShouldEventuallyContain("DELETED", 120*time.Second)
ginkgo.GinkgoWriter.Printf("Current sync status: %s", output)
})
// Push agent_v3.json to peer 1
ginkgo.It("should push agent_v3.json to peer 1", func() {
agentCID = cli.Push("./testdata/agent_v3.json").OnServer(utils.Peer1Addr).ShouldSucceed()
// Validate that the returned CID correctly represents the pushed data
utils.LoadAndValidateCID(agentCID, "./testdata/agent_v3.json")
})
// Pull agent_v3.json from peer 2
ginkgo.It("should fail to pull agent_v3.json from peer 2", func() {
_ = cli.Pull(agentCID).OnServer(utils.Peer2Addr).ShouldFail()
})
})
})