tests: add taskservice_create test

This commit is contained in:
Максим Слипенко 2024-12-26 19:20:54 +03:00
parent dc6da3cabb
commit 863d25b85f
5 changed files with 55 additions and 18 deletions

View file

@ -2,5 +2,5 @@
<rect width="1100" height="20" fill="#555"/>
<rect x="60" width="50" height="20" fill="#4c1"/>
<text x="5" y="14" fill="#fff" font-family="Verdana" font-size="11">coverage</text>
<text x="70" y="14" fill="#fff" font-family="Verdana" font-size="11">22.3%</text>
<text x="70" y="14" fill="#fff" font-family="Verdana" font-size="11">25.5%</text>
</svg>

Before

Width:  |  Height:  |  Size: 341 B

After

Width:  |  Height:  |  Size: 341 B

View file

@ -20,7 +20,7 @@ func (s *Service) Create(repo string) (*models.Task, error) {
FirstOrCreate(&altRepo)
task := models.Task{
RepoID: taskRepo.ID,
Repo: &taskRepo,
ALTRepo: altRepo,
Type: models.TypeUpsert,
Status: models.StatusPending,

View file

@ -0,0 +1,25 @@
package integration
import (
"testing"
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/taskservice"
"github.com/stretchr/testify/assert"
)
func TestTaskService_Create(t *testing.T) {
db := prepareDb(t)
config := prepareConfig()
service := taskservice.New(db, config)
repoName := "example-foo"
task, err := service.Create(repoName)
assert.NoError(t, err)
assert.Equal(t, uint(1), task.ID)
assert.Equal(t, repoName, task.Repo.Name)
assert.Equal(t, models.StatusPending, task.Status)
}

View file

@ -11,10 +11,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config"
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/taskservice"
)
@ -71,18 +68,9 @@ func createMultipartFileHeader(filePath string) *multipart.FileHeader {
return files[0]
}
func prepareDb(t *testing.T) *gorm.DB {
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
assert.NoError(t, err)
err = db.AutoMigrate(&models.Task{}, &models.GitRepoAltRepoTask{}, &models.RPMFile{})
assert.NoError(t, err)
return db
}
func TestTaskService_Upload(t *testing.T) {
db := prepareDb(t)
config := prepareConfig()
task := &models.Task{
ALTRepoID: 1,
@ -93,9 +81,6 @@ func TestTaskService_Upload(t *testing.T) {
db.Create(task)
config := &config.Config{
UploadDir: "./test_uploads",
}
os.MkdirAll(config.GetUploadDir(), os.ModePerm)
os.MkdirAll(path.Join(config.GetUploadDir(), "repo/Sisyphus"), os.ModePerm)

View file

@ -0,0 +1,27 @@
package integration
import (
"testing"
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config"
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
"github.com/stretchr/testify/assert"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func prepareDb(t *testing.T) *gorm.DB {
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
assert.NoError(t, err)
err = db.AutoMigrate(&models.Task{}, &models.GitRepoAltRepoTask{}, &models.RPMFile{})
assert.NoError(t, err)
return db
}
func prepareConfig() *config.Config {
return &config.Config{
UploadDir: "./test_uploads",
}
}