mirror of
https://github.com/netbirdio/netbird.git
synced 2025-01-23 14:28:51 +01:00
fcea3c99d4
* move setup-key to root command * up will check login and start service * update tests to reflect new UP capabilities * display client IP * removed unused argument * install service if not installed * update post-install and add pre remove script * improve log messages * handle service status failures and install service when needed * removing unused files * update documentation and description * add version command * update service lib version * using lib constant for not installed services * match version from goreleaser * fix: graceful shutdown * stop only if service is running * add logs initialization to service controller commands Co-authored-by: braginini <bangvalo@gmail.com>
83 lines
1.6 KiB
Go
83 lines
1.6 KiB
Go
package cmd
|
|
|
|
import (
|
|
"github.com/wiretrustee/wiretrustee/iface"
|
|
mgmt "github.com/wiretrustee/wiretrustee/management/server"
|
|
"github.com/wiretrustee/wiretrustee/util"
|
|
"net/url"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
var signalAddr string
|
|
|
|
func TestUp_Start(t *testing.T) {
|
|
config := &mgmt.Config{}
|
|
_, err := util.ReadJson("../testdata/management.json", config)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
testDir := t.TempDir()
|
|
config.Datadir = testDir
|
|
err = util.CopyFileContents("../testdata/store.json", filepath.Join(testDir, "store.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
_, signalLis := startSignal(t)
|
|
signalAddr = signalLis.Addr().String()
|
|
config.Signal.URI = signalAddr
|
|
|
|
_, mgmLis := startManagement(config, t)
|
|
mgmAddr = mgmLis.Addr().String()
|
|
|
|
}
|
|
|
|
func TestUp(t *testing.T) {
|
|
|
|
defer iface.Close()
|
|
|
|
tempDir := t.TempDir()
|
|
confPath := tempDir + "/config.json"
|
|
mgmtURL, err := url.Parse("http://" + mgmAddr)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
rootCmd.SetArgs([]string{
|
|
"up",
|
|
"--config",
|
|
confPath,
|
|
"--setup-key",
|
|
"A2C8E62B-38F5-4553-B31E-DD66C696CEBB",
|
|
"--management-url",
|
|
mgmtURL.String(),
|
|
"--log-file",
|
|
"console",
|
|
})
|
|
go func() {
|
|
err = rootCmd.Execute()
|
|
if err != nil {
|
|
t.Errorf("expected no error while running up command, got %v", err)
|
|
}
|
|
}()
|
|
|
|
exists := false
|
|
for start := time.Now(); time.Since(start) < 15*time.Second; {
|
|
e, err := iface.Exists(iface.WgInterfaceDefault)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
if *e {
|
|
exists = true
|
|
break
|
|
}
|
|
|
|
}
|
|
|
|
if !exists {
|
|
t.Errorf("expected wireguard interface %s to be created", iface.WgInterfaceDefault)
|
|
}
|
|
}
|