fork 0k-charms
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
3.0 KiB

  1. #!/bin/bash
  2. exname=$(basename $0)
  3. prefix_cmd="
  4. . /etc/shlib
  5. include common
  6. include parse
  7. . ../lib/common
  8. valid_existing_cert() {
  9. local i
  10. echo \"Calling valid_existing_cert\" >&2
  11. ((i=0))
  12. for arg in \"\$@\"; do
  13. echo \" arg\$((i++)):\"
  14. echo \"\$arg\" | prefix \" | \"
  15. done >&2
  16. [ \"\$VALID_EXISTING_CERT\" == \"yes\" ]
  17. }
  18. export -f valid_existing_cert
  19. crt() {
  20. local i
  21. echo \"Calling crt\" >&2
  22. ((i=0))
  23. for arg in \"\$@\"; do
  24. echo \" arg\$((i++)):\"
  25. echo \"\$arg\" | prefix \" | \"
  26. done >&2
  27. }
  28. export -f crt
  29. get_domain_list() {
  30. local i
  31. echo \"Calling get_domain_list\" >&2
  32. ((i=0))
  33. for arg in \"\$@\"; do
  34. echo \" arg\$((i++)):\"
  35. echo \"\$arg\" | prefix \" | \"
  36. done >&2
  37. echo \"\$GET_DOMAIN_LIST\"
  38. }
  39. export -f get_domain_list
  40. "
  41. ##
  42. ## Mocks
  43. ##
  44. get_compose_service_def() {
  45. local i
  46. echo "Calling: get_compose_service_def" >&2
  47. ((i=0))
  48. for arg in "$@"; do
  49. echo " arg$((i++)):"
  50. echo "$arg" | prefix " | "
  51. done >&2
  52. echo "$GET_COMPOSE_SERVICE_DEF"
  53. }
  54. export -f get_compose_service_def
  55. try "
  56. exname=\"crt renew\"
  57. SERVICE_NAME='\$SERVICE_NAME'
  58. GET_COMPOSE_SERVICE_DEF=
  59. crt_renew xxx
  60. "
  61. is err 'Error: No argument required
  62. usage: $
  63. crt renew [-h|--help]' RTRIM
  64. is errlvl 1
  65. is out ''
  66. try "
  67. exname=\"crt renew\"
  68. SERVICE_NAME='\$SERVICE_NAME'
  69. GET_COMPOSE_SERVICE_DEF=
  70. GET_DOMAIN_LIST=
  71. crt_renew
  72. "
  73. is err part 'II No domain founds' RTRIM
  74. is errlvl 0
  75. is out ''
  76. try "
  77. exname=\"crt renew\"
  78. SERVICE_NAME='\$SERVICE_NAME'
  79. GET_COMPOSE_SERVICE_DEF='
  80. options:
  81. wiz: foo
  82. '
  83. GET_DOMAIN_LIST='
  84. www.example.com:
  85. remaining: 20
  86. foo.bar:
  87. remaining: 32
  88. '
  89. crt_renew
  90. " "2 certs, one need renew, one is ok"
  91. is err part 'II Renewing domain www.example.com (20 days left)' RTRIM
  92. is err part 'Calling crt
  93. arg0:
  94. | wiz: foo
  95. arg1:
  96. | renew
  97. arg2:
  98. | www.example.com
  99. '
  100. is err part 'II Domain foo.bar does not need renewing (32 days left).' RTRIM
  101. is errlvl 0
  102. is out ''
  103. try "
  104. exname=\"crt renew\"
  105. SERVICE_NAME='\$SERVICE_NAME'
  106. GET_COMPOSE_SERVICE_DEF='
  107. options:
  108. wiz: foo
  109. renew-before-expiry: 15
  110. '
  111. GET_DOMAIN_LIST='
  112. www.example.com:
  113. remaining: 45
  114. '
  115. crt_renew
  116. " "setting renew-before-expiry"
  117. is err part 'II Domain www.example.com does not need renewing (45 days left).' RTRIM
  118. is errlvl 0
  119. is out ''
  120. try "
  121. exname=\"crt renew\"
  122. SERVICE_NAME='\$SERVICE_NAME'
  123. GET_COMPOSE_SERVICE_DEF=
  124. GET_DOMAIN_LIST='
  125. www.example.com:
  126. remaining: EXPIRED
  127. '
  128. crt_renew
  129. " "expired cert"
  130. is err part 'II Renewing domain www.example.com (expired).' RTRIM
  131. is errlvl 0
  132. is out ''
  133. try "
  134. crt() { ! [[ \"\$3\" =~ ^wiz|foo$ ]]; }
  135. exname=\"crt renew\"
  136. SERVICE_NAME='\$SERVICE_NAME'
  137. GET_COMPOSE_SERVICE_DEF=
  138. GET_DOMAIN_LIST='
  139. www.example.com:
  140. remaining: EXPIRED
  141. foo:
  142. remaining: EXPIRED
  143. bar:
  144. remaining: 98
  145. wiz:
  146. remaining: 10
  147. '
  148. crt_renew
  149. " "some failed renewal"
  150. is err part 'II Renewing domain www.example.com (expired).' RTRIM
  151. is err part 'Error: At least one domain failed to be renewed: foo wiz' RTRIM
  152. is errlvl 1
  153. is out ''