Myzel394 eb076dbf53
refactor(server): Improve Wireguard analyzer
Signed-off-by: Myzel394 <github.7a2op@simplelogin.co>
2025-03-16 00:23:54 +01:00

58 lines
1.0 KiB
Go

package analyzer
import (
"config-lsp/handlers/wireguard/parser"
"config-lsp/utils"
"testing"
)
func TestMultipleIntefaces(t *testing.T) {
content := utils.Dedent(`
[Interface]
PrivateKey = abc
[Interface]
PrivateKey = def
`)
p := parser.CreateWireguardParser()
p.ParseFromString(content)
diagnostics := Analyze(p)
if len(diagnostics) == 0 {
t.Errorf("Expected diagnostic errors, got %d", len(diagnostics))
}
}
func TestInvalidValue(t *testing.T) {
content := utils.Dedent(`
[Interface]
DNS = nope
`)
p := parser.CreateWireguardParser()
p.ParseFromString(content)
diagnostics := Analyze(p)
if len(diagnostics) == 0 {
t.Errorf("Expected diagnostic errors, got %d", len(diagnostics))
}
}
func TestDuplicateProperties(t *testing.T) {
content := utils.Dedent(`
[Interface]
PrivateKey = abc
DNS = 1.1.1.1
PrivateKey = def
`)
p := parser.CreateWireguardParser()
p.ParseFromString(content)
diagnostics := Analyze(p)
if len(diagnostics) == 0 {
t.Errorf("Expected diagnostic errors, got %d", len(diagnostics))
}
}