001-create_test.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #!/usr/bin/env bash
  2. source $(dirname ${BASH_SOURCE[0]})/../../tests/utils.sh
  3. source $(dirname ${BASH_SOURCE[0]})/utils.sh
  4. test_call() {
  5. imag-store create -p test-call
  6. if [[ ! $? -eq 0 ]]; then
  7. err "Return value should be zero, was non-zero"
  8. return 1;
  9. fi
  10. }
  11. test_call_id() {
  12. imag-store create -i test-call
  13. if [[ ! $? -eq 0 ]]; then
  14. err "Return value should be zero, was non-zero"
  15. return 1;
  16. fi
  17. }
  18. test_call_no_id() {
  19. imag-store create
  20. if [[ ! $? -eq 1 ]]; then
  21. err "Return value should be zero, was non-zero"
  22. return 1;
  23. fi
  24. }
  25. test_mkstore() {
  26. imag-store create -p test-mkstore || { err "Calling imag failed"; return 1; }
  27. if [[ -d ${STORE} ]]; then
  28. out "Store exists."
  29. else
  30. err "No store created"
  31. return 1
  32. fi
  33. }
  34. test_std_header() {
  35. local expected=$(cat <<EOS
  36. ---
  37. [imag]
  38. links = []
  39. version = "0.3.0"
  40. ---
  41. EOS
  42. )
  43. imag-store create -p test-std-header
  44. local result=$(cat ${STORE}/test-std-header)
  45. if [[ "$expected" == "$result" ]]; then
  46. out "Expected store entry == result"
  47. else
  48. err "${STORE}/test-std-header differs from expected"
  49. return 1
  50. fi
  51. }
  52. test_std_header_plus_custom() {
  53. local expected=$(cat <<EOS
  54. ---
  55. [imag]
  56. links = []
  57. version = "0.3.0"
  58. [zzz]
  59. zzz = "z"
  60. ---
  61. EOS
  62. )
  63. imag-store create -p test-std-header-plus-custom entry -h zzz.zzz=z
  64. local result=$(cat ${STORE}/test-std-header-plus-custom)
  65. if [[ "$expected" == "$result" ]]; then
  66. out "Expected store entry == result"
  67. else
  68. err "${STORE}/test differs from expected"
  69. return 1
  70. fi
  71. }
  72. test_std_header_plus_custom_multiheader() {
  73. local expected=$(cat <<EOS
  74. ---
  75. [foo]
  76. bar = "baz"
  77. [imag]
  78. links = []
  79. version = "0.3.0"
  80. [zzz]
  81. zzz = "z"
  82. ---
  83. EOS
  84. )
  85. local filename="test-std-header-plus-custom-multiheader"
  86. imag-store create -p $filename entry -h zzz.zzz=z foo.bar=baz
  87. local result=$(cat ${STORE}/$filename)
  88. if [[ "$expected" == "$result" ]]; then
  89. out "Expected store entry == result"
  90. else
  91. err "${STORE}/$filename differs from expected"
  92. return 1
  93. fi
  94. }
  95. test_std_header_plus_custom_multiheader_same_section() {
  96. local expected=$(cat <<EOS
  97. ---
  98. [imag]
  99. links = []
  100. version = "0.3.0"
  101. [zzz]
  102. bar = "baz"
  103. zzz = "z"
  104. ---
  105. EOS
  106. )
  107. local filename="test-std-header-plus-custom-mutliheader-same-section"
  108. imag-store create -p $filename entry -h zzz.zzz=z zzz.bar=baz
  109. local result=$(cat ${STORE}/$filename)
  110. if [[ "$expected" == "$result" ]]; then
  111. out "Expected store entry == result"
  112. else
  113. err "${STORE}/$filename differs from expected"
  114. return 1
  115. fi
  116. }
  117. test_std_header_plus_custom_and_content() {
  118. local expected=$(cat <<EOS
  119. ---
  120. [imag]
  121. links = []
  122. version = "0.3.0"
  123. [zzz]
  124. zzz = "z"
  125. ---
  126. content
  127. EOS
  128. )
  129. local name="test-std-header-plus-custom-and-content"
  130. imag-store create -p $name entry -h zzz.zzz=z -c content
  131. local result=$(cat ${STORE}/$name)
  132. if [[ "$expected" == "$result" ]]; then
  133. out "Expected store entry == result"
  134. else
  135. err "${STORE}/test differs from expected"
  136. return 1
  137. fi
  138. }
  139. invoke_tests \
  140. test_call \
  141. test_call_id \
  142. test_call_no_id \
  143. test_mkstore \
  144. test_std_header \
  145. test_std_header_plus_custom \
  146. test_std_header_plus_custom_multiheader \
  147. test_std_header_plus_custom_multiheader_same_section \
  148. test_std_header_plus_custom_and_content