Add more tests (#241)
* add form builder tests * lint * add client tests * lint * add non-existent file test
This commit is contained in:
29
internal/test/helpers.go
Normal file
29
internal/test/helpers.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"github.com/sashabaranov/go-openai/internal/test/checks"
|
||||
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// CreateTestFile creates a fake file with "hello" as the content.
|
||||
func CreateTestFile(t *testing.T, path string) {
|
||||
file, err := os.Create(path)
|
||||
checks.NoError(t, err, "failed to create file")
|
||||
|
||||
if _, err = file.WriteString("hello"); err != nil {
|
||||
t.Fatalf("failed to write to file %v", err)
|
||||
}
|
||||
file.Close()
|
||||
}
|
||||
|
||||
// CreateTestDirectory creates a temporary folder which will be deleted when cleanup is called.
|
||||
func CreateTestDirectory(t *testing.T) (path string, cleanup func()) {
|
||||
t.Helper()
|
||||
|
||||
path, err := os.MkdirTemp(os.TempDir(), "")
|
||||
checks.NoError(t, err)
|
||||
|
||||
return path, func() { os.RemoveAll(path) }
|
||||
}
|
||||
Reference in New Issue
Block a user