Add more tests (#241)

* add form builder tests

* lint

* add client tests

* lint

* add non-existent file test
This commit is contained in:
sashabaranov
2023-04-09 18:36:15 +04:00
committed by GitHub
parent 334ee6dbdd
commit 9a1ecf5f4a
5 changed files with 125 additions and 27 deletions

29
internal/test/helpers.go Normal file
View 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) }
}