mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-22 16:13:31 +01:00
1a8c03bef0
* created InitializePeer and ClosePeerConnection functions * feature: simplify peer stopping * chore: remove unused code * feature: basic management service implementation (#44) * feat: basic management service implementation [FAILING TESTS] * test: fix healthcheck test * test: #39 add peer registration endpoint test * feat: #39 add setup key handling * feat: #39 add peer management store persistence * refactor: extract config read/write to the utility package * refactor: move file contents copy to the utility package * refactor: use Accounts instead of Users in the Store * feature: add management server Docker file * refactor: introduce datadir instead of config * chore: use filepath.Join to concat filepaths instead of string concat * refactor: move stop channel to the root * refactor: move stop channel to the root * review: fix PR review notes Co-authored-by: braginini <hello@wiretrustee.com> * Handle read config file errors * feature: add letsencrypt support to the management service * fix: lint warnings * chore: change default datadir * refactor: set default flags in code not Dockerfile * chore: remove unused code * Added RemovePeer and centralized configureDevice code * remove peer from the wg interface when closing proxy * remove config file * add iface tests * fix tests, validate if file exists before removing it * removed unused functions UpdateListenPort and ConfigureWithKeyGen * Ensure we don't wait for timeout when closing * Rename ClosePeerConnection to RemovePeerConnection * Avoid returning on uapi Accept failures * Added engine tests * Remove extra add address code * Adding iface.Close * Ensure Close the interface and disable parallel test execution * check err var when listing interfaces * chore: add synchronisation to peer management * chore: add connection status to track peer connection * refactor: remove unused code Co-authored-by: braginini <hello@wiretrustee.com> Co-authored-by: Mikhail Bragin <bangvalo@gmail.com>
140 lines
2.8 KiB
Go
140 lines
2.8 KiB
Go
package cmd
|
|
|
|
import (
|
|
"bytes"
|
|
"github.com/kardianos/service"
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
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{
|
|
"init",
|
|
"--stunURLs",
|
|
"stun:stun.wiretrustee.com:3468",
|
|
"--signalAddr",
|
|
"signal.wiretrustee.com:10000",
|
|
"--turnURLs",
|
|
"foo:bar@turn:stun.wiretrustee.com:3468",
|
|
"--wgInterface",
|
|
"utun99",
|
|
"--wgLocalAddr",
|
|
"10.100.100.1/24",
|
|
"--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))
|
|
}
|
|
}
|