add wiretrustee LOGIN command (#90)

* feature: add wiretrustee LOGIN command

* chore: add management initial connection timeout

* test: add login cmd test

* test: validate generated config in login cmd

* test: add up command test

* chore: add timeout to signal client creation method

* test: close wireguard interface once test finished
This commit is contained in:
Mikhail Bragin
2021-08-18 13:35:42 +02:00
committed by GitHub
parent f7e51e7453
commit 1dfa99d07c
14 changed files with 557 additions and 244 deletions

View File

@ -1,129 +0,0 @@
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))
}
}