1
0
mirror of https://github.com/openshift/source-to-image.git synced 2026-02-05 12:44:54 +01:00
Files
source-to-image/pkg/util/callback_test.go
2025-11-24 12:28:04 -06:00

50 lines
982 B
Go

package util
import (
"encoding/json"
"io"
"net/http"
"testing"
)
type FakePost struct {
err error
response http.Response
body []byte
url string
}
func (f *FakePost) post(url, contentType string, body io.Reader) (resp *http.Response, err error) {
f.url = url
f.body, _ = io.ReadAll(body)
return &f.response, f.err
}
func TestExecuteCallback(t *testing.T) {
fp := FakePost{}
cb := callbackInvoker{
postFunc: fp.post,
}
labels := map[string]string{
"foo": "bar",
}
cb.ExecuteCallback("http://the.callback.url/test", true, labels, []string{"msg1", "msg2"})
type postBody struct {
Labels map[string]string
Success bool
}
var pb postBody
json.Unmarshal(fp.body, &pb)
if len(pb.Labels) == 0 {
t.Errorf("Expected labels to be present in payload")
}
if pb.Labels["foo"] != "bar" {
t.Errorf("Expected 'foo' to be 'bar', got %q", pb.Labels["foo"])
}
if pb.Success != true {
t.Errorf("Unexpected success flag: %v", pb.Success)
}
}