forked from felipeagc/ollama
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default Keep Alive environment variable (ollama#3094)
--------- Co-authored-by: Chris-AS1 <8493773+Chris-AS1@users.noreply.github.com>
- Loading branch information
1 parent
1e42968
commit d2e9274
Showing
2 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"math" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestKeepAliveParsingFromJSON(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
req string | ||
exp *Duration | ||
}{ | ||
{ | ||
name: "Positive Integer", | ||
req: `{ "keep_alive": 42 }`, | ||
exp: &Duration{42 * time.Second}, | ||
}, | ||
{ | ||
name: "Positive Integer String", | ||
req: `{ "keep_alive": "42m" }`, | ||
exp: &Duration{42 * time.Minute}, | ||
}, | ||
{ | ||
name: "Negative Integer", | ||
req: `{ "keep_alive": -1 }`, | ||
exp: &Duration{math.MaxInt64}, | ||
}, | ||
{ | ||
name: "Negative Integer String", | ||
req: `{ "keep_alive": "-1m" }`, | ||
exp: &Duration{math.MaxInt64}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
var dec ChatRequest | ||
err := json.Unmarshal([]byte(test.req), &dec) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, test.exp, dec.KeepAlive) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters