mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-23 00:23:36 +01:00
877ad97a96
* feature: replace RegisterPeer with Login method that does both - registration and login * test: add management login test * feature: add WiretrusteeConfig to the Login response to configure peer global config * feature: add client peer login support * fix: missing parts * chore: update go deps * feature: support Management Service gRPC endpoints [CLIENT] * feature: finalize client sync with management * fix: management store peer key lower case restore * fix: management returns peer ip without a mask * refactor: remove cmd pkg * fix: invalid tun interface name on mac * fix: timeout when calling management client * fix: tests and lint errors * fix: golang-test workflow * fix: client service tests * fix: iface build * feature: detect management scheme on startup * chore: better logs for management * fix: goreleaser * fix: lint errors * fix: signal TLS * fix: direct Wireguard connection * chore: verbose logging on direct connection
130 lines
2.6 KiB
Go
130 lines
2.6 KiB
Go
package cmd
|
|
|
|
import (
|
|
"bytes"
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/kardianos/service"
|
|
)
|
|
|
|
func Test_ServiceInstallCMD(t *testing.T) {
|
|
b := bytes.NewBufferString("")
|
|
rootCmd.SetOut(b)
|
|
rootCmd.SetErr(b)
|
|
rootCmd.SetArgs([]string{
|
|
"service",
|
|
"install",
|
|
"--config",
|
|
"/tmp/config.json",
|
|
})
|
|
err := rootCmd.Execute()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
out, err := ioutil.ReadAll(b)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
expectedMSG := "Wiretrustee service has been installed"
|
|
if string(out) != expectedMSG {
|
|
t.Fatalf("expected \"%s\" got \"%s\"", expectedMSG, string(out))
|
|
}
|
|
}
|
|
|
|
func Test_ServiceStartCMD(t *testing.T) {
|
|
b := bytes.NewBufferString("")
|
|
rootCmd.SetOut(b)
|
|
rootCmd.SetErr(b)
|
|
rootCmd.SetArgs([]string{"service", "start"})
|
|
err := rootCmd.Execute()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
out, err := ioutil.ReadAll(b)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
expectedMSG := "Wiretrustee service has been started"
|
|
if string(out) != expectedMSG {
|
|
t.Fatalf("expected \"%s\" got \"%s\"", expectedMSG, string(out))
|
|
}
|
|
}
|
|
|
|
func Test_ServiceRunCMD(t *testing.T) {
|
|
configFilePath := "/tmp/config.json"
|
|
if _, err := os.Stat(configFilePath); err == nil {
|
|
e := os.Remove(configFilePath)
|
|
if e != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
rootCmd.SetArgs([]string{
|
|
"--config",
|
|
configFilePath,
|
|
})
|
|
err := rootCmd.Execute()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
rootCmd.ResetFlags()
|
|
rootCmd.SetArgs([]string{"service", "start"})
|
|
err = rootCmd.Execute()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
s, err := newSVC(&program{}, newSVCConfig())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
status, err := s.Status()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if status != service.StatusRunning {
|
|
t.Fatalf("expected running status of \"%d\" got \"%d\"", service.StatusRunning, status)
|
|
}
|
|
}
|
|
|
|
/*func Test_ServiceStopCMD(t *testing.T) {
|
|
b := bytes.NewBufferString("")
|
|
rootCmd.SetOut(b)
|
|
rootCmd.SetErr(b)
|
|
rootCmd.SetArgs([]string{"service", "stop"})
|
|
err := rootCmd.Execute()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
out, err := ioutil.ReadAll(b)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
expectedMSG := "Wiretrustee service has been stopped"
|
|
if string(out) != expectedMSG {
|
|
t.Fatalf("expected \"%s\" got \"%s\"", expectedMSG, string(out))
|
|
}
|
|
}*/
|
|
|
|
func Test_ServiceUninstallCMD(t *testing.T) {
|
|
b := bytes.NewBufferString("")
|
|
rootCmd.SetOut(b)
|
|
rootCmd.SetErr(b)
|
|
rootCmd.SetArgs([]string{"service", "uninstall"})
|
|
err := rootCmd.Execute()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
out, err := ioutil.ReadAll(b)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
expectedMSG := "Wiretrustee has been uninstalled"
|
|
if string(out) != expectedMSG {
|
|
t.Fatalf("expected \"%s\" got \"%s\"", expectedMSG, string(out))
|
|
}
|
|
}
|