[lxc-devel] [lxd/master] Clear database state in the mock daemon after each lxdSuiteTest

freeekanayaka on Github lxc-bot at linuxcontainers.org
Tue May 16 07:59:00 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 703 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170516/1329042f/attachment.bin>
-------------- next part --------------
From 7c5c5ba9dca8297f7b213ce9a7a462084be98aef Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Tue, 16 May 2017 09:55:41 +0200
Subject: [PATCH] Clear database state in the mock daemon after each
 lxdSuiteTest

Currently unit tests based on lxdSuiteTest all share the same
database, meaning that state left by certain tests can influence other
tests (for instance it's not possible to create a pool with the same
name in two different tests).

This change resets the db state after each individual test run,
increasing isolation between tests.

Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
 lxd/main_test.go | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lxd/main_test.go b/lxd/main_test.go
index 9a1530a..382ce27 100644
--- a/lxd/main_test.go
+++ b/lxd/main_test.go
@@ -106,5 +106,15 @@ func (suite *lxdTestSuite) TearDownSuite() {
 }
 
 func (suite *lxdTestSuite) SetupTest() {
+	initializeDbObject(suite.d, shared.VarPath("lxd.db"))
+	daemonConfigInit(suite.d.db)
 	suite.Req = require.New(suite.T())
 }
+
+func (suite *lxdTestSuite) TearDownTest() {
+	suite.d.db.Close()
+	err := os.Remove(shared.VarPath("lxd.db"))
+	if err != nil {
+		os.Exit(1)
+	}
+}


More information about the lxc-devel mailing list