Welcome to mirror list, hosted at ThFree Co, Russian Federation.

factory_test.go « gitlab « source « internal - gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 705fdc4718a70ccbce6846dde21b7fd8e61b9b7a (plain)
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
package gitlab

import (
	"testing"

	"github.com/stretchr/testify/require"

	"gitlab.com/gitlab-org/gitlab-pages/internal/serving/disk"
	"gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/api"
)

func TestFabricateLookupPath(t *testing.T) {
	t.Run("when lookup path is not a namespace project", func(t *testing.T) {
		lookup := api.LookupPath{Prefix: "/something"}

		path := fabricateLookupPath(1, lookup)

		require.Equal(t, path.Prefix, "/something")
		require.False(t, path.IsNamespaceProject)
	})

	t.Run("when lookup path is a namespace project", func(t *testing.T) {
		lookup := api.LookupPath{Prefix: "/"}

		path := fabricateLookupPath(2, lookup)

		require.Equal(t, path.Prefix, "/")
		require.True(t, path.IsNamespaceProject)
	})
}

func TestFabricateServing(t *testing.T) {
	t.Run("when lookup path requires disk serving", func(t *testing.T) {
		g := Gitlab{
			enableDisk: true,
		}

		lookup := api.LookupPath{
			Prefix: "/",
			Source: api.Source{Type: "file"},
		}
		srv, err := g.fabricateServing(lookup)
		require.NoError(t, err)
		require.IsType(t, &disk.Disk{}, srv)
	})

	t.Run("when lookup path requires disk serving but disk is disabled", func(t *testing.T) {
		g := Gitlab{
			enableDisk: false,
		}

		lookup := api.LookupPath{
			Prefix: "/",
			Source: api.Source{Type: "file"},
		}
		srv, err := g.fabricateServing(lookup)
		require.EqualError(t, err, ErrDiskDisabled.Error())
		require.Nil(t, srv)
	})
}