Monorepo for Tangled
tangled.org
1package knotserver
2
3import (
4 "testing"
5
6 "github.com/alecthomas/assert/v2"
7 "github.com/stretchr/testify/require"
8 "tangled.org/core/knotserver/db"
9)
10
11const (
12 appviewURL = "https://tangled.org/"
13 user = "willdot.net"
14 userDID = "did:plc:dadhhalkfcq3gucaq25hjqon"
15 pushedBranch = "feature-abc"
16 defaultBranch = "main"
17)
18
19func TestCreatePullURL(t *testing.T) {
20
21 tt := map[string]struct {
22 repoName string
23 remote string
24 expectedURL string
25 }{
26 "not a fork": {
27 repoName: "knot-testing",
28 remote: "",
29 expectedURL: "https://tangled.org/willdot.net/knot-testing/pulls/new?source=branch&sourceBranch=feature-abc&targetBranch=main",
30 },
31 "is fork": {
32 repoName: "knot-testing-fork",
33 remote: "https://knot1.tangled.sh/did:plc:dadhhalkfcq3gucaq25hjqon/knot-testing",
34 expectedURL: "https://tangled.org/did:plc:dadhhalkfcq3gucaq25hjqon/knot-testing/pulls/new?fork=did%3Aplc%3Adadhhalkfcq3gucaq25hjqon%2Fknot-testing-fork&source=fork&sourceBranch=feature-abc&targetBranch=main",
35 },
36 "is fork on same knot": {
37 repoName: "knot-testing-fork",
38 remote: "file:///home/git/repositories/did:plc:ixran6dpypl5lslliiqceshs",
39 expectedURL: "https://tangled.org/did:plc:dadhhalkfcq3gucaq25hjqon/knot-testing/pulls/new?fork=did%3Aplc%3Adadhhalkfcq3gucaq25hjqon%2Fknot-testing-fork&source=fork&sourceBranch=feature-abc&targetBranch=main",
40 },
41 }
42
43 for name, tc := range tt {
44 t.Run(name, func(t *testing.T) {
45 database, err := db.Setup(t.Context(), ":memory:")
46 require.NoError(t, err)
47 err = database.StoreRepoKey("did:plc:ixran6dpypl5lslliiqceshs", []byte{}, "did:plc:dadhhalkfcq3gucaq25hjqon", "knot-testing")
48 require.NoError(t, err)
49
50 h := InternalHandle{
51 db: database,
52 }
53 res, err := h.createPullURL(appviewURL, tc.remote, user, userDID, tc.repoName, pushedBranch, defaultBranch)
54 require.NoError(t, err)
55
56 assert.Equal(t, tc.expectedURL, res)
57 })
58 }
59}