2022-01-19 21:42:08 +01:00
|
|
|
package bolt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ansible-semaphore/semaphore/db"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTask_GetVersion(t *testing.T) {
|
|
|
|
VERSION := "1.54.48"
|
|
|
|
|
2024-04-19 18:47:08 +02:00
|
|
|
invID := 0
|
|
|
|
|
2022-01-23 14:21:27 +01:00
|
|
|
store := CreateTestStore()
|
2022-01-19 21:42:08 +01:00
|
|
|
|
|
|
|
build, err := store.CreateTemplate(db.Template{
|
2024-04-19 18:47:08 +02:00
|
|
|
ProjectID: 0,
|
|
|
|
Type: db.TemplateBuild,
|
|
|
|
Name: "Build",
|
|
|
|
Playbook: "build.yml",
|
|
|
|
InventoryID: &invID,
|
2022-01-19 21:42:08 +01:00
|
|
|
})
|
|
|
|
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",
|
2022-01-19 21:42:08 +01:00
|
|
|
Playbook: "deploy.yml",
|
2024-04-19 18:47:08 +02:00
|
|
|
InventoryID: &invID,
|
2022-01-19 21:42:08 +01:00
|
|
|
})
|
|
|
|
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",
|
2022-01-19 21:42:08 +01:00
|
|
|
Playbook: "deploy2.yml",
|
2024-04-19 18:47:08 +02:00
|
|
|
InventoryID: &invID,
|
2022-01-19 21:42:08 +01:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
buildTask, err := store.CreateTask(db.Task{
|
|
|
|
ProjectID: 0,
|
|
|
|
TemplateID: build.ID,
|
|
|
|
Version: &VERSION,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
deployTask, err := store.CreateTask(db.Task{
|
|
|
|
ProjectID: 0,
|
|
|
|
TemplateID: deploy.ID,
|
|
|
|
BuildTaskID: &buildTask.ID,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
deploy2Task, err := store.CreateTask(db.Task{
|
|
|
|
ProjectID: 0,
|
|
|
|
TemplateID: deploy2.ID,
|
|
|
|
BuildTaskID: &deployTask.ID,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2022-11-18 23:23:30 +01:00
|
|
|
version := deployTask.GetIncomingVersion(store)
|
2022-01-19 22:49:33 +01:00
|
|
|
if version == nil {
|
|
|
|
t.Fatal()
|
|
|
|
return
|
2022-01-19 21:42:08 +01:00
|
|
|
}
|
2022-01-19 22:49:33 +01:00
|
|
|
if *version != VERSION {
|
2022-01-19 21:42:08 +01:00
|
|
|
t.Fatal()
|
2022-01-19 22:49:33 +01:00
|
|
|
return
|
2022-01-19 21:42:08 +01:00
|
|
|
}
|
|
|
|
|
2022-11-18 23:23:30 +01:00
|
|
|
version = deploy2Task.GetIncomingVersion(store)
|
2022-01-19 22:49:33 +01:00
|
|
|
if version == nil {
|
|
|
|
t.Fatal()
|
|
|
|
return
|
2022-01-19 21:42:08 +01:00
|
|
|
}
|
2022-01-19 22:49:33 +01:00
|
|
|
if *version != VERSION {
|
2022-01-19 21:42:08 +01:00
|
|
|
t.Fatal()
|
2022-01-19 22:49:33 +01:00
|
|
|
return
|
2022-01-19 21:42:08 +01:00
|
|
|
}
|
|
|
|
}
|