mirror of
https://github.com/thomiceli/opengist.git
synced 2025-07-09 01:18:04 +02:00
Set gist visibility via Git push options (#215)
This commit is contained in:
71
internal/git/test_funcs.go
Normal file
71
internal/git/test_funcs.go
Normal file
@ -0,0 +1,71 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/thomiceli/opengist/internal/config"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func SetupTest(t *testing.T) {
|
||||
_ = os.Setenv("OPENGIST_SKIP_GIT_HOOKS", "1")
|
||||
|
||||
err := config.InitConfig("", io.Discard)
|
||||
require.NoError(t, err, "Could not init config")
|
||||
|
||||
err = os.MkdirAll(path.Join(config.GetHomeDir(), "tests"), 0755)
|
||||
ReposDirectory = path.Join("tests")
|
||||
require.NoError(t, err)
|
||||
|
||||
err = os.MkdirAll(filepath.Join(config.GetHomeDir(), "tmp", "repos"), 0755)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = InitRepository("thomas", "gist1")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TeardownTest(t *testing.T) {
|
||||
err := os.RemoveAll(path.Join(config.GetHomeDir(), "tests"))
|
||||
require.NoError(t, err, "Could not remove repos directory")
|
||||
}
|
||||
|
||||
func CommitToBare(t *testing.T, user string, gist string, files map[string]string) {
|
||||
err := CloneTmp(user, gist, gist, "thomas@mail.com", true)
|
||||
require.NoError(t, err, "Could not clone repository")
|
||||
|
||||
if len(files) > 0 {
|
||||
for filename, content := range files {
|
||||
if strings.Contains(filename, "/") {
|
||||
dir := filepath.Dir(filename)
|
||||
err := os.MkdirAll(filepath.Join(TmpRepositoryPath(gist), dir), os.ModePerm)
|
||||
require.NoError(t, err, "Could not create directory")
|
||||
}
|
||||
_ = os.WriteFile(filepath.Join(TmpRepositoryPath(gist), filename), []byte(content), 0644)
|
||||
|
||||
if err := AddAll(gist); err != nil {
|
||||
require.NoError(t, err, "Could not add all to repository")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := CommitRepository(gist, user, "thomas@mail.com"); err != nil {
|
||||
require.NoError(t, err, "Could not commit to repository")
|
||||
}
|
||||
|
||||
if err := Push(gist); err != nil {
|
||||
require.NoError(t, err, "Could not push to repository")
|
||||
}
|
||||
}
|
||||
|
||||
func LastHashOfCommit(t *testing.T, user string, gist string) string {
|
||||
cmd := exec.Command("git", "rev-parse", "HEAD")
|
||||
cmd.Dir = RepositoryPath(user, gist)
|
||||
out, err := cmd.Output()
|
||||
require.NoError(t, err, "Could not run git command")
|
||||
return strings.TrimSpace(string(out))
|
||||
}
|
Reference in New Issue
Block a user