MCPcopy Create free account
hub / github.com/gogs/gogs / Test_CreateRepository_PreventDeletion

Function Test_CreateRepository_PreventDeletion

internal/database/repo_test.go:61–85  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

59}
60
61func Test_CreateRepository_PreventDeletion(t *testing.T) {
62 tempRepositoryRoot := filepath.Join(os.TempDir(), "createRepository-tempRepositoryRoot")
63 conf.SetMockRepository(
64 t,
65 conf.RepositoryOpts{
66 Root: tempRepositoryRoot,
67 },
68 )
69 err := os.RemoveAll(tempRepositoryRoot)
70 require.NoError(t, err)
71 defer func() { _ = os.RemoveAll(tempRepositoryRoot) }()
72
73 owner := &User{Name: "testuser"}
74 opts := CreateRepoOptionsLegacy{Name: "safety-test"}
75 repoPath := RepoPath(owner.Name, opts.Name)
76 require.NoError(t, os.MkdirAll(repoPath, os.ModePerm))
77
78 canary := filepath.Join(repoPath, "canary.txt")
79 require.NoError(t, os.WriteFile(canary, []byte("should survive"), 0o644))
80
81 _, err = CreateRepository(owner, owner, opts)
82 require.Error(t, err)
83 assert.Contains(t, err.Error(), "repository directory already exists")
84 assert.True(t, osutil.Exist(canary))
85}

Callers

nothing calls this directly

Calls 5

SetMockRepositoryFunction · 0.92
ExistFunction · 0.92
RepoPathFunction · 0.85
CreateRepositoryFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected