2020-01-12 12:11:17 +00:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-01-12 12:11:17 +00:00
|
|
|
|
|
|
|
package repository
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-08-25 02:31:57 +00:00
|
|
|
activities_model "code.gitea.io/gitea/models/activities"
|
2021-11-18 17:42:27 +00:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2022-06-06 08:01:49 +00:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-12 14:36:47 +00:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2020-01-12 12:11:17 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-07-30 19:41:10 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-01-12 12:11:17 +00:00
|
|
|
)
|
|
|
|
|
2022-06-06 08:01:49 +00:00
|
|
|
func TestUpdateRepositoryVisibilityChanged(t *testing.T) {
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2022-06-06 08:01:49 +00:00
|
|
|
|
|
|
|
// Get sample repo and change visibility
|
2022-12-03 02:48:26 +00:00
|
|
|
repo, err := repo_model.GetRepositoryByID(db.DefaultContext, 9)
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, err)
|
2022-06-06 08:01:49 +00:00
|
|
|
repo.IsPrivate = true
|
|
|
|
|
|
|
|
// Update it
|
|
|
|
err = UpdateRepository(db.DefaultContext, repo, true)
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, err)
|
2022-06-06 08:01:49 +00:00
|
|
|
|
|
|
|
// Check visibility of action has become private
|
2022-08-25 02:31:57 +00:00
|
|
|
act := activities_model.Action{}
|
2022-06-06 08:01:49 +00:00
|
|
|
_, err = db.GetEngine(db.DefaultContext).ID(3).Get(&act)
|
|
|
|
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, err)
|
2022-06-06 08:01:49 +00:00
|
|
|
assert.True(t, act.IsPrivate)
|
|
|
|
}
|
2023-01-13 18:54:02 +00:00
|
|
|
|
|
|
|
func TestGetDirectorySize(t *testing.T) {
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2023-01-13 18:54:02 +00:00
|
|
|
repo, err := repo_model.GetRepositoryByID(db.DefaultContext, 1)
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, err)
|
2023-01-13 18:54:02 +00:00
|
|
|
|
|
|
|
size, err := getDirectorySize(repo.RepoPath())
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, err)
|
2023-01-13 18:54:02 +00:00
|
|
|
assert.EqualValues(t, size, repo.Size)
|
|
|
|
}
|