Skip to content

Commit

Permalink
minor rework of test cases
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
bassosimone committed Jun 27, 2024
1 parent 274961f commit 9b01049
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions internal/oonirun/v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())

Expand All @@ -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)
Expand All @@ -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())

Expand Down Expand Up @@ -797,5 +795,4 @@ func Test_readFirstLineFromFile(t *testing.T) {
t.Fatal("expected err==nil")
}
})

}

0 comments on commit 9b01049

Please sign in to comment.