mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-22 09:54:24 +01:00
add test & fix compile
This commit is contained in:
parent
4938d38e39
commit
508b4deac8
|
@ -10,14 +10,14 @@ import (
|
|||
// FederatedRepo represents a federated Repository Actor connected with a local Repo
|
||||
type FederatedRepo struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
RepositoryID int64 `xorm:"NOT NULL"`
|
||||
RepoID int64 `xorm:"NOT NULL"`
|
||||
ExternalID string `xorm:"TEXT UNIQUE(federation_repo_mapping) NOT NULL"`
|
||||
FederationHostID int64 `xorm:"UNIQUE(federation_repo_mapping) NOT NULL"`
|
||||
}
|
||||
|
||||
func NewFederatedRepo(repositoryID int64, externalID string, federationHostID int64) (FederatedRepo, error) {
|
||||
func NewFederatedRepo(repoID int64, externalID string, federationHostID int64) (FederatedRepo, error) {
|
||||
result := FederatedRepo{
|
||||
RepositoryID: repositoryID,
|
||||
RepoID: repoID,
|
||||
ExternalID: externalID,
|
||||
FederationHostID: federationHostID,
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ func NewFederatedRepo(repositoryID int64, externalID string, federationHostID in
|
|||
|
||||
func (user FederatedRepo) Validate() []string {
|
||||
var result []string
|
||||
result = append(result, validation.ValidateNotEmpty(user.RepositoryID, "UserID")...)
|
||||
result = append(result, validation.ValidateNotEmpty(user.RepoID, "UserID")...)
|
||||
result = append(result, validation.ValidateNotEmpty(user.ExternalID, "ExternalID")...)
|
||||
result = append(result, validation.ValidateNotEmpty(user.FederationHostID, "FederationHostID")...)
|
||||
return result
|
||||
|
|
29
models/repo/federated_repo_test.go
Normal file
29
models/repo/federated_repo_test.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/validation"
|
||||
)
|
||||
|
||||
func Test_FederatedRepoValidation(t *testing.T) {
|
||||
sut := FederatedRepo{
|
||||
RepoID: 12,
|
||||
ExternalID: "12",
|
||||
FederationHostID: 1,
|
||||
}
|
||||
if res, err := validation.IsValid(sut); !res {
|
||||
t.Errorf("sut should be valid but was %q", err)
|
||||
}
|
||||
|
||||
sut = FederatedRepo{
|
||||
ExternalID: "12",
|
||||
FederationHostID: 1,
|
||||
}
|
||||
if res, _ := validation.IsValid(sut); res {
|
||||
t.Errorf("sut should be invalid")
|
||||
}
|
||||
}
|
|
@ -350,7 +350,8 @@ func (repo *Repository) APIURL() string {
|
|||
// TODO: At least camel case?
|
||||
// TODO: Mv federation related stuff to federated_repo
|
||||
func (repo *Repository) APAPIURL() string {
|
||||
return setting.AppURL + "api/v1/activitypub/repository-id/" + url.PathEscape(string(repo.ID))
|
||||
// TODO: use spintf instead of concat - might mitigate injections
|
||||
return fmt.Sprintf("%vapi/v1/activitypub/repository-id/%v", setting.AppURL, url.PathEscape(fmt.Sprint(repo.ID)))
|
||||
}
|
||||
|
||||
// GetCommitsCountCacheKey returns cache key used for commits count caching.
|
||||
|
|
Loading…
Reference in a new issue