tests: add taskservice_create test
This commit is contained in:
parent
dc6da3cabb
commit
863d25b85f
5 changed files with 55 additions and 18 deletions
|
@ -2,5 +2,5 @@
|
||||||
<rect width="1100" height="20" fill="#555"/>
|
<rect width="1100" height="20" fill="#555"/>
|
||||||
<rect x="60" width="50" height="20" fill="#4c1"/>
|
<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="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>
|
</svg>
|
||||||
|
|
Before Width: | Height: | Size: 341 B After Width: | Height: | Size: 341 B |
|
@ -20,7 +20,7 @@ func (s *Service) Create(repo string) (*models.Task, error) {
|
||||||
FirstOrCreate(&altRepo)
|
FirstOrCreate(&altRepo)
|
||||||
|
|
||||||
task := models.Task{
|
task := models.Task{
|
||||||
RepoID: taskRepo.ID,
|
Repo: &taskRepo,
|
||||||
ALTRepo: altRepo,
|
ALTRepo: altRepo,
|
||||||
Type: models.TypeUpsert,
|
Type: models.TypeUpsert,
|
||||||
Status: models.StatusPending,
|
Status: models.StatusPending,
|
||||||
|
|
25
tests/integration/taskservice_create_test.go
Normal file
25
tests/integration/taskservice_create_test.go
Normal 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)
|
||||||
|
}
|
|
@ -11,10 +11,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"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/models"
|
||||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/taskservice"
|
"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]
|
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) {
|
func TestTaskService_Upload(t *testing.T) {
|
||||||
db := prepareDb(t)
|
db := prepareDb(t)
|
||||||
|
config := prepareConfig()
|
||||||
|
|
||||||
task := &models.Task{
|
task := &models.Task{
|
||||||
ALTRepoID: 1,
|
ALTRepoID: 1,
|
||||||
|
@ -93,9 +81,6 @@ func TestTaskService_Upload(t *testing.T) {
|
||||||
|
|
||||||
db.Create(task)
|
db.Create(task)
|
||||||
|
|
||||||
config := &config.Config{
|
|
||||||
UploadDir: "./test_uploads",
|
|
||||||
}
|
|
||||||
os.MkdirAll(config.GetUploadDir(), os.ModePerm)
|
os.MkdirAll(config.GetUploadDir(), os.ModePerm)
|
||||||
os.MkdirAll(path.Join(config.GetUploadDir(), "repo/Sisyphus"), os.ModePerm)
|
os.MkdirAll(path.Join(config.GetUploadDir(), "repo/Sisyphus"), os.ModePerm)
|
||||||
|
|
||||||
|
|
27
tests/integration/utils.go
Normal file
27
tests/integration/utils.go
Normal 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",
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue