mirror of
https://github.com/valitydev/botkube.git
synced 2024-11-06 16:35:22 +00:00
b087f94804
This Commit, - Fixes build failure due to e2e tests ##### ISSUE TYPE <!--- Pick one below and delete the rest: --> - Bug fix Pull Request ##### SUMMARY <!--- Describe the change, including rationale and design decisions --> <!--- If you are fixing an existing issue, please include "Fixes #nnn" in your PR comment; and describe briefly what the change does. --> <!--- Please list dependencies added with your change also --> Fixes #384
65 lines
2.1 KiB
Go
65 lines
2.1 KiB
Go
// Copyright (c) 2019 InfraCloud Technologies
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
// this software and associated documentation files (the "Software"), to deal in
|
|
// the Software without restriction, including without limitation the rights to
|
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
// the Software, and to permit persons to whom the Software is furnished to do so,
|
|
// subject to the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
// copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
package notify
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// Unit test PostWebhook
|
|
func TestPostWebhook(t *testing.T) {
|
|
tests := map[string]struct {
|
|
server *httptest.Server
|
|
expected error
|
|
}{
|
|
`Status Not Ok`: {
|
|
httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusServiceUnavailable)
|
|
})),
|
|
fmt.Errorf("Error Posting Webhook: %s", fmt.Sprint(http.StatusServiceUnavailable)),
|
|
},
|
|
`Status Ok`: {
|
|
httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusOK)
|
|
})),
|
|
nil,
|
|
},
|
|
}
|
|
for name, test := range tests {
|
|
name, test := name, test
|
|
t.Run(name, func(t *testing.T) {
|
|
ts := test.server
|
|
defer ts.Close()
|
|
// create a dummy webhook object to test
|
|
w := &Webhook{
|
|
URL: ts.URL,
|
|
}
|
|
|
|
err := w.PostWebhook(&WebhookPayload{})
|
|
assert.Equal(t, test.expected, err)
|
|
})
|
|
}
|
|
}
|