2024-07-07 21:08:41 +02:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TestLogger struct {
|
|
|
|
t *testing.T
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *TestLogger) Log(str string, fmt ...any) (int, error) {
|
|
|
|
s.t.Logf(str, fmt...)
|
|
|
|
return 10, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *TestLogger) LogError(str string, fmt ...any) (int, error) {
|
|
|
|
s.t.Errorf(str, fmt...)
|
|
|
|
return 10, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *TestLogger) LogPlainError(err error) (int, error) {
|
|
|
|
s.t.Error(err)
|
|
|
|
return 10, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateTestLogger(t *testing.T) Logger {
|
|
|
|
var logger TestLogger
|
|
|
|
|
|
|
|
logger.t = t
|
|
|
|
return &logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPushRequestParsing(t *testing.T) {
|
|
|
|
t.Run("parsing repo creation message", func(t *testing.T) {
|
|
|
|
var h RequestHandler
|
|
|
|
|
|
|
|
h.Logger = CreateTestLogger(t)
|
2024-07-09 12:06:24 +02:00
|
|
|
json := h.parsePushRequest(strings.NewReader(examplePushJSON))
|
2024-07-10 10:14:56 +02:00
|
|
|
if json == nil {
|
|
|
|
t.Fatalf("failed to parser push request: %v", h.Error)
|
|
|
|
}
|
2024-07-07 21:08:41 +02:00
|
|
|
if h.HasError() {
|
|
|
|
t.Fatalf("Can't parse struct: %s", h.Error.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|