mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-24 08:57:03 -05:00
add test & fix compile
This commit is contained in:
parent
4938d38e39
commit
508b4deac8
3 changed files with 35 additions and 5 deletions
|
@ -10,14 +10,14 @@ import (
|
||||||
// FederatedRepo represents a federated Repository Actor connected with a local Repo
|
// FederatedRepo represents a federated Repository Actor connected with a local Repo
|
||||||
type FederatedRepo struct {
|
type FederatedRepo struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
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"`
|
ExternalID string `xorm:"TEXT UNIQUE(federation_repo_mapping) NOT NULL"`
|
||||||
FederationHostID int64 `xorm:"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{
|
result := FederatedRepo{
|
||||||
RepositoryID: repositoryID,
|
RepoID: repoID,
|
||||||
ExternalID: externalID,
|
ExternalID: externalID,
|
||||||
FederationHostID: federationHostID,
|
FederationHostID: federationHostID,
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ func NewFederatedRepo(repositoryID int64, externalID string, federationHostID in
|
||||||
|
|
||||||
func (user FederatedRepo) Validate() []string {
|
func (user FederatedRepo) Validate() []string {
|
||||||
var result []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.ExternalID, "ExternalID")...)
|
||||||
result = append(result, validation.ValidateNotEmpty(user.FederationHostID, "FederationHostID")...)
|
result = append(result, validation.ValidateNotEmpty(user.FederationHostID, "FederationHostID")...)
|
||||||
return result
|
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: At least camel case?
|
||||||
// TODO: Mv federation related stuff to federated_repo
|
// TODO: Mv federation related stuff to federated_repo
|
||||||
func (repo *Repository) APAPIURL() string {
|
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.
|
// GetCommitsCountCacheKey returns cache key used for commits count caching.
|
||||||
|
|
Loading…
Reference in a new issue