-
Notifications
You must be signed in to change notification settings - Fork 432
Expand file tree
/
Copy pathllama-swap_test.go
More file actions
64 lines (53 loc) · 1.43 KB
/
Copy pathllama-swap_test.go
File metadata and controls
64 lines (53 loc) · 1.43 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
60
61
62
63
64
package main
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestRunValidate_ValidConfig(t *testing.T) {
dir := t.TempDir()
configPath := filepath.Join(dir, "config.yml")
require.NoError(t, os.WriteFile(configPath, []byte(`
models:
model1:
cmd: server --port ${PORT}
proxy: http://localhost:8080
`), 0644))
var buf strings.Builder
code := runValidate(configPath, "", &buf)
assert.Equal(t, 0, code)
assert.NotEmpty(t, buf.String())
assert.Contains(t, buf.String(), "config is valid")
}
func TestRunValidate_BrokenConfig(t *testing.T) {
dir := t.TempDir()
configPath := filepath.Join(dir, "config.yml")
require.NoError(t, os.WriteFile(configPath, []byte(`
models:
model1:
cmd: server --port ${PORT} ${UNKNOWN_MACRO}
proxy: http://localhost:8080
`), 0644))
var buf strings.Builder
code := runValidate(configPath, "", &buf)
assert.Equal(t, 1, code)
assert.NotEmpty(t, buf.String())
assert.Contains(t, buf.String(), "failed")
}
func TestRunValidate_ConfigDir(t *testing.T) {
dir := t.TempDir()
require.NoError(t, os.WriteFile(filepath.Join(dir, "a.yml"), []byte(`
models:
model1:
cmd: server --port ${PORT}
proxy: http://localhost:8080
`), 0644))
var buf strings.Builder
code := runValidate("", dir, &buf)
assert.Equal(t, 0, code)
assert.NotEmpty(t, buf.String())
assert.Contains(t, buf.String(), "config is valid")
}