mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-26 09:09:36 -05:00
8cd89bf4d3
This does not work yet. APAPI url OR host and id have to be derived from repoUri.
39 lines
1 KiB
Go
39 lines
1 KiB
Go
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package federation
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test_IsValidRepoUri(t *testing.T) {
|
|
validUri := "http://localhost:3000/me/test"
|
|
invalidUri := "http://localhost:3000/me/test/foo"
|
|
assert.True(t, IsValidRepoUri(validUri))
|
|
assert.False(t, IsValidRepoUri(invalidUri))
|
|
}
|
|
|
|
func Test_GetRepoAPIUriFromRepoUri(t *testing.T) {
|
|
uri := "http://localhost:3000/me/test"
|
|
expectedUri := "http://localhost:3000/api/v1/repos/me/test"
|
|
|
|
res, err := GetRepoAPIUriFromRepoUri(uri)
|
|
assert.ErrorIs(t, err, nil)
|
|
assert.Equal(t, expectedUri, res)
|
|
}
|
|
|
|
func Test_GetRepoOwnerAndNameFromRepoUri(t *testing.T) {
|
|
validUri := "http://localhost:3000/me/test"
|
|
invalidUri := "http://localhost:3000/me/test/foo"
|
|
|
|
owner, name, err := GetRepoOwnerAndNameFromRepoUri(validUri)
|
|
assert.ErrorIs(t, err, nil)
|
|
assert.Equal(t, "me", owner)
|
|
assert.Equal(t, "test", name)
|
|
|
|
_, _, err = GetRepoOwnerAndNameFromRepoUri(invalidUri)
|
|
assert.Error(t, err)
|
|
}
|