-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre_sql_test.go
More file actions
59 lines (48 loc) · 1.7 KB
/
Copy pathpre_sql_test.go
File metadata and controls
59 lines (48 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package pistachio_test
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/winebarrel/pistachio"
)
func TestResolvePreSQL_DirectString(t *testing.T) {
got, err := pistachio.ResolvePreSQL("SELECT 1;", "")
require.NoError(t, err)
assert.Equal(t, "SELECT 1;", got)
}
func TestResolvePreSQL_File(t *testing.T) {
tmpFile := filepath.Join(t.TempDir(), "pre.sql")
require.NoError(t, os.WriteFile(tmpFile, []byte("SELECT 2;"), 0o644))
got, err := pistachio.ResolvePreSQL("", tmpFile)
require.NoError(t, err)
assert.Equal(t, "SELECT 2;", got)
}
func TestResolvePreSQL_DirectTakesPrecedence(t *testing.T) {
tmpFile := filepath.Join(t.TempDir(), "pre.sql")
require.NoError(t, os.WriteFile(tmpFile, []byte("SELECT 2;"), 0o644))
got, err := pistachio.ResolvePreSQL("SELECT 1;", tmpFile)
require.NoError(t, err)
assert.Equal(t, "SELECT 1;", got)
}
func TestResolvePreSQL_Empty(t *testing.T) {
got, err := pistachio.ResolvePreSQL("", "")
require.NoError(t, err)
assert.Empty(t, got)
}
func TestResolvePreSQL_FileNotFound(t *testing.T) {
_, err := pistachio.ResolvePreSQL("", "/nonexistent/pre.sql")
require.Error(t, err)
assert.Contains(t, err.Error(), "failed to read pre-SQL file")
}
func TestResolveConcurrentlyPreSQL_DirectString(t *testing.T) {
got, err := pistachio.ResolveConcurrentlyPreSQL("SET lock_timeout = '5s';", "")
require.NoError(t, err)
assert.Equal(t, "SET lock_timeout = '5s';", got)
}
func TestResolveConcurrentlyPreSQL_FileNotFound(t *testing.T) {
_, err := pistachio.ResolveConcurrentlyPreSQL("", "/nonexistent/pre.sql")
require.Error(t, err)
assert.Contains(t, err.Error(), "failed to read concurrently-pre-SQL file")
}