Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
d721a02e
"src/libtorchaudio/rnnt/compute.cpp" did not exist on "2d99fee29efac7fcd09f679ed6f7f3379eaac512"
Unverified
Commit
d721a02e
authored
Feb 20, 2025
by
yuiseki
Committed by
GitHub
Feb 19, 2025
Browse files
test: add test cases for ListHandler (#9146)
parent
778603a8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
0 deletions
+91
-0
cmd/cmd_test.go
cmd/cmd_test.go
+91
-0
No files found.
cmd/cmd_test.go
View file @
d721a02e
...
...
@@ -10,6 +10,7 @@ import (
"os"
"strings"
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/spf13/cobra"
...
...
@@ -490,6 +491,96 @@ func TestPushHandler(t *testing.T) {
}
}
func
TestListHandler
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
args
[]
string
serverResponse
[]
api
.
ListModelResponse
expectedError
string
expectedOutput
string
}{
{
name
:
"list all models"
,
args
:
[]
string
{},
serverResponse
:
[]
api
.
ListModelResponse
{
{
Name
:
"model1"
,
Digest
:
"sha256:abc123"
,
Size
:
1024
,
ModifiedAt
:
time
.
Now
()
.
Add
(
-
24
*
time
.
Hour
)},
{
Name
:
"model2"
,
Digest
:
"sha256:def456"
,
Size
:
2048
,
ModifiedAt
:
time
.
Now
()
.
Add
(
-
48
*
time
.
Hour
)},
},
expectedOutput
:
"NAME ID SIZE MODIFIED
\n
"
+
"model1 sha256:abc12 1.0 KB 24 hours ago
\n
"
+
"model2 sha256:def45 2.0 KB 2 days ago
\n
"
,
},
{
name
:
"filter models by prefix"
,
args
:
[]
string
{
"model1"
},
serverResponse
:
[]
api
.
ListModelResponse
{
{
Name
:
"model1"
,
Digest
:
"sha256:abc123"
,
Size
:
1024
,
ModifiedAt
:
time
.
Now
()
.
Add
(
-
24
*
time
.
Hour
)},
{
Name
:
"model2"
,
Digest
:
"sha256:def456"
,
Size
:
2048
,
ModifiedAt
:
time
.
Now
()
.
Add
(
-
24
*
time
.
Hour
)},
},
expectedOutput
:
"NAME ID SIZE MODIFIED
\n
"
+
"model1 sha256:abc12 1.0 KB 24 hours ago
\n
"
,
},
{
name
:
"server error"
,
args
:
[]
string
{},
expectedError
:
"server error"
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
mockServer
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
r
.
URL
.
Path
!=
"/api/tags"
||
r
.
Method
!=
http
.
MethodGet
{
t
.
Errorf
(
"unexpected request to %s %s"
,
r
.
Method
,
r
.
URL
.
Path
)
http
.
Error
(
w
,
"not found"
,
http
.
StatusNotFound
)
return
}
if
tt
.
expectedError
!=
""
{
http
.
Error
(
w
,
tt
.
expectedError
,
http
.
StatusInternalServerError
)
return
}
response
:=
api
.
ListResponse
{
Models
:
tt
.
serverResponse
}
if
err
:=
json
.
NewEncoder
(
w
)
.
Encode
(
response
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
}))
defer
mockServer
.
Close
()
t
.
Setenv
(
"OLLAMA_HOST"
,
mockServer
.
URL
)
cmd
:=
&
cobra
.
Command
{}
cmd
.
SetContext
(
context
.
TODO
())
// Capture stdout
oldStdout
:=
os
.
Stdout
r
,
w
,
_
:=
os
.
Pipe
()
os
.
Stdout
=
w
err
:=
ListHandler
(
cmd
,
tt
.
args
)
// Restore stdout and get output
w
.
Close
()
os
.
Stdout
=
oldStdout
output
,
_
:=
io
.
ReadAll
(
r
)
if
tt
.
expectedError
==
""
{
if
err
!=
nil
{
t
.
Errorf
(
"expected no error, got %v"
,
err
)
}
if
got
:=
string
(
output
);
got
!=
tt
.
expectedOutput
{
t
.
Errorf
(
"expected output:
\n
%s
\n
got:
\n
%s"
,
tt
.
expectedOutput
,
got
)
}
}
else
{
if
err
==
nil
||
!
strings
.
Contains
(
err
.
Error
(),
tt
.
expectedError
)
{
t
.
Errorf
(
"expected error containing %q, got %v"
,
tt
.
expectedError
,
err
)
}
}
})
}
}
func
TestCreateHandler
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment