Refactor some tests to use require.
instead of assert.
+ fail
The `require.XXX` functions are exactly the same as `assert.XXX` functions + directly failing the test, so this refactor simplifies the code quite a bit. Can be done in more areas than this. No functional changes.
This commit is contained in:
parent
0afde53209
commit
780a9f9ef6
@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
"github.com/benbjohnson/clock"
|
"github.com/benbjohnson/clock"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"git.blender.org/flamenco/pkg/api"
|
"git.blender.org/flamenco/pkg/api"
|
||||||
)
|
)
|
||||||
@ -73,12 +74,8 @@ func TestSimpleBlenderRenderHappy(t *testing.T) {
|
|||||||
|
|
||||||
sj := exampleSubmittedJob()
|
sj := exampleSubmittedJob()
|
||||||
aj, err := s.Compile(ctx, sj)
|
aj, err := s.Compile(ctx, sj)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("job compiler failed: %v", err)
|
require.NotNil(t, aj)
|
||||||
}
|
|
||||||
if aj == nil {
|
|
||||||
t.Fatalf("job compiler returned nil but no error")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Properties should be copied as-is.
|
// Properties should be copied as-is.
|
||||||
assert.Equal(t, sj.Name, aj.Name)
|
assert.Equal(t, sj.Name, aj.Name)
|
||||||
@ -157,12 +154,8 @@ func TestSimpleBlenderRenderWindowsPaths(t *testing.T) {
|
|||||||
sj.Settings.AdditionalProperties["render_output_path"] = "R:\\sprites\\farm_output\\promo\\square_ellie\\square_ellie.lighting_light_breakdown2\\######"
|
sj.Settings.AdditionalProperties["render_output_path"] = "R:\\sprites\\farm_output\\promo\\square_ellie\\square_ellie.lighting_light_breakdown2\\######"
|
||||||
|
|
||||||
aj, err := s.Compile(ctx, sj)
|
aj, err := s.Compile(ctx, sj)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("job compiler failed: %v", err)
|
require.NotNil(t, aj)
|
||||||
}
|
|
||||||
if aj == nil {
|
|
||||||
t.Fatalf("job compiler returned nil but no error")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Properties should be copied as-is, so also with filesystem paths as-is.
|
// Properties should be copied as-is, so also with filesystem paths as-is.
|
||||||
assert.Equal(t, sj.Name, aj.Name)
|
assert.Equal(t, sj.Name, aj.Name)
|
||||||
@ -212,7 +205,7 @@ func TestSimpleBlenderRenderOutputPathFieldReplacement(t *testing.T) {
|
|||||||
c := mockedClock(t)
|
c := mockedClock(t)
|
||||||
|
|
||||||
s, err := Load(c)
|
s, err := Load(c)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Compiling a job should be really fast.
|
// Compiling a job should be really fast.
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
|
||||||
@ -222,12 +215,8 @@ func TestSimpleBlenderRenderOutputPathFieldReplacement(t *testing.T) {
|
|||||||
sj.Settings.AdditionalProperties["render_output_path"] = "/root/{timestamp}/jobname/######"
|
sj.Settings.AdditionalProperties["render_output_path"] = "/root/{timestamp}/jobname/######"
|
||||||
|
|
||||||
aj, err := s.Compile(ctx, sj)
|
aj, err := s.Compile(ctx, sj)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("job compiler failed: %v", err)
|
require.NotNil(t, aj)
|
||||||
}
|
|
||||||
if aj == nil {
|
|
||||||
t.Fatalf("job compiler returned nil but no error")
|
|
||||||
}
|
|
||||||
|
|
||||||
// The job compiler should have replaced the {timestamp} and {ext} fields.
|
// The job compiler should have replaced the {timestamp} and {ext} fields.
|
||||||
assert.Equal(t, "/root/2006-01-02_090405/jobname/######", aj.Settings["render_output_path"])
|
assert.Equal(t, "/root/2006-01-02_090405/jobname/######", aj.Settings["render_output_path"])
|
||||||
@ -263,13 +252,11 @@ func TestEtag(t *testing.T) {
|
|||||||
c := mockedClock(t)
|
c := mockedClock(t)
|
||||||
|
|
||||||
s, err := Load(c)
|
s, err := Load(c)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Etags should be computed when the compiler VM is obtained.
|
// Etags should be computed when the compiler VM is obtained.
|
||||||
vm, err := s.compilerVMForJobType("echo-sleep-test")
|
vm, err := s.compilerVMForJobType("echo-sleep-test")
|
||||||
if !assert.NoError(t, err) {
|
require.NoError(t, err)
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
const expectEtag = "eba586e16d6b55baaa43e32f9e78ae514b457fee"
|
const expectEtag = "eba586e16d6b55baaa43e32f9e78ae514b457fee"
|
||||||
assert.Equal(t, expectEtag, vm.jobTypeEtag)
|
assert.Equal(t, expectEtag, vm.jobTypeEtag)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user