From 6ec4c258a08667b498274234e5c158ff13c166d9 Mon Sep 17 00:00:00 2001 From: Fritz Duchardt Date: Sun, 12 Nov 2023 11:26:33 +0100 Subject: [PATCH] fix: introduced require lib to test Signed-off-by: Fritz Duchardt --- test/e2e/directory_flag_test.go | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/test/e2e/directory_flag_test.go b/test/e2e/directory_flag_test.go index a102eead..0906f2b6 100644 --- a/test/e2e/directory_flag_test.go +++ b/test/e2e/directory_flag_test.go @@ -4,6 +4,7 @@ package e2e import ( + "github.com/stretchr/testify/require" "os" "testing" ) @@ -18,25 +19,12 @@ func TestUseDirectory(t *testing.T) { reset := func() { // Make sure state is reset _, err := vendir.RunWithOpts([]string{"sync"}, RunOpts{Dir: path}) - if err != nil { - t.Fatalf("Expected no err") - } + require.NoError(t, err) } checkFileContent := func(filePath string, expectedContent string) { file, err := os.ReadFile(path + filePath) - if err != nil { - t.Fatalf("Expected no err") - } - if string(file) != expectedContent { - t.Fatalf("Expected file contents to be known: %s", string(file)) - } - } - - checkFileExists := func(filePath string) { - _, err := os.Stat(path + filePath) - if err != nil { - t.Fatalf("Expected no err") - } + require.NoError(t, err) + require.EqualValues(t, string(file), expectedContent) } // Sync with directory flag @@ -49,13 +37,11 @@ func TestUseDirectory(t *testing.T) { // Sync with directory flag and local-dir-dev _, err = vendir.RunWithOpts([]string{"sync", "--directory", "vendor/local-dir=local-dir-dev"}, RunOpts{Dir: path}) - if err != nil { - t.Fatalf("Expected no err") - } + require.NoError(t, err) checkFileContent("/vendor/local-dir/file.txt", "file-dir-dev\n") // Lock file check - checkFileExists("/vendir.lock.yml") + require.FileExists(t, path+"/vendir.lock.yml") // Final regular sync to make sure nothing in vendir was deleted (manual syncs would fail). reset()