autogits/bots-common/request_push_test.go

33 lines
833 B
Go
Raw Normal View History

2024-07-07 21:08:41 +02:00
package common
import (
2024-08-28 17:53:15 +02:00
"os"
2024-07-07 21:08:41 +02:00
"strings"
"testing"
)
func TestPushRequestParsing(t *testing.T) {
t.Run("parsing repo creation message", func(t *testing.T) {
var h RequestHandler
2024-08-28 17:53:15 +02:00
h.StdLogger, h.ErrLogger = CreateStdoutLogger(os.Stdout, os.Stderr)
2024-08-28 17:20:09 +02:00
json, err := h.parsePushRequest(strings.NewReader(examplePushJSON))
if err != nil {
t.Fatalf("failed to parser push request: %v", err)
2024-07-07 21:08:41 +02:00
}
if json.Total_Commits < 1 || json.Total_Commits != len(json.Commits) {
t.Fatalf("push without commits? '%#v'", json)
}
if json.Repository.Full_Name != "autogits/_ObsPrj" ||
json.Repository.Parent != nil ||
len(json.Repository.Ssh_Url) < 10 ||
json.Repository.Default_Branch != "main" ||
json.Repository.Object_Format_Name != "sha256" {
t.Fatalf("invalid repository parse: %#v", json.Repository)
}
})
}