mirror of
https://github.com/prashantgupta24/automatic-mouse-mover.git
synced 2024-12-22 16:34:11 +00:00
adding tests
This commit is contained in:
parent
118bce49e0
commit
19e0318359
@ -46,10 +46,8 @@ func (m *MouseMover) run(heartbeatCh chan *tracker.Heartbeat, activityTracker *t
|
||||
}
|
||||
state.updateRunningStatus(true)
|
||||
|
||||
logger := getLogger(m, false) //set writeToFile=true only for debugging
|
||||
logger := getLogger(m, false, logFileName) //set writeToFile=true only for debugging
|
||||
movePixel := 10
|
||||
// var lastMoved time.Time
|
||||
// didNotMoveTimes := 0
|
||||
for {
|
||||
select {
|
||||
case heartbeat := <-heartbeatCh:
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func getLogger(m *MouseMover, doWriteToFile bool) *log.Logger {
|
||||
func getLogger(m *MouseMover, doWriteToFile bool, filename string) *log.Logger {
|
||||
logger := log.New()
|
||||
logger.Formatter = &logrus.TextFormatter{
|
||||
FullTimestamp: true,
|
||||
@ -26,7 +26,7 @@ func getLogger(m *MouseMover, doWriteToFile bool) *log.Logger {
|
||||
}
|
||||
}
|
||||
|
||||
logFile, err := os.OpenFile(logDir+"/"+logFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
||||
logFile, err := os.OpenFile(logDir+"/"+filename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
log.Fatalf("error opening file: %v", err)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package mousemover
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -57,11 +58,29 @@ func (suite *TestMover) TestSingleton() {
|
||||
assert.True(t, mouseMover2.state.isRunning(), "instance should have started")
|
||||
}
|
||||
|
||||
func (suite *TestMover) TestLogFile() {
|
||||
t := suite.T()
|
||||
mouseMover := GetInstance()
|
||||
logFileName := "test1"
|
||||
|
||||
getLogger(mouseMover, true, logFileName)
|
||||
|
||||
filePath := logDir + "/" + logFileName
|
||||
assert.FileExists(t, filePath, "log file should exist")
|
||||
os.RemoveAll(filePath)
|
||||
}
|
||||
func (suite *TestMover) TestSystemSleepAndWake() {
|
||||
t := suite.T()
|
||||
mouseMover := GetInstance()
|
||||
|
||||
state := &state{
|
||||
override: &override{
|
||||
valueToReturn: true,
|
||||
},
|
||||
}
|
||||
mouseMover.state = state
|
||||
heartbeatCh := make(chan *tracker.Heartbeat)
|
||||
|
||||
mouseMover.run(heartbeatCh, suite.activityTracker)
|
||||
time.Sleep(time.Millisecond * 500) //wait for app to start
|
||||
assert.True(t, mouseMover.state.isRunning(), "instance should have started")
|
||||
@ -79,6 +98,15 @@ func (suite *TestMover) TestSystemSleepAndWake() {
|
||||
time.Sleep(time.Millisecond * 500) //wait for it to be registered
|
||||
assert.True(t, mouseMover.state.isSystemSleeping(), "machine should be sleeping now")
|
||||
|
||||
//assert app is sleeping
|
||||
heartbeatCh <- &tracker.Heartbeat{
|
||||
WasAnyActivity: false,
|
||||
}
|
||||
|
||||
time.Sleep(time.Millisecond * 500) //wait for it to be registered
|
||||
assert.True(t, time.Time.IsZero(state.getLastMouseMovedTime()), "should be default but is ", state.getLastMouseMovedTime())
|
||||
assert.Equal(t, state.getDidNotMoveCount(), 0, "should be 0")
|
||||
|
||||
//fake a machine-wake activity
|
||||
machineWakeActivityMap := make(map[activity.Type][]time.Time)
|
||||
var wakeTimeArray []time.Time
|
||||
|
Loading…
Reference in New Issue
Block a user