
Replace old used-to-be-GORM datastructures (#104305) with sqlc-generated structs. This also makes it possible to use more specific structs that are more taylored to the specific queries, increasing efficiency. This commit mostly deals with workers, including the sleep schedule and task scheduler. Functional changes are kept to a minimum, as the API still serves the same data. Because this work covers so much of Flamenco's code, it's been split up into different commits. Each commit brings Flamenco to a state where it compiles and unit tests pass. Only the result of the final commit has actually been tested properly. Ref: #104343
35 lines
979 B
Go
35 lines
979 B
Go
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
package persistence
|
|
|
|
import (
|
|
"database/sql"
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestNotFoundErrors(t *testing.T) {
|
|
assert.ErrorIs(t, ErrJobNotFound, sql.ErrNoRows)
|
|
assert.ErrorIs(t, ErrTaskNotFound, sql.ErrNoRows)
|
|
|
|
assert.Contains(t, ErrJobNotFound.Error(), "job")
|
|
assert.Contains(t, ErrTaskNotFound.Error(), "task")
|
|
}
|
|
|
|
func TestTranslateJobError(t *testing.T) {
|
|
assert.Nil(t, translateJobError(nil))
|
|
assert.Equal(t, ErrJobNotFound, translateJobError(sql.ErrNoRows))
|
|
|
|
otherError := errors.New("this error is not special for this function")
|
|
assert.Equal(t, otherError, translateJobError(otherError))
|
|
}
|
|
|
|
func TestTranslateTaskError(t *testing.T) {
|
|
assert.Nil(t, translateTaskError(nil))
|
|
assert.Equal(t, ErrTaskNotFound, translateTaskError(sql.ErrNoRows))
|
|
|
|
otherError := errors.New("this error is not special for this function")
|
|
assert.Equal(t, otherError, translateTaskError(otherError))
|
|
}
|