MCPcopy Create free account
hub / github.com/encodeous/nylon / TestDistribution

Function TestDistribution

e2e/distribution_test.go:19–179  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestDistribution(t *testing.T) {
20 t.Parallel()
21 h := NewHarness(t)
22 ctx := context.Background()
23
24 // 1. Setup Keys
25 privKey := state.GenerateKey()
26 pubKey := privKey.Pubkey()
27
28 // 2. Prepare Directories
29 runDir := h.SetupTestDir()
30
31 // 3. Prepare Initial Bundle (v1)
32 distCfg := &state.DistributionCfg{
33 Key: pubKey,
34 Repos: []string{"http://repo:80/bundle"},
35 }
36
37 nodeKey := state.GenerateKey()
38 nodeId := "node-1"
39 nodeIP := GetIP(h.Subnet, 10)
40
41 cfg1 := state.CentralCfg{
42 Timestamp: 1,
43 Dist: distCfg,
44 Routers: []state.RouterCfg{
45 SimpleRouter(nodeId, nodeKey.Pubkey(), "10.0.0.1", ""),
46 },
47 }
48
49 cfg1Bytes, err := yaml.Marshal(cfg1)
50 if err != nil {
51 t.Fatal(err)
52 }
53 bundle1Str, err := state.BundleConfig(string(cfg1Bytes), privKey)
54 if err != nil {
55 t.Fatal(err)
56 }
57
58 // Ensure cfg1 has the same timestamp as bundle1 to prevent immediate update
59 unbundled1, err := state.UnbundleConfig(bundle1Str, pubKey)
60 if err != nil {
61 t.Fatal(err)
62 }
63 cfg1.Timestamp = unbundled1.Timestamp
64
65 bundle1Path := filepath.Join(runDir, "bundle1")
66 if err := os.WriteFile(bundle1Path, []byte(bundle1Str), 0644); err != nil {
67 t.Fatal(err)
68 }
69
70 // 4. Start Repo Server
71 t.Log("Starting Repo Server...")
72 repoReq := testcontainers.ContainerRequest{
73 Image: "python:3-alpine",
74 Cmd: []string{"sh", "-c", "mkdir -p /data && cd /data && python3 -u -m http.server 80"},
75 ExposedPorts: []string{"80/tcp"},
76 Networks: []string{h.Network.Name},

Callers

nothing calls this directly

Calls 14

SetupTestDirMethod · 0.95
WriteConfigMethod · 0.95
StartNodesMethod · 0.95
WaitForLogMethod · 0.95
ExecMethod · 0.95
GenerateKeyFunction · 0.92
BundleConfigFunction · 0.92
UnbundleConfigFunction · 0.92
NewHarnessFunction · 0.85
GetIPFunction · 0.85
SimpleRouterFunction · 0.85
SimpleLocalFunction · 0.85

Tested by

no test coverage detected