forked from agntcy/dir
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirctl_test.go
More file actions
112 lines (90 loc) · 3.39 KB
/
Copy pathdirctl_test.go
File metadata and controls
112 lines (90 loc) · 3.39 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
// Copyright AGNTCY Contributors (https://github.com/agntcy)
// SPDX-License-Identifier: Apache-2.0
package e2e
import (
_ "embed"
"os"
"path/filepath"
"time"
"github.com/agntcy/dir/e2e/config"
"github.com/agntcy/dir/e2e/utils"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
)
//go:embed testdata/agent.json
var expectedAgentJSON []byte
var _ = ginkgo.Describe("Running dirctl end-to-end tests using a local single node deployment", func() {
var cli *utils.CLI
ginkgo.BeforeEach(func() {
if cfg.DeploymentMode != config.DeploymentModeLocal {
ginkgo.Skip("Skipping test, not in local mode")
}
utils.ResetCLIState()
// Initialize CLI helper
cli = utils.NewCLI()
})
// Test params
var tempAgentCID string
tempAgentDir := os.Getenv("E2E_COMPILE_OUTPUT_DIR")
if tempAgentDir == "" {
tempAgentDir = os.TempDir()
}
tempAgentPath := filepath.Join(tempAgentDir, "agent.json")
// Setup: Copy test agent to temp location for push/pull tests
ginkgo.BeforeEach(func() {
err := os.MkdirAll(filepath.Dir(tempAgentPath), 0o755)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
err = os.WriteFile(tempAgentPath, expectedAgentJSON, 0o600)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
})
ginkgo.Context("agent push and pull", func() {
ginkgo.It("should successfully push an agent", func() {
tempAgentCID = cli.Push(tempAgentPath).ShouldSucceed()
// Validate that the returned CID correctly represents the pushed data
utils.LoadAndValidateCID(tempAgentCID, tempAgentPath)
})
ginkgo.It("should successfully pull an existing agent", func() {
cli.Pull(tempAgentCID).ShouldSucceed()
})
ginkgo.It("should push the same agent again and return the same digest", func() {
cli.Push(tempAgentPath).ShouldReturn(tempAgentCID)
})
ginkgo.It("should push two different agents and return different digests", func() {
// Modify the agent file to create a different agent
tempAgentPath2 := filepath.Join(tempAgentDir, "agent2.json")
err := os.WriteFile(tempAgentPath2, []byte(`{"name": "different-agent", "signature": {}}`), 0o600)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
// Push second agent
newAgentCID := cli.Push(tempAgentPath2).ShouldSucceed()
// Ensure the CIDs are different
gomega.Expect(newAgentCID).NotTo(gomega.Equal(tempAgentCID))
})
ginkgo.It("should pull a non-existent agent and return an error", func() {
_ = cli.Pull("non-existent-CID").ShouldFail()
})
})
ginkgo.Context("agent search", func() {
ginkgo.It("should search for records with every filter and return their CID", func() {
cli.Search().
WithLimit(10).
WithOffset(0).
WithQuery("name", "directory.agntcy.org/cisco/marketing-strategy").
WithQuery("version", "v1.0.0").
WithQuery("skill-id", "10201").
WithQuery("skill-name", "Natural Language Processing/Text Completion").
WithQuery("locator", "docker-image:https://ghcr.io/agntcy/marketing-strategy").
WithQuery("extension", "schema.oasf.agntcy.org/features/runtime/framework:v0.0.0").
ShouldReturn(tempAgentCID)
})
})
ginkgo.Context("agent delete", func() {
ginkgo.It("should successfully delete an agent", func() {
cli.Delete(tempAgentCID).ShouldSucceed()
})
ginkgo.It("should fail to pull a deleted agent", func() {
// Add a small delay to ensure delete operation is fully processed
time.Sleep(100 * time.Millisecond)
_ = cli.Pull(tempAgentCID).ShouldFail()
})
})
})