2025-06-02 22:29:10 +02:00
|
|
|
// Copyright 2023, 2024, 2025 The Forgejo Authors. All rights reserved.
|
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
2025-12-09 15:37:50 +01:00
|
|
|
package forgefed_test
|
2025-06-02 22:29:10 +02:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
2025-12-09 15:37:50 +01:00
|
|
|
"forgejo.org/modules/forgefed"
|
2025-06-02 22:29:10 +02:00
|
|
|
"forgejo.org/modules/setting"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestNewRepositoryId(t *testing.T) {
|
2025-12-09 15:37:50 +01:00
|
|
|
var sut, expected forgefed.RepositoryID
|
2025-06-02 22:29:10 +02:00
|
|
|
var err error
|
|
|
|
|
setting.AppURL = "http://localhost:3000/"
|
|
|
|
|
|
2025-12-09 15:37:50 +01:00
|
|
|
expected = forgefed.RepositoryID{}
|
2025-06-02 22:29:10 +02:00
|
|
|
expected.ID = "1"
|
|
|
|
|
expected.Source = "forgejo"
|
|
|
|
|
expected.HostSchema = "http"
|
|
|
|
|
expected.Path = ""
|
|
|
|
|
expected.Host = "localhost"
|
|
|
|
|
expected.HostPort = 3000
|
|
|
|
|
expected.IsPortSupplemented = false
|
|
|
|
|
expected.UnvalidatedInput = "http://localhost:3000/1"
|
|
|
|
|
|
2025-12-09 15:37:50 +01:00
|
|
|
_, err = forgefed.NewRepositoryID("https://an.other.host/api/v1/activitypub/user-id/1", "forgejo")
|
2025-06-02 22:29:10 +02:00
|
|
|
require.EqualError(t, err, "Validation Error: forgefed.RepositoryID: path: \"api/v1/activitypub/user-id\" has to be a repo specific api path")
|
|
|
|
|
|
2025-12-09 15:37:50 +01:00
|
|
|
expected = forgefed.RepositoryID{}
|
2025-06-02 22:29:10 +02:00
|
|
|
expected.ID = "1"
|
|
|
|
|
expected.Source = "forgejo"
|
|
|
|
|
expected.HostSchema = "http"
|
|
|
|
|
expected.Path = "api/activitypub/repository-id"
|
|
|
|
|
expected.Host = "localhost"
|
|
|
|
|
expected.HostPort = 3000
|
|
|
|
|
expected.IsPortSupplemented = false
|
|
|
|
|
expected.UnvalidatedInput = "http://localhost:3000/api/activitypub/repository-id/1"
|
2025-12-09 15:37:50 +01:00
|
|
|
sut, err = forgefed.NewRepositoryID("http://localhost:3000/api/activitypub/repository-id/1", "forgejo")
|
2025-06-02 22:29:10 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, expected, sut)
|
|
|
|
|
}
|