mirror of
				https://github.com/gravitl/netmaker.git
				synced 2025-10-31 12:16:29 +08:00 
			
		
		
		
	| @@ -4,6 +4,7 @@ import ( | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"net" | ||||
| 	"os" | ||||
| 	"testing" | ||||
|  | ||||
| 	"github.com/google/uuid" | ||||
| @@ -12,7 +13,7 @@ import ( | ||||
| 	"github.com/matryer/is" | ||||
| ) | ||||
|  | ||||
| func TestCheckPorts(t *testing.T) { | ||||
| func TestMain(m *testing.M) { | ||||
| 	database.InitializeDatabase() | ||||
| 	defer database.CloseDB() | ||||
| 	peerUpdate := make(chan *models.Node) | ||||
| @@ -24,6 +25,10 @@ func TestCheckPorts(t *testing.T) { | ||||
| 		} | ||||
| 	}() | ||||
|  | ||||
| 	os.Exit(m.Run()) | ||||
| } | ||||
|  | ||||
| func TestCheckPorts(t *testing.T) { | ||||
| 	h := models.Host{ | ||||
| 		ID:              uuid.New(), | ||||
| 		EndpointIP:      net.ParseIP("192.168.1.1"), | ||||
| @@ -36,10 +41,16 @@ func TestCheckPorts(t *testing.T) { | ||||
| 		ListenPort:      51830, | ||||
| 		ProxyListenPort: 51730, | ||||
| 	} | ||||
| 	//not sure why this initialization is required but without it | ||||
| 	// RemoveHost returns database is closed | ||||
| 	database.InitializeDatabase() | ||||
| 	RemoveHost(&h) | ||||
| 	CreateHost(&h) | ||||
| 	t.Run("no change", func(t *testing.T) { | ||||
| 		is := is.New(t) | ||||
| 		CheckHostPorts(&testHost) | ||||
| 		t.Log(testHost.ListenPort, testHost.ProxyListenPort) | ||||
| 		t.Log(h.ListenPort, h.ProxyListenPort) | ||||
| 		is.Equal(testHost.ListenPort, 51830) | ||||
| 		is.Equal(testHost.ProxyListenPort, 51730) | ||||
| 	}) | ||||
| @@ -47,6 +58,8 @@ func TestCheckPorts(t *testing.T) { | ||||
| 		is := is.New(t) | ||||
| 		testHost.ListenPort = 51821 | ||||
| 		CheckHostPorts(&testHost) | ||||
| 		t.Log(testHost.ListenPort, testHost.ProxyListenPort) | ||||
| 		t.Log(h.ListenPort, h.ProxyListenPort) | ||||
| 		is.Equal(testHost.ListenPort, 51822) | ||||
| 		is.Equal(testHost.ProxyListenPort, 51730) | ||||
| 	}) | ||||
| @@ -54,6 +67,8 @@ func TestCheckPorts(t *testing.T) { | ||||
| 		is := is.New(t) | ||||
| 		testHost.ProxyListenPort = 65535 | ||||
| 		CheckHostPorts(&testHost) | ||||
| 		t.Log(testHost.ListenPort, testHost.ProxyListenPort) | ||||
| 		t.Log(h.ListenPort, h.ProxyListenPort) | ||||
| 		is.Equal(testHost.ListenPort, 51822) | ||||
| 		is.Equal(testHost.ProxyListenPort, minPort) | ||||
| 	}) | ||||
| @@ -61,6 +76,8 @@ func TestCheckPorts(t *testing.T) { | ||||
| 		is := is.New(t) | ||||
| 		testHost.ListenPort = maxPort | ||||
| 		CheckHostPorts(&testHost) | ||||
| 		t.Log(testHost.ListenPort, testHost.ProxyListenPort) | ||||
| 		t.Log(h.ListenPort, h.ProxyListenPort) | ||||
| 		is.Equal(testHost.ListenPort, minPort) | ||||
| 		is.Equal(testHost.ProxyListenPort, minPort+1) | ||||
| 	}) | ||||
| @@ -68,6 +85,8 @@ func TestCheckPorts(t *testing.T) { | ||||
| 		is := is.New(t) | ||||
| 		testHost.ProxyListenPort = 51821 | ||||
| 		CheckHostPorts(&testHost) | ||||
| 		t.Log(testHost.ListenPort, testHost.ProxyListenPort) | ||||
| 		t.Log(h.ListenPort, h.ProxyListenPort) | ||||
| 		is.Equal(testHost.ListenPort, minPort) | ||||
| 		is.Equal(testHost.ProxyListenPort, 51822) | ||||
| 	}) | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package pro | ||||
|  | ||||
| import ( | ||||
| 	"os" | ||||
| 	"testing" | ||||
|  | ||||
| 	"github.com/google/uuid" | ||||
| @@ -13,6 +14,7 @@ import ( | ||||
| func TestMain(m *testing.M) { | ||||
| 	database.InitializeDatabase() | ||||
| 	defer database.CloseDB() | ||||
| 	os.Exit(m.Run()) | ||||
| } | ||||
|  | ||||
| func TestNetworkUserLogic(t *testing.T) { | ||||
| @@ -33,7 +35,7 @@ func TestNetworkUserLogic(t *testing.T) { | ||||
| 	} | ||||
|  | ||||
| 	clients := []models.ExtClient{ | ||||
| 		models.ExtClient{ | ||||
| 		{ | ||||
| 			ClientID: "coolclient", | ||||
| 		}, | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 dcarns
					dcarns