From e2d7d9024a00c1762f5e4afd48ebd33abfe97bd5 Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Sun, 9 May 2021 15:46:31 -0400 Subject: [PATCH] fix test failures --- .github/workflows/test.yml | 3 ++- controllers/common_test.go | 20 +++++++++----------- controllers/userHttpController_test.go | 11 +++++++++++ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0ad80f34..4921d712 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,4 +19,5 @@ jobs: uses: actions/checkout@v2 - name: run tests run: | - go test ./... -v + go test ./test -v + go test ./controllers -v diff --git a/controllers/common_test.go b/controllers/common_test.go index cfd2628b..f88ce696 100644 --- a/controllers/common_test.go +++ b/controllers/common_test.go @@ -23,19 +23,17 @@ type NodeValidationUpdateTC struct { errorMessage string } -func createTestNode() models.Node { +func createTestNode(t *testing.T) models.Node { createnode := models.Node{PublicKey: "DM5qhLAE20PG9BbfBCger+Ac9D2NDOwCtY1rbYDLf34=", Endpoint: "10.0.0.1", MacAddress: "01:02:03:04:05:06", Password: "password", Network: "skynet"} node, err := CreateNode(createnode, "skynet") - if err != nil { - panic(err) - } + assert.Nil(t, err) return node } func TestCreateNode(t *testing.T) { deleteNet(t) - createnode := models.Node{PublicKey: "DM5qhLAE20PG9BbfBCger+Ac9D2NDOwCtY1rbYDLf34=", Endpoint: "10.0.0.1", MacAddress: "01:02:03:04:05:06", Password: "password", Network: "skynet"} createNet() + createnode := models.Node{PublicKey: "DM5qhLAE20PG9BbfBCger+Ac9D2NDOwCtY1rbYDLf34=", Endpoint: "10.0.0.1", MacAddress: "01:02:03:04:05:06", Password: "password", Network: "skynet"} err := ValidateNodeCreate("skynet", createnode) assert.Nil(t, err) node, err := CreateNode(createnode, "skynet") @@ -51,7 +49,7 @@ func TestCreateNode(t *testing.T) { func TestDeleteNode(t *testing.T) { deleteNet(t) createNet() - node := createTestNode() + node := createTestNode(t) t.Run("NodeExists", func(t *testing.T) { deleted, err := DeleteNode(node.MacAddress, node.Network) assert.Nil(t, err) @@ -66,7 +64,7 @@ func TestDeleteNode(t *testing.T) { func TestGetNode(t *testing.T) { deleteNet(t) createNet() - node := createTestNode() + node := createTestNode(t) t.Run("NodeExists", func(t *testing.T) { response, err := GetNode(node.MacAddress, node.Network) assert.Nil(t, err) @@ -102,7 +100,7 @@ func TestGetNode(t *testing.T) { func TestGetPeerList(t *testing.T) { deleteNet(t) createNet() - _ = createTestNode() + _ = createTestNode(t) //createnode := models.Node{PublicKey: "RM5qhLAE20PG9BbfBCger+Ac9D2NDOwCtY1rbYDLf34=", Endpoint: "10.0.0.2", MacAddress: "02:02:03:04:05:06", Password: "password", Network: "skynet"} //_, _ = CreateNode(createnode, "skynet") t.Run("PeerExist", func(t *testing.T) { @@ -122,7 +120,7 @@ func TestGetPeerList(t *testing.T) { func TestNodeCheckIn(t *testing.T) { deleteNet(t) createNet() - node := createTestNode() + node := createTestNode(t) time.Sleep(time.Second * 1) expectedResponse := models.CheckInResponse{false, false, false, false, false, "", false} t.Run("BadNet", func(t *testing.T) { @@ -225,7 +223,7 @@ func TestSetNetworkNodesLastModified(t *testing.T) { func TestTimestampNode(t *testing.T) { deleteNet(t) createNet() - node := createTestNode() + node := createTestNode(t) time.Sleep(time.Second * 1) before, err := GetNode(node.MacAddress, node.Network) assert.Nil(t, err) @@ -261,7 +259,7 @@ func TestTimestampNode(t *testing.T) { func TestUpdateNode(t *testing.T) { deleteNet(t) createNet() - node := createTestNode() + node := createTestNode(t) var update models.NodeUpdate update.MacAddress = "01:02:03:04:05:06" update.Name = "helloworld" diff --git a/controllers/userHttpController_test.go b/controllers/userHttpController_test.go index 5345dee9..f8a68545 100644 --- a/controllers/userHttpController_test.go +++ b/controllers/userHttpController_test.go @@ -25,6 +25,17 @@ func TestMain(m *testing.M) { if err != nil { panic("could not create config store") } + //drop network, nodes, and user collections + var collections = []string{"networks", "nodes", "users", "dns"} + for _, table := range collections { + collection := mongoconn.Client.Database("netmaker").Collection(table) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + err := collection.Drop(ctx) + if err != nil { + panic("could not drop collection") + } + } os.Exit(m.Run()) }