From 780a9f9ef67c55726b8e8fc2123c9fb7e8d07b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 31 Aug 2022 17:24:53 +0200 Subject: [PATCH] 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. --- .../job_compilers/job_compilers_test.go | 33 ++++++------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/internal/manager/job_compilers/job_compilers_test.go b/internal/manager/job_compilers/job_compilers_test.go index 4e0abab6..debc62df 100644 --- a/internal/manager/job_compilers/job_compilers_test.go +++ b/internal/manager/job_compilers/job_compilers_test.go @@ -11,6 +11,7 @@ import ( "github.com/benbjohnson/clock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "git.blender.org/flamenco/pkg/api" ) @@ -73,12 +74,8 @@ func TestSimpleBlenderRenderHappy(t *testing.T) { sj := exampleSubmittedJob() aj, err := s.Compile(ctx, sj) - if err != nil { - t.Fatalf("job compiler failed: %v", err) - } - if aj == nil { - t.Fatalf("job compiler returned nil but no error") - } + require.NoError(t, err) + require.NotNil(t, aj) // Properties should be copied as-is. 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\\######" aj, err := s.Compile(ctx, sj) - if err != nil { - t.Fatalf("job compiler failed: %v", err) - } - if aj == nil { - t.Fatalf("job compiler returned nil but no error") - } + require.NoError(t, err) + require.NotNil(t, aj) // Properties should be copied as-is, so also with filesystem paths as-is. assert.Equal(t, sj.Name, aj.Name) @@ -212,7 +205,7 @@ func TestSimpleBlenderRenderOutputPathFieldReplacement(t *testing.T) { c := mockedClock(t) s, err := Load(c) - assert.NoError(t, err) + require.NoError(t, err) // Compiling a job should be really fast. 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/######" aj, err := s.Compile(ctx, sj) - if err != nil { - t.Fatalf("job compiler failed: %v", err) - } - if aj == nil { - t.Fatalf("job compiler returned nil but no error") - } + require.NoError(t, err) + require.NotNil(t, aj) // 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"]) @@ -263,13 +252,11 @@ func TestEtag(t *testing.T) { c := mockedClock(t) s, err := Load(c) - assert.NoError(t, err) + require.NoError(t, err) // Etags should be computed when the compiler VM is obtained. vm, err := s.compilerVMForJobType("echo-sleep-test") - if !assert.NoError(t, err) { - t.FailNow() - } + require.NoError(t, err) const expectEtag = "eba586e16d6b55baaa43e32f9e78ae514b457fee" assert.Equal(t, expectEtag, vm.jobTypeEtag)