diff options
| author | sergei <sergei@em-sysadmin.xyz> | 2026-04-14 06:23:55 +0400 |
|---|---|---|
| committer | sergei <sergei@em-sysadmin.xyz> | 2026-04-14 06:23:55 +0400 |
| commit | 3d51aa455006903345f554a2dd90034993796114 (patch) | |
| tree | 62a7be2faf047f5eb7886feebc3b815556f03d7f /internal/control/dns_test.go | |
| download | vpnem-main.tar.gz vpnem-main.tar.bz2 vpnem-main.zip | |
- Multi-protocol VPS nodes (VLESS-REALITY + Hysteria2 + SOCKS5)
- Smart load balancing via recommendation API
- Windows/Linux client (Go + Wails + sing-box)
- Server API with RealIP detection and connection tracking
- Auto-deployment via vpnui control plane
- Silent Windows installer with UAC elevation
- Load-based server recommendation (no sticky sessions)
- Best Server one-click connection workflow
Diffstat (limited to 'internal/control/dns_test.go')
| -rw-r--r-- | internal/control/dns_test.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/internal/control/dns_test.go b/internal/control/dns_test.go new file mode 100644 index 0000000..cf44639 --- /dev/null +++ b/internal/control/dns_test.go @@ -0,0 +1,58 @@ +package control + +import ( + "context" + "encoding/json" + "io" + "net/http" + "strings" + "testing" +) + +func TestPorkbunEnsureRandomARecord(t *testing.T) { + t.Parallel() + + retrieveCalls := 0 + client := &http.Client{Transport: roundTripFunc(func(r *http.Request) (*http.Response, error) { + recorder := map[string]any{} + switch { + case strings.Contains(r.URL.Path, "/dns/retrieveByNameType/"): + retrieveCalls++ + recorder = map[string]any{ + "status": "SUCCESS", + "records": []map[string]any{}, + } + case strings.Contains(r.URL.Path, "/dns/create/"): + recorder = map[string]any{ + "status": "SUCCESS", + "id": "123", + } + default: + t.Fatalf("unexpected path %s", r.URL.Path) + } + body, _ := json.Marshal(recorder) + return &http.Response{ + StatusCode: http.StatusOK, + Header: make(http.Header), + Body: io.NopCloser(strings.NewReader(string(body))), + }, nil + })} + + clientAPI := PorkbunClient{APIKey: "a", SecretAPIKey: "b", HTTPClient: client} + name, err := clientAPI.EnsureRandomARecord(context.Background(), "em-sysadmin.xyz", "vpn", "203.0.113.10", 600) + if err != nil { + t.Fatalf("EnsureRandomARecord error = %v", err) + } + if !strings.HasSuffix(name, ".em-sysadmin.xyz") { + t.Fatalf("expected fqdn suffix, got %q", name) + } + if retrieveCalls == 0 { + t.Fatal("expected retrieve call") + } +} + +type roundTripFunc func(*http.Request) (*http.Response, error) + +func (f roundTripFunc) RoundTrip(r *http.Request) (*http.Response, error) { + return f(r) +} |
