Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

145 righe
4.2 KiB

  1. #!/usr/bin/env bats
  2. # needs:
  3. # bash-bats
  4. #
  5. # run with:
  6. # bats --tap test_mw.bats
  7. run_only_test() {
  8. if [ "$BATS_TEST_NUMBER" -ne "$1" ]; then
  9. skip
  10. fi
  11. }
  12. # these are called for every test
  13. setup()
  14. {
  15. #run_only_test 6
  16. rm -rf mwtesttmp
  17. XDG_CONFIG_HOME=mwtesttmp/config \
  18. MAILDIR=mwtesttmp/share/mail \
  19. XDG_CACHE_HOME=mwtesttmp/cache \
  20. source ../bin/mw
  21. export NOTMUCH_CONFIG=mwtesttmp/config/notmuch-config
  22. export mwname="real name"
  23. export mwaddr="full.addr@gmail.com"
  24. export mwlogin="$mwaddr"
  25. export mwmailboxes="[Gmail]/INBOX"
  26. export mwshare=$PWD/../share
  27. function pass() { return 0; }
  28. export pass
  29. function _mwcheckinternet() { return 0; }
  30. export _mwcheckinternet
  31. function _mwcheckcert() { return 0; }
  32. export _mwcheckcert
  33. function pgrep() { return 0; }
  34. export pgrep
  35. function crontab() { echo 'none'; }
  36. export crontab
  37. function _mwsyncandnotify() { echo "$mwaddr"; }
  38. export _mwsyncandnotify
  39. }
  40. teardown()
  41. {
  42. if [ -z "$TEST_FUNCTION" ]
  43. then
  44. rm -rf mwtesttmp
  45. fi
  46. }
  47. # 1
  48. @test "check config" {
  49. [ "$mwmbsyncrc" = "mwtesttmp/config/isync/mbsyncrc" ]
  50. [ "$mwmsmtprc" = "mwtesttmp/config/msmtp/config" ]
  51. }
  52. # 2
  53. @test "add online" {
  54. mwtype="online" run _mwadd
  55. [ -f mwtesttmp/config/mutt/muttrc ]
  56. [ -f mwtesttmp/config/mutt/accounts/1-$mwaddr.mwonofftype.online.muttrc ]
  57. [ "$(cat mwtesttmp/config/isync/mbsyncrc | sed -ne '/^\s*\w/p')" = "" ]
  58. [ "$(cat mwtesttmp/config/msmtp/config | sed -ne '/^account/p')" = "" ]
  59. [ ! "$(cat mwtesttmp/config/mutt/accounts/1-$mwaddr.mwonofftype.online.muttrc | sed -ne '/smtp_url/p')" = "" ]
  60. [ ! -f mwtesttmp/config/notmuch-config ]
  61. }
  62. # 3
  63. @test "add offline unsuccessful" {
  64. export mwmailboxes="[Gmail]/OTHER"
  65. mwtype="offline" run _mwadd
  66. [ -f mwtesttmp/config/mutt/muttrc ]
  67. [ -d mwtesttmp/config/mutt/accounts ]
  68. [ ! -f mwtesttmp/config/mutt/accounts/1-$mwaddr.mwonofftype.offline.muttrc ]
  69. [ "$(cat mwtesttmp/config/isync/mbsyncrc | sed -ne '/^\s*\w/p')" = "" ]
  70. [ "$(cat mwtesttmp/config/msmtp/config | sed -ne '/^account/p')" = "" ]
  71. [ ! -f mwtesttmp/config/notmuch-config ]
  72. }
  73. # 4
  74. @test "add offline successfully" {
  75. mwtype="offline" run _mwadd
  76. [ -f mwtesttmp/config/mutt/muttrc ]
  77. [ -d mwtesttmp/config/mutt/accounts ]
  78. [ -f mwtesttmp/config/mutt/accounts/1-$mwaddr.mwonofftype.offline.muttrc ]
  79. [ -f mwtesttmp/config/notmuch-config ]
  80. [ ! "$(cat mwtesttmp/config/isync/mbsyncrc | sed -ne '/^\s*\w/p')" = "" ]
  81. [ ! "$(cat mwtesttmp/config/msmtp/config | sed -ne '/^account/p')" = "" ]
  82. [ "$(cat mwtesttmp/config/mutt/accounts/1-$mwaddr.mwonofftype.online.muttrc | sed -ne '/smtp_url/p')" = "" ]
  83. run _mwlist
  84. [ "$(echo $lines | awk '{print $2}')" = "$mwaddr" ]
  85. }
  86. # 5
  87. @test "delete account" {
  88. mwtype="online" run _mwadd
  89. mwtype="offline" run _mwadd
  90. pick_delete()
  91. {
  92. _mwpick delete && _mwdelete
  93. }
  94. export pick_delete
  95. mwpick="1" run pick_delete
  96. [ ! -f mwtesttmp/config/mutt/accounts/1-$mwaddr.mwonofftype.online.muttrc ]
  97. [ ! "$(cat mwtesttmp/config/isync/mbsyncrc | sed -ne '/^\s*\w/p')" = "" ]
  98. [ ! "$(cat mwtesttmp/config/msmtp/config | sed -ne '/^account/p')" = "" ]
  99. }
  100. # 6
  101. @test "cron" {
  102. mwcronminutes=99 run _mwcron
  103. chkline="${lines[1]}"
  104. [ "${chkline::16}" = "mw cronjob added" ]
  105. function crontab() { echo 'mw sync'; }
  106. export crontab
  107. mwcronremove=y run _mwcron
  108. chkline="${lines[1]}"
  109. [ "${chkline#*cronjob}" = " removed." ]
  110. }
  111. # 7
  112. @test "sync" {
  113. mwtype="offline" run _mwadd
  114. function pgrep() { [ "$1" = "-u" ] && return 0 || return 1; }
  115. export pgrep
  116. run _mwsync
  117. [ "${lines// /}" = "full.addr@gmail.com" ]
  118. }
  119. # 8
  120. @test "add pop" {
  121. export mwaddr="full.addr@chello.at"
  122. mwtype="offline" run _mwadd
  123. [ -f mwtesttmp/config/mutt/muttrc ]
  124. [ -d mwtesttmp/config/mutt/accounts ]
  125. [ -f mwtesttmp/config/mutt/accounts/1-$mwaddr.mwonofftype.offline.muttrc ]
  126. [ -f mwtesttmp/config/notmuch-config ]
  127. [ ! "$(cat mwtesttmp/config/msmtp/config | sed -ne '/^account/p')" = "" ]
  128. [ ! "$(cat mwtesttmp/config/getmail/$mwaddr | sed -ne '/^\s*\w/p')" = "" ]
  129. run _mwlist
  130. [ "$(echo $lines | awk '{print $2}')" = "$mwaddr" ]
  131. }