2024-07-07 21:08:41 +02:00
|
|
|
package common
|
|
|
|
|
2024-09-10 18:24:41 +02:00
|
|
|
/*
|
|
|
|
* This file is part of Autogits.
|
|
|
|
*
|
|
|
|
* Copyright © 2024 SUSE LLC
|
|
|
|
*
|
|
|
|
* Autogits is free software: you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation, either version 2 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* Autogits is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
|
|
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* Foobar. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2024-07-07 21:08:41 +02:00
|
|
|
import (
|
2024-08-24 13:32:39 +02:00
|
|
|
"os"
|
2024-07-07 21:08:41 +02:00
|
|
|
"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 h RequestHandler
|
|
|
|
|
2024-08-24 13:32:39 +02:00
|
|
|
h.StdLogger, h.ErrLogger = CreateStdoutLogger(os.Stdout, os.Stdout)
|
2024-08-28 17:20:09 +02:00
|
|
|
json, err := h.parseRepositoryRequest(strings.NewReader(repoCreateJSON))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Can't parse struct: %s", err)
|
2024-07-07 21:08:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|