|
| 1 | +#!/usr/bin/env bats |
| 2 | +# |
| 3 | +# Copyright 2022 HAProxy Technologies |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http:#www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | + |
| 18 | +# We test both mailers sections and entries in the same file. |
| 19 | +# If they were separated in 2 files, bats would run them |
| 20 | +# in parrallel, making some tests fail. |
| 21 | + |
| 22 | +load '../../libs/dataplaneapi' |
| 23 | +load '../../libs/get_json_path' |
| 24 | +load '../../libs/resource_client' |
| 25 | +load '../../libs/version' |
| 26 | + |
| 27 | +load 'utils/_helpers' |
| 28 | + |
| 29 | +@test "mailers: add a section" { |
| 30 | + resource_post "$_MAILERS_SECTION_PATH" "data/post_section.json" "force_reload=true" |
| 31 | + assert_equal "$SC" "201" |
| 32 | +} |
| 33 | + |
| 34 | +@test "mailers: get a section" { |
| 35 | + resource_get "$_MAILERS_SECTION_PATH/$_SECTION_NAME" |
| 36 | + assert_equal "$SC" "200" |
| 37 | + assert_equal "$_SECTION_NAME" "$(get_json_path "$BODY" .data.name)" |
| 38 | + assert_equal "15000" "$(get_json_path "$BODY" .data.timeout)" |
| 39 | +} |
| 40 | + |
| 41 | +@test "mailers: edit a section" { |
| 42 | + resource_put "$_MAILERS_SECTION_PATH/$_SECTION_NAME" "data/put_section.json" "force_reload=true" |
| 43 | + assert_equal "$SC" "200" |
| 44 | + resource_get "$_MAILERS_SECTION_PATH/$_SECTION_NAME" |
| 45 | + assert_equal "30000" "$(get_json_path "$BODY" .data.timeout)" |
| 46 | +} |
| 47 | + |
| 48 | +@test "mailers: get a list of sections" { |
| 49 | + resource_get "$_MAILERS_SECTION_PATH" |
| 50 | + assert_equal "$SC" "200" |
| 51 | + assert_equal "$_SECTION_NAME" "$(get_json_path "$BODY" .data[0].name)" |
| 52 | +} |
| 53 | + |
| 54 | +@test "mailers: add entries" { |
| 55 | + resource_post "$_MAILER_ENTRIES_PATH" "data/post_entry1.json" "mailers_section=$_SECTION_NAME" |
| 56 | + assert_equal "$SC" "202" |
| 57 | + resource_post "$_MAILER_ENTRIES_PATH" "data/post_entry2.json" "mailers_section=$_SECTION_NAME" |
| 58 | + assert_equal "$SC" "202" |
| 59 | +} |
| 60 | + |
| 61 | +@test "mailers: get an entry" { |
| 62 | + resource_get "$_MAILER_ENTRIES_PATH/smtp1" "mailers_section=$_SECTION_NAME" |
| 63 | + assert_equal "$SC" "200" |
| 64 | + assert_equal "smtp1" "$(get_json_path "$BODY" .data.name)" |
| 65 | + assert_equal "10.0.10.1" "$(get_json_path "$BODY" .data.address)" |
| 66 | + assert_equal "587" "$(get_json_path "$BODY" .data.port)" |
| 67 | +} |
| 68 | + |
| 69 | +@test "mailers: get all entries" { |
| 70 | + resource_get "$_MAILER_ENTRIES_PATH" "mailers_section=$_SECTION_NAME" |
| 71 | + assert_equal "$SC" "200" |
| 72 | + assert_equal "2" "$(get_json_path "$BODY" '.data|length')" |
| 73 | + assert_equal "smtp1" "$(get_json_path "$BODY" .data[0].name)" |
| 74 | + assert_equal "smtp2" "$(get_json_path "$BODY" .data[1].name)" |
| 75 | +} |
| 76 | + |
| 77 | +@test "mailers: modify an entry" { |
| 78 | + resource_put "$_MAILER_ENTRIES_PATH/smtp2" "data/put_entry.json" \ |
| 79 | + "mailers_section=$_SECTION_NAME" "force_reload=true" |
| 80 | + assert_equal "$SC" "202" |
| 81 | + resource_get "$_MAILER_ENTRIES_PATH/smtp2" "mailers_section=$_SECTION_NAME" |
| 82 | + assert_equal "smtp2" "$(get_json_path "$BODY" .data.name)" |
| 83 | + assert_equal "10.0.10.88" "$(get_json_path "$BODY" .data.address)" |
| 84 | + assert_equal "8587" "$(get_json_path "$BODY" .data.port)" |
| 85 | +} |
| 86 | + |
| 87 | +@test "mailers: delete an entry" { |
| 88 | + resource_delete "$_MAILER_ENTRIES_PATH/smtp2" "mailers_section=$_SECTION_NAME" "force_reload=true" |
| 89 | + assert_equal "$SC" "202" |
| 90 | + resource_get "$_MAILER_ENTRIES_PATH/smtp2" "mailers_section=$_SECTION_NAME" |
| 91 | + assert_equal "$SC" "404" |
| 92 | +} |
| 93 | + |
| 94 | +@test "mailers: delete a section" { |
| 95 | + resource_delete "$_MAILERS_SECTION_PATH/$_SECTION_NAME" "force_reload=true" |
| 96 | + assert_equal "$SC" "204" |
| 97 | + resource_get "$_MAILERS_SECTION_PATH/$_SECTION_NAME" |
| 98 | + assert_equal "$SC" "404" |
| 99 | +} |
0 commit comments