Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ainghazal committed Jun 27, 2024
1 parent f1f63c9 commit d070106
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions internal/oonirun/v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,4 +690,46 @@ func Test_readFirstLineFromFile(t *testing.T) {
}
})

t.Run("return first line with a file of one line", func(t *testing.T) {
f, err := os.CreateTemp(t.TempDir(), "auth-")
if err != nil {
t.Fatal(err)
}

token := "asecret"
f.Write([]byte(token))
defer f.Close()
defer os.Remove(f.Name())

line, err := readFirstLineFromFile(f.Name())
if line != token {
t.Fatalf("expected %s, got %s", token, line)
}
if err != nil {
t.Fatal("expected err==nil")
}
})

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)
}

token := "asecret"
f.Write([]byte(token))
f.Write([]byte("\n"))
f.Write([]byte("something\nelse\nand\nsomething\nmore"))
defer f.Close()
defer os.Remove(f.Name())

line, err := readFirstLineFromFile(f.Name())
if line != token {
t.Fatalf("expected %s, got %s", token, line)
}
if err != nil {
t.Fatal("expected err==nil")
}
})

}

0 comments on commit d070106

Please sign in to comment.