mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 08:47:35 +08:00
fix tests
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/gravitl/netmaker/database"
|
||||
"github.com/gravitl/netmaker/logger"
|
||||
"github.com/gravitl/netmaker/logic"
|
||||
"github.com/gravitl/netmaker/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -21,8 +22,27 @@ type NetworkValidationTestCase struct {
|
||||
|
||||
var netHost models.Host
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
database.InitializeDatabase()
|
||||
defer database.CloseDB()
|
||||
logic.CreateAdmin(&models.User{
|
||||
UserName: "admin",
|
||||
Password: "password",
|
||||
IsAdmin: true,
|
||||
Networks: []string{},
|
||||
Groups: []string{},
|
||||
})
|
||||
peerUpdate := make(chan *models.Node)
|
||||
go logic.ManageZombies(context.Background(), peerUpdate)
|
||||
go func() {
|
||||
for update := range peerUpdate {
|
||||
//do nothing
|
||||
logger.Log(3, "received node update", update.Action)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func TestCreateNetwork(t *testing.T) {
|
||||
initialize()
|
||||
deleteAllNetworks()
|
||||
|
||||
var network models.Network
|
||||
@@ -35,7 +55,6 @@ func TestCreateNetwork(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
func TestGetNetwork(t *testing.T) {
|
||||
initialize()
|
||||
createNet()
|
||||
|
||||
t.Run("GetExistingNetwork", func(t *testing.T) {
|
||||
@@ -51,7 +70,6 @@ func TestGetNetwork(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteNetwork(t *testing.T) {
|
||||
initialize()
|
||||
createNet()
|
||||
//create nodes
|
||||
t.Run("NetworkwithNodes", func(t *testing.T) {
|
||||
@@ -67,7 +85,6 @@ func TestDeleteNetwork(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateKey(t *testing.T) {
|
||||
initialize()
|
||||
createNet()
|
||||
keys, _ := logic.GetKeys("skynet")
|
||||
for _, key := range keys {
|
||||
@@ -139,7 +156,6 @@ func TestCreateKey(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetKeys(t *testing.T) {
|
||||
initialize()
|
||||
deleteAllNetworks()
|
||||
createNet()
|
||||
network, err := logic.GetNetwork("skynet")
|
||||
@@ -162,7 +178,6 @@ func TestGetKeys(t *testing.T) {
|
||||
})
|
||||
}
|
||||
func TestDeleteKey(t *testing.T) {
|
||||
initialize()
|
||||
createNet()
|
||||
network, err := logic.GetNetwork("skynet")
|
||||
assert.Nil(t, err)
|
||||
@@ -184,7 +199,6 @@ func TestDeleteKey(t *testing.T) {
|
||||
func TestSecurityCheck(t *testing.T) {
|
||||
//these seem to work but not sure it the tests are really testing the functionality
|
||||
|
||||
initialize()
|
||||
os.Setenv("MASTER_KEY", "secretkey")
|
||||
t.Run("NoNetwork", func(t *testing.T) {
|
||||
networks, username, err := logic.UserPermissions(false, "", "Bearer secretkey")
|
||||
@@ -215,7 +229,6 @@ func TestValidateNetwork(t *testing.T) {
|
||||
//t.Skip()
|
||||
//This functions is not called by anyone
|
||||
//it panics as validation function 'display_name_valid' is not defined
|
||||
initialize()
|
||||
//yes := true
|
||||
//no := false
|
||||
//deleteNet(t)
|
||||
@@ -292,7 +305,6 @@ func TestValidateNetwork(t *testing.T) {
|
||||
func TestIpv6Network(t *testing.T) {
|
||||
//these seem to work but not sure it the tests are really testing the functionality
|
||||
|
||||
initialize()
|
||||
os.Setenv("MASTER_KEY", "secretkey")
|
||||
deleteAllNetworks()
|
||||
createNet()
|
||||
@@ -319,22 +331,6 @@ func deleteAllNetworks() {
|
||||
}
|
||||
}
|
||||
|
||||
func initialize() {
|
||||
database.InitializeDatabase()
|
||||
createAdminUser()
|
||||
go logic.ManageZombies(context.Background())
|
||||
}
|
||||
|
||||
func createAdminUser() {
|
||||
logic.CreateAdmin(&models.User{
|
||||
UserName: "admin",
|
||||
Password: "password",
|
||||
IsAdmin: true,
|
||||
Networks: []string{},
|
||||
Groups: []string{},
|
||||
})
|
||||
}
|
||||
|
||||
func createNet() {
|
||||
var network models.Network
|
||||
network.NetID = "skynet"
|
||||
|
Reference in New Issue
Block a user