| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 | package logicimport (	"context"	"fmt"	"github.com/gravitl/netmaker/db"	"github.com/gravitl/netmaker/schema"	"net"	"os"	"testing"	"github.com/google/uuid"	"github.com/gravitl/netmaker/database"	"github.com/gravitl/netmaker/models"	"github.com/matryer/is")func TestMain(m *testing.M) {	db.InitializeDB(schema.ListModels()...)	defer db.CloseDB()	database.InitializeDatabase()	defer database.CloseDB()	peerUpdate := make(chan *models.Node)	go ManageZombies(context.Background(), peerUpdate)	go func() {		for y := range peerUpdate {			fmt.Printf("Pointless %v\n", y)			//do nothing		}	}()	os.Exit(m.Run())}func TestCheckPorts(t *testing.T) {	h := models.Host{		ID:         uuid.New(),		EndpointIP: net.ParseIP("192.168.1.1"),		ListenPort: 51821,	}	testHost := models.Host{		ID:         uuid.New(),		EndpointIP: net.ParseIP("192.168.1.1"),		ListenPort: 51830,	}	//not sure why this initialization is required but without it	// RemoveHost returns database is closed	db.InitializeDB(schema.ListModels()...)	defer db.CloseDB()	database.InitializeDatabase()	RemoveHost(&h, true)	CreateHost(&h)	t.Run("no change", func(t *testing.T) {		is := is.New(t)		CheckHostPorts(&testHost)		t.Log(testHost.ListenPort)		t.Log(h.ListenPort)		is.Equal(testHost.ListenPort, 51830)	})	t.Run("same listen port", func(t *testing.T) {		is := is.New(t)		testHost.ListenPort = 51821		CheckHostPorts(&testHost)		t.Log(testHost.ListenPort)		t.Log(h.ListenPort)		is.Equal(testHost.ListenPort, 51822)	})}
 |