File: pullrequest_test.go

package info (click to toggle)
golang-code.forgejo-f3-gof3 3.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,952 kB
  • sloc: sh: 100; makefile: 65
file content (71 lines) | stat: -rw-r--r-- 2,767 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright Earl Warren <contact@earl-warren.org>
// Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT

package f3

import (
	"context"
	"testing"

	filesystem_options "code.forgejo.org/f3/gof3/v3/forges/filesystem/options"
	"code.forgejo.org/f3/gof3/v3/options"
	"code.forgejo.org/f3/gof3/v3/path"
	"code.forgejo.org/f3/gof3/v3/tree/generic"
	tests_forge "code.forgejo.org/f3/gof3/v3/tree/tests/f3/forge"

	"github.com/stretchr/testify/assert"
)

func TestF3PullRequest(t *testing.T) {
	ctx := context.Background()

	for _, factory := range tests_forge.GetFactories() {
		testForge := factory()
		t.Run(testForge.GetName(), func(t *testing.T) {
			// testCase.options will t.Skip if the forge instance is not up
			forgeWriteOptions := testForge.NewOptions(t)
			forgeReadOptions := testForge.NewOptions(t)
			forgeReadOptions.(options.URLInterface).SetURL(forgeWriteOptions.(options.URLInterface).GetURL())

			fixtureTree := generic.GetFactory("f3")(ctx, tests_forge.GetFactory(filesystem_options.Name)().NewOptions(t))
			fixtureTree.Trace("======= build fixture")
			TreeBuildPartial(t, "F3PullRequest"+testForge.GetName(), testForge.GetKindExceptions(), forgeWriteOptions, fixtureTree)

			// craft a PR condition depending on testCase

			fixtureTree.Trace("======= mirror fixture to forge")

			forgeWriteTree := generic.GetFactory("f3")(ctx, forgeWriteOptions)
			generic.TreeMirror(ctx, fixtureTree, forgeWriteTree, generic.NewPathFromString(""), generic.NewMirrorOptions())

			paths := []string{"/forge/users/10111/projects/74823/repositories", "/forge/users/10111/projects/74823/pull_requests"}
			pathPairs := make([][2]path.Path, 0, 5)
			for _, p := range paths {
				p := generic.NewPathFromString(p)
				pathPairs = append(pathPairs, [2]path.Path{p, generic.TreePathRemap(ctx, fixtureTree, p, forgeWriteTree)})
			}

			fixtureTree.Trace("======= read from forge")

			forgeReadTree := generic.GetFactory("f3")(ctx, forgeReadOptions)
			forgeReadTree.WalkAndGet(ctx, generic.NewWalkOptions(nil))

			fixtureTree.Trace("======= mirror forge to filesystem")

			verificationTree := generic.GetFactory("f3")(ctx, tests_forge.GetFactory(filesystem_options.Name)().NewOptions(t))

			for _, pathPair := range pathPairs {
				generic.TreeMirror(ctx, forgeReadTree, verificationTree, pathPair[1], generic.NewMirrorOptions())
			}

			fixtureTree.Trace("======= compare fixture with forge mirrored to filesystem")
			for _, pathPair := range pathPairs {
				fixtureTree.Trace("======= compare %s with %s", pathPair[0], pathPair[1])
				assert.True(t, generic.TreeCompare(ctx, fixtureTree, pathPair[0], verificationTree, pathPair[1]))
			}

			TreeDelete(t, testForge.GetNonTestUsers(), forgeWriteOptions, forgeWriteTree)
		})
	}
}