From 9b010490aea83308846779e395e4fc6d6fbe5fc7 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 27 Jun 2024 18:53:51 +0400 Subject: [PATCH] minor rework of test cases - we don't need to care about tokens - we need to care about existing/nonexisting newline at EOL when there's just a single line in the file --- internal/oonirun/v2_test.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/internal/oonirun/v2_test.go b/internal/oonirun/v2_test.go index d75761c4d..63d3075af 100644 --- a/internal/oonirun/v2_test.go +++ b/internal/oonirun/v2_test.go @@ -710,7 +710,7 @@ func Test_readFirstLineFromFile(t *testing.T) { } }) - t.Run("return first line with a file of one line", func(t *testing.T) { + t.Run("return first line with a file of one line without EOL", func(t *testing.T) { f, err := os.CreateTemp(t.TempDir(), "auth-") if err != nil { t.Fatal(err) @@ -730,16 +730,14 @@ func Test_readFirstLineFromFile(t *testing.T) { } }) - t.Run("return first line with a file of >1 line", func(t *testing.T) { + t.Run("return first line with a file of one line with EOL", func(t *testing.T) { f, err := os.CreateTemp(t.TempDir(), "auth-") if err != nil { t.Fatal(err) } token := "c2VjcmV0" // b64("secret") - f.Write([]byte(token)) - f.Write([]byte("\n")) - f.Write([]byte("something\nelse\nand\nsomething\nmore")) + f.Write(append([]byte(token), '\n')) defer f.Close() defer os.Remove(f.Name()) @@ -752,7 +750,7 @@ func Test_readFirstLineFromFile(t *testing.T) { } }) - t.Run("return only first token if >1 is found", func(t *testing.T) { + t.Run("return first line with a file of >1 line", func(t *testing.T) { f, err := os.CreateTemp(t.TempDir(), "auth-") if err != nil { t.Fatal(err) @@ -761,7 +759,7 @@ func Test_readFirstLineFromFile(t *testing.T) { token := "c2VjcmV0" // b64("secret") f.Write([]byte(token)) f.Write([]byte("\n")) - f.Write([]byte(" antani\n")) + f.Write([]byte("something\nelse\nand\nsomething\nmore")) defer f.Close() defer os.Remove(f.Name()) @@ -797,5 +795,4 @@ func Test_readFirstLineFromFile(t *testing.T) { t.Fatal("expected err==nil") } }) - }