You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

migrate_test.go 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package integrations
  5. import (
  6. "os"
  7. "testing"
  8. "code.gitea.io/gitea/models/unittest"
  9. user_model "code.gitea.io/gitea/models/user"
  10. "code.gitea.io/gitea/modules/setting"
  11. "code.gitea.io/gitea/services/migrations"
  12. "github.com/stretchr/testify/assert"
  13. )
  14. func TestMigrateLocalPath(t *testing.T) {
  15. assert.NoError(t, unittest.PrepareTestDatabase())
  16. adminUser := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user1"}).(*user_model.User)
  17. old := setting.ImportLocalPaths
  18. setting.ImportLocalPaths = true
  19. lowercasePath, err := os.MkdirTemp("", "lowercase") // may not be lowercase because MkdirTemp creates a random directory name which may be mixedcase
  20. assert.NoError(t, err)
  21. defer os.RemoveAll(lowercasePath)
  22. err = migrations.IsMigrateURLAllowed(lowercasePath, adminUser)
  23. assert.NoError(t, err, "case lowercase path")
  24. mixedcasePath, err := os.MkdirTemp("", "mIxeDCaSe")
  25. assert.NoError(t, err)
  26. defer os.RemoveAll(mixedcasePath)
  27. err = migrations.IsMigrateURLAllowed(mixedcasePath, adminUser)
  28. assert.NoError(t, err, "case mixedcase path")
  29. setting.ImportLocalPaths = old
  30. }