summaryrefslogtreecommitdiff
path: root/internal/control/bootstrap_test.go
blob: 70e5ccb92ea7d3b75c4feeb0472d5d4ebc96d7b9 (plain)
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
package control

import (
	"os"
	"path/filepath"
	"strings"
	"testing"
)

func TestRenderBootstrapScript(t *testing.T) {
	t.Parallel()

	script := RenderBootstrapPrepareScript()
	script += RenderBootstrapFinalizeScript(Node{
		ID:      "nl-01",
		Name:    "NL 01",
		Region:  "nl",
		Host:    "203.0.113.10",
		Domain:  "nl-01.example.com",
		Enabled: true,
		SSH: SSHConfig{
			User: "root",
			Port: 22,
			Auth: "key",
		},
	}, "20260401-123000", "/tmp/vpnem-node-nl-01.tar.gz")

	if !strings.Contains(script, "mkdir -p /opt/vpnem-node/releases") {
		t.Fatal("expected remote workdir creation")
	}
	if !strings.Contains(script, "vpnem-node release 20260401-123000 ready for nl-01") {
		t.Fatal("expected release finalize message")
	}
}

func TestSaveNodeState(t *testing.T) {
	t.Parallel()

	dir := t.TempDir()
	err := SaveNodeState(dir, NodeState{
		NodeID:          "nl-01",
		BootstrapStatus: "ready",
		Services: []ServiceStatus{
			{Type: "vless", Status: "configured", Port: 443},
		},
	})
	if err != nil {
		t.Fatalf("SaveNodeState error = %v", err)
	}

	data, err := os.ReadFile(filepath.Join(dir, "nl-01.json"))
	if err != nil {
		t.Fatalf("ReadFile error = %v", err)
	}
	if !strings.Contains(string(data), `"bootstrap_status": "ready"`) {
		t.Fatal("expected bootstrap_status in state file")
	}
}