tests/q.rm.test.R

require(qrmarkdown)
require(testthat)
#debug(q.rm)

cleanlog <- function()
{
  if(file.exists('testlog'))
    system('rm -r testlog')
  q.wd('testlog')
  dir('testlog')
}



test_null_param <- function()
{
  cleanlog()
  # null parameters
  q.push(code="ls")

  q.rm()
  AFTER  <- dir(q.wd(), recursive = TRUE, full.names = TRUE)

  testthat::expect(length(AFTER) == 0 ,'test_null_param: must clear all immidate queue')

  # jid
  jid <- q.push(code="ls")
  q.rm(jid)
  res <-q.show()

  testthat::expect(res$inbox == 0 ,
                   'rm by jid test')

  # jid & type test
  ii <- q.push(code="ls")
  q.rm(ii,type='outbox')
  res <-q.show()

  testthat::expect(res$inbox == 1 ,
                   'rm by jid must exist')

  q.rm(ii,type='inbox')
  res <-q.show()

  testthat::expect(res$inbox == 0 ,
                   'rm by jid must not exist')

  ii <- q.schedule(code='ls()', wday = 'monday',hour = 1)

  testthat::expect_warning( q.rm(type='schedule') )

  res <-q.show()

  testthat::expect(res$schedule == 1 ,
                     'rm on schedule only allowed by force=TRUE')

  q.rm(type='schedule', force = TRUE)
  res <-q.show()

  testthat::expect(res$schedule == 0 ,
                   'rm on schedule only allowed by force=TRUE')

}

test_null_param()

test_type <- function()
{
  cleanlog()

  # type parameters test
  jid <- q.push(code="ls")

  # copy it some directory
  fpath <- gsub('inbox','output', jid)
  file.copy(jid,to=fpath)

  fpath <- gsub('inbox','schedule', jid)
  file.copy(jid,to=fpath)

  q.rm(type='output')
  res <- q.show()
  testthat::expect(res$outbox == 0  ,
                   'type=ouput failed')

  q.rm(type='inbox')
  res <- q.show()
  testthat::expect(res$inbox == 0  ,
                   'type=inbox failed')

  q.rm(type=NULL) # delete all except schedule
  res <- q.show()

  testthat::expect(res$schedule == 1  ,
                   'param force is failed')

  q.rm(force = TRUE)
  res <- q.show()

  testthat::expect(res$schedule == 0  ,
                   'param force did not clear job failed')

}

test_type()
okux/qrmarkdown documentation built on Dec. 22, 2021, 4:17 a.m.