Semaphore/db/bolt/Task_test.go

97 lines
1.7 KiB
Go
Raw Permalink Normal View History

package bolt
import (
"github.com/semaphoreui/semaphore/db"
"testing"
)
func TestTask_GetVersion(t *testing.T) {
VERSION := "1.54.48"
invID := 0
store := CreateTestStore()
build, err := store.CreateTemplate(db.Template{
ProjectID: 0,
Type: db.TemplateBuild,
Name: "Build",
Playbook: "build.yml",
InventoryID: &invID,
})
if err != nil {
t.Fatal(err)
}
deploy, err := store.CreateTemplate(db.Template{
ProjectID: 0,
Type: db.TemplateDeploy,
BuildTemplateID: &build.ID,
2022-02-03 08:05:13 +01:00
Name: "Deploy",
Playbook: "deploy.yml",
InventoryID: &invID,
})
if err != nil {
t.Fatal(err)
}
deploy2, err := store.CreateTemplate(db.Template{
ProjectID: 0,
Type: db.TemplateDeploy,
BuildTemplateID: &deploy.ID,
2022-02-03 08:05:13 +01:00
Name: "Deploy2",
Playbook: "deploy2.yml",
InventoryID: &invID,
})
if err != nil {
t.Fatal(err)
}
buildTask, err := store.CreateTask(db.Task{
ProjectID: 0,
TemplateID: build.ID,
Version: &VERSION,
2024-06-30 09:48:36 +02:00
}, 0)
if err != nil {
t.Fatal(err)
}
deployTask, err := store.CreateTask(db.Task{
ProjectID: 0,
TemplateID: deploy.ID,
BuildTaskID: &buildTask.ID,
2024-06-30 09:48:36 +02:00
}, 0)
if err != nil {
t.Fatal(err)
}
deploy2Task, err := store.CreateTask(db.Task{
ProjectID: 0,
TemplateID: deploy2.ID,
BuildTaskID: &deployTask.ID,
2024-06-30 09:48:36 +02:00
}, 0)
if err != nil {
t.Fatal(err)
}
version := deployTask.GetIncomingVersion(store)
if version == nil {
t.Fatal()
return
}
if *version != VERSION {
t.Fatal()
return
}
version = deploy2Task.GetIncomingVersion(store)
if version == nil {
t.Fatal()
return
}
if *version != VERSION {
t.Fatal()
return
}
}