44 lines
983 B
Go
44 lines
983 B
Go
|
package common
|
||
|
|
||
|
import (
|
||
|
"strings"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
type testLogger struct {
|
||
|
str string
|
||
|
}
|
||
|
|
||
|
func (s *testLogger) WriteString(str2 string) (int, error) {
|
||
|
s.str += str2
|
||
|
return len(s.str), nil
|
||
|
}
|
||
|
|
||
|
|
||
|
func TestRepositoryRequestParsing(t *testing.T) {
|
||
|
t.Run("parsing repo creation message", func(t *testing.T) {
|
||
|
var strStr, errStr testLogger
|
||
|
var h RequestHandler
|
||
|
|
||
|
h.Logger = CreateStdoutLogger(&strStr, &errStr)
|
||
|
json := h.ParseRepositoryRequest(strings.NewReader(repoCreateJSON))
|
||
|
if h.HasError() {
|
||
|
t.Fatalf("Can't parse struct: %s", h.Error)
|
||
|
}
|
||
|
|
||
|
if json.Action != "created" {
|
||
|
t.Fatalf("json.action is '%#v'", json)
|
||
|
}
|
||
|
|
||
|
if json.Repository.Full_Name != "autogits/nodejs22" ||
|
||
|
json.Repository.Parent == nil ||
|
||
|
json.Repository.Parent.Parent != nil ||
|
||
|
len(json.Repository.Ssh_Url) < 10 ||
|
||
|
json.Repository.Default_Branch != "factory" ||
|
||
|
json.Repository.Object_Format_Name != "sha256" {
|
||
|
|
||
|
t.Fatalf("invalid repository parse: %#v", json.Repository)
|
||
|
}
|
||
|
})
|
||
|
}
|