aboutsummaryrefslogtreecommitdiff
path: root/integrations/projectbase_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'integrations/projectbase_test.go')
-rw-r--r--integrations/projectbase_test.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/integrations/projectbase_test.go b/integrations/projectbase_test.go
new file mode 100644
index 000000000..48d8f7b81
--- /dev/null
+++ b/integrations/projectbase_test.go
@@ -0,0 +1,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)
+ })
+}