code.gitea.io/gitea@v1.21.7/tests/integration/api_repo_lfs_migrate_test.go (about) 1 // Copyright 2021 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package integration 5 6 import ( 7 "net/http" 8 "path" 9 "testing" 10 11 auth_model "code.gitea.io/gitea/models/auth" 12 "code.gitea.io/gitea/models/unittest" 13 user_model "code.gitea.io/gitea/models/user" 14 "code.gitea.io/gitea/modules/lfs" 15 "code.gitea.io/gitea/modules/setting" 16 api "code.gitea.io/gitea/modules/structs" 17 "code.gitea.io/gitea/services/migrations" 18 "code.gitea.io/gitea/tests" 19 20 "github.com/stretchr/testify/assert" 21 ) 22 23 func TestAPIRepoLFSMigrateLocal(t *testing.T) { 24 defer tests.PrepareTestEnv(t)() 25 26 oldImportLocalPaths := setting.ImportLocalPaths 27 oldAllowLocalNetworks := setting.Migrations.AllowLocalNetworks 28 setting.ImportLocalPaths = true 29 setting.Migrations.AllowLocalNetworks = true 30 assert.NoError(t, migrations.Init()) 31 32 user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) 33 session := loginUser(t, user.Name) 34 token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) 35 36 req := NewRequestWithJSON(t, "POST", "/api/v1/repos/migrate?token="+token, &api.MigrateRepoOptions{ 37 CloneAddr: path.Join(setting.RepoRootPath, "migration/lfs-test.git"), 38 RepoOwnerID: user.ID, 39 RepoName: "lfs-test-local", 40 LFS: true, 41 }) 42 resp := MakeRequest(t, req, NoExpectedStatus) 43 assert.EqualValues(t, http.StatusCreated, resp.Code) 44 45 store := lfs.NewContentStore() 46 ok, _ := store.Verify(lfs.Pointer{Oid: "fb8f7d8435968c4f82a726a92395be4d16f2f63116caf36c8ad35c60831ab041", Size: 6}) 47 assert.True(t, ok) 48 ok, _ = store.Verify(lfs.Pointer{Oid: "d6f175817f886ec6fbbc1515326465fa96c3bfd54a4ea06cfd6dbbd8340e0152", Size: 6}) 49 assert.True(t, ok) 50 51 setting.ImportLocalPaths = oldImportLocalPaths 52 setting.Migrations.AllowLocalNetworks = oldAllowLocalNetworks 53 assert.NoError(t, migrations.Init()) // reset old migration settings 54 }