aboutsummaryrefslogtreecommitdiff
path: root/integrations/projectbase_test.go
blob: 48d8f7b819fc9192dc9da71817f800cba2454a07 (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
61
62
63
64
65
66
67
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package integrations

import (
	"context"
	"fmt"
	"net/url"
	"sort"
	"testing"

	repo_model "code.gitea.io/gitea/models/repo"
	"code.gitea.io/gitea/models/unittest"
	user_model "code.gitea.io/gitea/models/user"
	"code.gitea.io/gitea/modules/git"
	"code.gitea.io/gitea/modules/setting"
	"code.gitea.io/gitea/services/migrations"
	projectbase_service "code.gitea.io/gitea/services/projectbase"

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

func TestProjectBaseUpdate(t *testing.T) {
	onGiteaRun(t, func(t *testing.T, u *url.URL) {
		AllowedDomains := setting.Migrations.AllowedDomains
		setting.Migrations.AllowedDomains = "loopback"
		AllowLocalNetworks := setting.Migrations.AllowLocalNetworks
		setting.Migrations.AllowLocalNetworks = true
		setting.Database.LogSQL = true
		AppVer := setting.AppVer
		setting.AppVer = "1.15"
		defer func() {
			setting.Migrations.AllowedDomains = AllowedDomains
			setting.Migrations.AllowLocalNetworks = AllowLocalNetworks
			setting.Database.LogSQL = false
			setting.AppVer = AppVer
		}()

		assert.NoError(t, migrations.Init())

		reponame := "repo1"
		repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: reponame}).(*repo_model.Repository)
		repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
		session := loginUser(t, repoOwner.Name)
		token := getTokenForLoggedInUser(t, session)
		assert.False(t, repo.HasProjectBase())
		ctx := context.Background()
		assert.NoError(t, projectbase_service.InitProjectBase(ctx, repo))
		assert.True(t, repo.HasProjectBase())
		assert.NoError(t, projectbase_service.UpdateProjectBase(ctx, token, repo))

		gitRepo, err := git.OpenRepository(repo.ProjectBasePath())
		fmt.Println(repo.ProjectBasePath())
		assert.NoError(t, err)
		defer gitRepo.Close()
		files := []string{"repo.yml", "issue.yml", "comments"}
		filelist, err := gitRepo.LsTree("HEAD", files...)
		assert.NoError(t, err)
		sort.Strings(filelist)
		expected := files
		expected = append(expected, "")
		sort.Strings(expected)
		assert.Equal(t, expected, filelist)
	})
}