diff --git a/coverage-badge.svg b/coverage-badge.svg
index 8d2c133..3138aa8 100644
--- a/coverage-badge.svg
+++ b/coverage-badge.svg
@@ -2,5 +2,5 @@
coverage
- 25.5%
+ 29.0%
diff --git a/tests/integration/taskservice_create_test.go b/tests/integration/taskservice_create_test.go
index dffbc85..3a644af 100644
--- a/tests/integration/taskservice_create_test.go
+++ b/tests/integration/taskservice_create_test.go
@@ -3,9 +3,10 @@ package integration
import (
"testing"
+ "github.com/stretchr/testify/assert"
+
"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) {
diff --git a/tests/integration/taskservice_upload_test.go b/tests/integration/taskservice_upload_test.go
index 5b29047..34a01c5 100644
--- a/tests/integration/taskservice_upload_test.go
+++ b/tests/integration/taskservice_upload_test.go
@@ -8,6 +8,7 @@ import (
"os"
"path"
"path/filepath"
+ "strconv"
"testing"
"github.com/stretchr/testify/assert"
@@ -68,46 +69,102 @@ func createMultipartFileHeader(filePath string) *multipart.FileHeader {
return files[0]
}
-func TestTaskService_Upload(t *testing.T) {
- db := prepareDb(t)
- config := prepareConfig()
-
- task := &models.Task{
- ALTRepoID: 1,
- RepoID: 1,
- Status: models.StatusPending,
- }
- task.ID = uint(1)
-
- db.Create(task)
-
- os.MkdirAll(config.GetUploadDir(), os.ModePerm)
- os.MkdirAll(path.Join(config.GetUploadDir(), "repo/Sisyphus"), os.ModePerm)
-
- service := taskservice.New(db, config)
-
- fileName := "example-foo-1.0.0-alt1.x86_64.rpm"
+func createTaskUploadInput(task *models.Task, fileName string) *taskservice.TaskUploadInput {
filePath := path.Join("./test_rpms/", fileName)
-
fileHeader := createMultipartFileHeader(filePath)
-
- input := &taskservice.TaskUploadInput{
- TaskID: "1",
+ return &taskservice.TaskUploadInput{
+ TaskID: strconv.FormatUint(uint64(task.ID), 10),
Files: []*multipart.FileHeader{fileHeader},
}
-
- // Вызываем метод Upload
- err := service.Upload(input)
- assert.NoError(t, err)
-
- // Проверяем, что задача обновлена
- var updatedTask models.Task
- db.First(&updatedTask, 1)
- assert.Equal(t, models.StatusCompleted, updatedTask.Status)
-
- // Проверяем, что файл добавлен в базу
- var rpmFiles []models.RPMFile
- db.Find(&rpmFiles)
- assert.Len(t, rpmFiles, 1)
- assert.Equal(t, fileName, rpmFiles[0].Filename)
+}
+
+func TestTaskService_Upload(t *testing.T) {
+ t.Run("Correct upload (new)", func(t *testing.T) {
+ db := prepareDb(t)
+ config := prepareConfig()
+ service := taskservice.New(db, config)
+
+ os.MkdirAll(config.GetUploadDir(), os.ModePerm)
+ os.MkdirAll(path.Join(config.GetUploadDir(), "repo/Sisyphus"), os.ModePerm)
+ defer os.RemoveAll(config.GetUploadDir())
+
+ task := &models.Task{
+ ALTRepoID: 1,
+ RepoID: 1,
+ Status: models.StatusPending,
+ }
+ task.ID = uint(1)
+ db.Create(task)
+
+ fileName := "example-foo-1.0.0-alt1.x86_64.rpm"
+
+ err := service.Upload(createTaskUploadInput(
+ task,
+ fileName,
+ ))
+ assert.NoError(t, err)
+
+ var updatedTask models.Task
+ db.First(&updatedTask, 1)
+ assert.Equal(t, models.StatusCompleted, updatedTask.Status)
+
+ var rpmFiles []models.RPMFile
+ db.Find(&rpmFiles)
+ assert.Len(t, rpmFiles, 1)
+ assert.Equal(t, fileName, rpmFiles[0].Filename)
+ })
+
+ t.Run("Incorrect upload (too old version)", func(t *testing.T) {
+ db := prepareDb(t)
+ config := prepareConfig()
+ service := taskservice.New(db, config)
+
+ os.MkdirAll(config.GetUploadDir(), os.ModePerm)
+ os.MkdirAll(path.Join(config.GetUploadDir(), "repo/Sisyphus"), os.ModePerm)
+ defer os.RemoveAll(config.GetUploadDir())
+
+ // ===
+
+ gitRepo := &models.GitRepo{
+ Name: "example-foo",
+ }
+
+ altRepo := &models.ALTRepo{
+ Name: "Sisyphus",
+ }
+
+ db.Debug().Create(&models.GitRepoAltRepoTask{
+ Repo: gitRepo,
+ ALTRepo: altRepo,
+ CurrentTask: &models.Task{
+ Status: models.StatusCompleted,
+ Files: []models.RPMFile{
+ {
+ Name: "example-foo",
+ Version: "1.0.0",
+ Release: "2",
+ Epoch: 0,
+ },
+ },
+ },
+ })
+
+ task := &models.Task{
+ Repo: gitRepo,
+ ALTRepo: *altRepo,
+ Status: models.StatusPending,
+ }
+ db.Create(task)
+
+ // ===
+
+ err := service.Upload(createTaskUploadInput(
+ task,
+ "example-foo-1.0.0-alt1.x86_64.rpm",
+ ))
+
+ var tooOldErr *taskservice.TooOldError
+ assert.ErrorAs(t, err, &tooOldErr)
+ assert.Equal(t, "example-foo is too old!", tooOldErr.Error())
+ })
}
diff --git a/tests/integration/utils.go b/tests/integration/utils.go
index 7773ccd..8b848fc 100644
--- a/tests/integration/utils.go
+++ b/tests/integration/utils.go
@@ -3,11 +3,12 @@ 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"
+
+ "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config"
+ "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
)
func prepareDb(t *testing.T) *gorm.DB {