-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathmain_test.go
More file actions
92 lines (86 loc) · 1.8 KB
/
main_test.go
File metadata and controls
92 lines (86 loc) · 1.8 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"testing"
"github.com/docker/model-runner/pkg/inference/backends/llamacpp"
)
func TestCreateLlamaCppConfigFromEnv(t *testing.T) {
tests := []struct {
name string
llamaArgs string
wantErr bool
}{
{
name: "empty args",
llamaArgs: "",
wantErr: false,
},
{
name: "valid args",
llamaArgs: "--threads 4 --ctx-size 2048",
wantErr: false,
},
{
name: "disallowed model arg",
llamaArgs: "--model test.gguf",
wantErr: true,
},
{
name: "disallowed host arg",
llamaArgs: "--host localhost:8080",
wantErr: true,
},
{
name: "disallowed embeddings arg",
llamaArgs: "--embeddings",
wantErr: true,
},
{
name: "disallowed mmproj arg",
llamaArgs: "--mmproj test.mmproj",
wantErr: true,
},
{
name: "multiple disallowed args",
llamaArgs: "--model test.gguf --host localhost:8080",
wantErr: true,
},
{
name: "quoted args",
llamaArgs: "--prompt \"Hello, world!\" --threads 4",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.llamaArgs != "" {
t.Setenv("LLAMA_ARGS", tt.llamaArgs)
}
cfg, err := createLlamaCppConfigFromEnv()
if tt.wantErr {
if err == nil {
t.Error("expected error, got nil")
}
return
}
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if tt.llamaArgs == "" {
if cfg != nil {
t.Error("expected nil config for empty args")
}
} else {
llamaConfig, ok := cfg.(*llamacpp.Config)
if !ok {
t.Fatalf("expected *llamacpp.Config, got %T", cfg)
}
if llamaConfig == nil {
t.Fatal("expected non-nil config")
}
if len(llamaConfig.Args) == 0 {
t.Error("expected non-empty args")
}
}
})
}
}