automatic-mouse-mover/pkg/mousemover/mouseMover_test.go

61 lines
1.4 KiB
Go
Raw Normal View History

2019-03-27 02:50:09 +00:00
package mousemover
import (
"testing"
2019-03-28 19:52:25 +00:00
"time"
2019-03-27 02:50:09 +00:00
"github.com/stretchr/testify/assert"
2019-03-28 19:52:25 +00:00
"github.com/stretchr/testify/suite"
2019-04-27 01:05:16 +00:00
"github.com/prashantgupta24/activity-tracker/pkg/tracker"
2019-03-27 02:50:09 +00:00
)
2019-03-28 19:52:25 +00:00
type TestMover struct {
suite.Suite
2019-04-27 01:05:16 +00:00
activityTracker *tracker.Instance
heartbeatCh chan *tracker.Heartbeat
2019-03-28 19:52:25 +00:00
}
func TestSuite(t *testing.T) {
suite.Run(t, new(TestMover))
}
2019-04-27 01:05:16 +00:00
//Run once before all tests
func (suite *TestMover) SetupSuite() {
heartbeatInterval := 60
workerInterval := 10
suite.activityTracker = &tracker.Instance{
HeartbeatInterval: heartbeatInterval,
WorkerInterval: workerInterval,
}
suite.heartbeatCh= make(chan *tracker.Heartbeat)
}
2019-03-28 19:52:25 +00:00
//Run once before each test
func (suite *TestMover) SetupTest() {
instance = nil
}
func (suite *TestMover) TestSingleton() {
t := suite.T()
2019-04-27 01:05:16 +00:00
2019-03-28 19:52:25 +00:00
mouseMover1 := GetInstance()
2019-04-27 01:05:16 +00:00
mouseMover1.run(suite.heartbeatCh, suite.activityTracker)
2019-03-28 19:52:25 +00:00
time.Sleep(time.Millisecond * 500)
mouseMover2 := GetInstance()
2019-04-27 01:05:16 +00:00
assert.True(t, mouseMover2.isRunning(), "instance should have started")
2019-03-28 19:52:25 +00:00
}
func (suite *TestMover) TestAppStartAndStop() {
t := suite.T()
mouseMover := GetInstance()
2019-04-27 01:05:16 +00:00
mouseMover.run(suite.heartbeatCh, suite.activityTracker)
2019-03-28 19:52:25 +00:00
time.Sleep(time.Millisecond * 500) //wait for app to start
assert.True(t, mouseMover.isRunning(), "app should have started")
mouseMover.Quit()
2019-04-27 01:05:16 +00:00
time.Sleep(time.Millisecond * 1000) //wait for app to stop
2019-03-28 19:52:25 +00:00
assert.False(t, mouseMover.isRunning(), "app should have stopped")
}