code.gitea.io/gitea@v1.22.3/routers/api/v1/repo/repo_test.go (about) 1 // Copyright 2019 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package repo 5 6 import ( 7 "net/http" 8 "testing" 9 10 repo_model "code.gitea.io/gitea/models/repo" 11 "code.gitea.io/gitea/models/unittest" 12 api "code.gitea.io/gitea/modules/structs" 13 "code.gitea.io/gitea/modules/web" 14 "code.gitea.io/gitea/services/contexttest" 15 16 "github.com/stretchr/testify/assert" 17 ) 18 19 func TestRepoEdit(t *testing.T) { 20 unittest.PrepareTestEnv(t) 21 22 ctx, _ := contexttest.MockAPIContext(t, "user2/repo1") 23 contexttest.LoadRepo(t, ctx, 1) 24 contexttest.LoadUser(t, ctx, 2) 25 ctx.Repo.Owner = ctx.Doer 26 description := "new description" 27 website := "http://wwww.newwebsite.com" 28 private := true 29 hasIssues := false 30 hasWiki := false 31 defaultBranch := "master" 32 hasPullRequests := true 33 ignoreWhitespaceConflicts := true 34 allowMerge := false 35 allowRebase := false 36 allowRebaseMerge := false 37 allowSquashMerge := false 38 allowFastForwardOnlyMerge := false 39 archived := true 40 opts := api.EditRepoOption{ 41 Name: &ctx.Repo.Repository.Name, 42 Description: &description, 43 Website: &website, 44 Private: &private, 45 HasIssues: &hasIssues, 46 HasWiki: &hasWiki, 47 DefaultBranch: &defaultBranch, 48 HasPullRequests: &hasPullRequests, 49 IgnoreWhitespaceConflicts: &ignoreWhitespaceConflicts, 50 AllowMerge: &allowMerge, 51 AllowRebase: &allowRebase, 52 AllowRebaseMerge: &allowRebaseMerge, 53 AllowSquash: &allowSquashMerge, 54 AllowFastForwardOnly: &allowFastForwardOnlyMerge, 55 Archived: &archived, 56 } 57 58 web.SetForm(ctx, &opts) 59 Edit(ctx) 60 61 assert.EqualValues(t, http.StatusOK, ctx.Resp.Status()) 62 unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ 63 ID: 1, 64 }, unittest.Cond("name = ? AND is_archived = 1", *opts.Name)) 65 } 66 67 func TestRepoEditNameChange(t *testing.T) { 68 unittest.PrepareTestEnv(t) 69 70 ctx, _ := contexttest.MockAPIContext(t, "user2/repo1") 71 contexttest.LoadRepo(t, ctx, 1) 72 contexttest.LoadUser(t, ctx, 2) 73 ctx.Repo.Owner = ctx.Doer 74 name := "newname" 75 opts := api.EditRepoOption{ 76 Name: &name, 77 } 78 79 web.SetForm(ctx, &opts) 80 Edit(ctx) 81 assert.EqualValues(t, http.StatusOK, ctx.Resp.Status()) 82 83 unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ 84 ID: 1, 85 }, unittest.Cond("name = ?", opts.Name)) 86 }