|
4 | 4 | package integration |
5 | 5 |
|
6 | 6 | import ( |
| 7 | +"context" |
| 8 | +"fmt" |
7 | 9 | "net/http" |
| 10 | +"strings" |
8 | 11 | "testing" |
9 | 12 |
|
| 13 | +repo_model "code.gitea.io/gitea/models/repo" |
| 14 | +"code.gitea.io/gitea/models/unittest" |
| 15 | +user_model "code.gitea.io/gitea/models/user" |
| 16 | +"code.gitea.io/gitea/modules/lfs" |
| 17 | +api "code.gitea.io/gitea/modules/structs" |
10 | 18 | "code.gitea.io/gitea/tests" |
11 | 19 |
|
12 | 20 | "github.com/stretchr/testify/assert" |
| 21 | +"github.com/stretchr/testify/require" |
13 | 22 | ) |
14 | 23 |
|
15 | 24 | // check that files stored in LFS render properly in the web UI |
@@ -81,3 +90,56 @@ func TestLFSRender(t *testing.T) { |
81 | 90 | assert.Contains(t, content, "Testing READMEs in LFS") |
82 | 91 | }) |
83 | 92 | } |
| 93 | + |
| 94 | +// TestLFSLockView tests the LFS lock view on settings page of repositories |
| 95 | +func TestLFSLockView(t *testing.T) { |
| 96 | +defer tests.PrepareTestEnv(t)() |
| 97 | + |
| 98 | +user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) // in org 3 |
| 99 | +repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3}) // own by org 3 |
| 100 | +session := loginUser(t, user2.Name) |
| 101 | + |
| 102 | +// create a lock |
| 103 | +lockPath := "test_lfs_lock_view.zip" |
| 104 | +lockID := "" |
| 105 | +{ |
| 106 | +req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/%s.git/info/lfs/locks", repo3.FullName()), map[string]string{"path": lockPath}) |
| 107 | +req.Header.Set("Accept", lfs.AcceptHeader) |
| 108 | +req.Header.Set("Content-Type", lfs.MediaType) |
| 109 | +resp := session.MakeRequest(t, req, http.StatusCreated) |
| 110 | +lockResp := &api.LFSLockResponse{} |
| 111 | +DecodeJSON(t, resp, lockResp) |
| 112 | +lockID = lockResp.Lock.ID |
| 113 | +} |
| 114 | +defer func() { |
| 115 | +// release the lock |
| 116 | +req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/%s.git/info/lfs/locks/%s/unlock", repo3.FullName(), lockID), map[string]string{}) |
| 117 | +req.Header.Set("Accept", lfs.AcceptHeader) |
| 118 | +req.Header.Set("Content-Type", lfs.MediaType) |
| 119 | +session.MakeRequest(t, req, http.StatusOK) |
| 120 | +}() |
| 121 | + |
| 122 | +t.Run("owner name", func(t *testing.T) { |
| 123 | +defer tests.PrintCurrentTest(t)() |
| 124 | + |
| 125 | +// make sure the display names are different, or the test is meaningless |
| 126 | +require.NoError(t, repo3.LoadOwner(context.Background())) |
| 127 | +require.NotEqual(t, user2.DisplayName(), repo3.Owner.DisplayName()) |
| 128 | + |
| 129 | +req := NewRequest(t, "GET", fmt.Sprintf("/%s/settings/lfs/locks", repo3.FullName())) |
| 130 | +resp := session.MakeRequest(t, req, http.StatusOK) |
| 131 | + |
| 132 | +doc := NewHTMLParser(t, resp.Body).doc |
| 133 | + |
| 134 | +tr := doc.Find("table#lfs-files-locks-table tbody tr") |
| 135 | +require.Equal(t, 1, tr.Length()) |
| 136 | + |
| 137 | +td := tr.First().Find("td") |
| 138 | +require.Equal(t, 4, td.Length()) |
| 139 | + |
| 140 | +// path |
| 141 | +assert.Equal(t, lockPath, strings.TrimSpace(td.Eq(0).Text())) |
| 142 | +// owner name |
| 143 | +assert.Equal(t, user2.DisplayName(), strings.TrimSpace(td.Eq(1).Text())) |
| 144 | +}) |
| 145 | +} |
0 commit comments