2022-01-27 13:44:35 +01:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ansible-semaphore/semaphore/util"
|
|
|
|
"math/rand"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRepository_GetSchema(t *testing.T) {
|
|
|
|
repo := Repository{GitURL: "https://example.com/hello/world"}
|
2022-03-30 17:31:00 +02:00
|
|
|
schema := repo.GetType()
|
2022-01-27 13:44:35 +01:00
|
|
|
if schema != "https" {
|
|
|
|
t.Fatal()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRepository_ClearCache(t *testing.T) {
|
|
|
|
util.Config = &util.ConfigType{
|
|
|
|
TmpPath: path.Join(os.TempDir(), util.RandString(rand.Intn(10-4)+4)),
|
|
|
|
}
|
|
|
|
repoDir := path.Join(util.Config.TmpPath, "repository_123_55")
|
|
|
|
err := os.MkdirAll(repoDir, 0755)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
repo := Repository{ID: 123}
|
|
|
|
err = repo.ClearCache()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
_, err = os.Stat(repoDir)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("repo directory not deleted")
|
|
|
|
}
|
|
|
|
if !os.IsNotExist(err) {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|