forked from agntcy/dir
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirctl_network_deploy_test.go
More file actions
193 lines (155 loc) · 5.21 KB
/
Copy pathdirctl_network_deploy_test.go
File metadata and controls
193 lines (155 loc) · 5.21 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// Copyright AGNTCY Contributors (https://github.com/agntcy)
// SPDX-License-Identifier: Apache-2.0
package e2e
import (
"bytes"
"strings"
clicmd "github.com/agntcy/dir/cli/cmd"
"github.com/agntcy/dir/e2e/config"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/opencontainers/go-digest"
)
const (
Peer1Addr = "0.0.0.0:8890"
Peer2Addr = "0.0.0.0:8891"
Peer3Addr = "0.0.0.0:8892"
)
var peerAddrs = []string{Peer1Addr, Peer2Addr, Peer3Addr}
var _ = ginkgo.Describe("Running dirctl end-to-end tests using a network multi peer deployment", func() {
ginkgo.BeforeEach(func() {
if cfg.DeploymentMode != config.DeploymentModeNetwork {
ginkgo.Skip("Skipping test, not in network mode")
}
})
// Test params
var tempAgentDigest string
ginkgo.It("should push an agent to peer 1", func() {
var outputBuffer bytes.Buffer
pushCmd := clicmd.RootCmd
pushCmd.SetOut(&outputBuffer)
pushCmd.SetArgs([]string{
"push",
"./testdata/agent.json",
"--server-addr",
Peer1Addr,
})
err := pushCmd.Execute()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
tempAgentDigest = outputBuffer.String()
// Ensure the digest is valid
_, err = digest.Parse(tempAgentDigest)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
})
ginkgo.It("should pull the agent from peer 1", func() {
var outputBuffer bytes.Buffer
pullCmd := clicmd.RootCmd
pullCmd.SetOut(&outputBuffer)
pullCmd.SetArgs([]string{
"pull",
tempAgentDigest,
"--server-addr",
Peer1Addr,
})
err := pullCmd.Execute()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
})
ginkgo.It("should fail to pull the agent from peer 2", func() {
var outputBuffer bytes.Buffer
pullCmd := clicmd.RootCmd
pullCmd.SetOut(&outputBuffer)
pullCmd.SetArgs([]string{
"pull",
tempAgentDigest,
"--server-addr",
Peer2Addr,
})
err := pullCmd.Execute()
gomega.Expect(err).To(gomega.HaveOccurred())
})
ginkgo.It("should publish an agent to the network on peer 1", func() {
var outputBuffer bytes.Buffer
publishCmd := clicmd.RootCmd
publishCmd.SetOut(&outputBuffer)
publishCmd.SetArgs([]string{
"publish",
tempAgentDigest,
"--server-addr",
Peer1Addr,
"--network",
})
err := publishCmd.Execute()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
})
ginkgo.It("should fail publish an agent to the network on peer 2 that does not store the agent", func() {
var outputBuffer bytes.Buffer
publishCmd := clicmd.RootCmd
publishCmd.SetOut(&outputBuffer)
publishCmd.SetArgs([]string{
"publish",
tempAgentDigest,
"--server-addr",
Peer2Addr,
"--network",
})
err := publishCmd.Execute()
gomega.Expect(err).To(gomega.HaveOccurred())
})
ginkgo.It("should list by digest on all peers", func() {
for _, addr := range peerAddrs {
var outputBuffer bytes.Buffer
listCmd := clicmd.RootCmd
listCmd.SetOut(&outputBuffer)
listCmd.SetArgs([]string{
"list",
"--digest",
tempAgentDigest,
"--server-addr",
addr,
})
err := listCmd.Execute()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
// Validate the output contains the expected digest
output := strings.TrimSpace(outputBuffer.String()) // Trim trailing whitespace and newlines
// Extract the Peer ID/hash from the output
peerIDStart := strings.Index(output, "Peer ") + len("Peer ")
peerIDEnd := strings.Index(output[peerIDStart:], "\n") + peerIDStart
gomega.Expect(peerIDStart).NotTo(gomega.Equal(-1), "Peer ID not found in output")
peerID := output[peerIDStart:peerIDEnd]
// Build the expected output string
expectedOutput := "Peer " + peerID + "\n" +
" Digest: " + tempAgentDigest + "\n" +
" Labels: /skills/Natural Language Processing/Text Completion, /skills/Natural Language Processing/Problem Solving, /domains/research, /features/runtime/framework, /features/runtime/language"
// Validate the output matches the expected format
gomega.Expect(output).To(gomega.Equal(expectedOutput))
}
})
ginkgo.It("should list by skill on all peers", func() {
for _, addr := range peerAddrs {
var outputBuffer bytes.Buffer
listCmd := clicmd.RootCmd
listCmd.SetOut(&outputBuffer)
listCmd.SetArgs([]string{
"list",
"\"/skills/Natural Language Processing\"",
"--server-addr",
addr,
})
err := listCmd.Execute()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
// Validate the output contains the expected digest
output := strings.TrimSpace(outputBuffer.String()) // Trim trailing whitespace and newlines
// Extract the Peer ID/hash from the output
peerIDStart := strings.Index(output, "Peer ") + len("Peer ")
peerIDEnd := strings.Index(output[peerIDStart:], "\n") + peerIDStart
gomega.Expect(peerIDStart).NotTo(gomega.Equal(-1), "Peer ID not found in output")
peerID := output[peerIDStart:peerIDEnd]
// Build the expected output string
expectedOutput := "Peer " + peerID + "\n" +
" Digest: " + tempAgentDigest + "\n" +
" Labels: /skills/Natural Language Processing/Text Completion, /skills/Natural Language Processing/Problem Solving, /domains/research, /features/runtime/framework, /features/runtime/language"
// Validate the output matches the expected format
gomega.Expect(output).To(gomega.Equal(expectedOutput))
}
})
})