-
Notifications
You must be signed in to change notification settings - Fork 489
Expand file tree
/
Copy pathgradientai_list_models_test.go
More file actions
126 lines (112 loc) · 3.82 KB
/
Copy pathgradientai_list_models_test.go
File metadata and controls
126 lines (112 loc) · 3.82 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
Copyright 2018 The Doctl Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package commands
import (
"bytes"
"testing"
"time"
"github.com/digitalocean/doctl"
"github.com/digitalocean/doctl/do"
"github.com/digitalocean/godo"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)
// Test data
var (
testModel1 = do.Model{
Model: &godo.Model{
Uuid: "model-1",
Name: "GPT-4 Turbo",
IsFoundational: true,
Provider: "OpenAI",
InferenceName: "gpt-4-turbo",
InferenceVersion: "2024-04-09",
UploadComplete: true,
Url: "https://api.openai.com/v1/models/gpt-4-turbo",
CreatedAt: &godo.Timestamp{Time: time.Now().AddDate(0, -2, 0)},
UpdatedAt: &godo.Timestamp{Time: time.Now().AddDate(0, -1, 0)},
Usecases: []string{"text-generation", "chat"},
Agreement: &godo.Agreement{
Name: "OpenAI Terms of Service",
Description: "Standard OpenAI API terms and conditions",
},
Version: &godo.ModelVersion{
Major: 4,
Minor: 0,
Patch: 0,
},
},
}
testModel2 = do.Model{
Model: &godo.Model{
Uuid: "model-2",
Name: "Claude 3.5 Sonnet",
IsFoundational: true,
Provider: "Anthropic",
InferenceName: "claude-3-5-sonnet",
InferenceVersion: "20240620",
UploadComplete: true,
Url: "https://api.anthropic.com/v1/models/claude-3-5-sonnet",
CreatedAt: &godo.Timestamp{Time: time.Now().AddDate(0, -1, -15)},
UpdatedAt: &godo.Timestamp{Time: time.Now().AddDate(0, 0, -10)},
Usecases: []string{"text-generation", "analysis", "coding"},
Agreement: &godo.Agreement{
Name: "Anthropic Service Terms",
Description: "Anthropic API service agreement",
},
Version: &godo.ModelVersion{
Major: 3,
Minor: 5,
Patch: 0,
},
},
}
testModels = do.Models{testModel1, testModel2}
)
func TestListModelsCommand(t *testing.T) {
parent := &Command{Command: &cobra.Command{Use: "gradient"}}
cmd := ListModelsCmd(parent)
assert.NotNil(t, cmd)
assert.Equal(t, "list-models", cmd.Use)
assert.Contains(t, cmd.Aliases, "models")
assert.Contains(t, cmd.Aliases, "lm")
assert.Equal(t, "List Gradient AI models", cmd.Short)
assert.Contains(t, cmd.Long, "doctl gradient list-models")
}
func TestRunGradientAIListModels(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
tm.gradientAI.EXPECT().ListAvailableModels().Return(testModels, nil)
err := RunGradientAIListModels(config)
assert.NoError(t, err)
})
}
func TestRunGradientAIListModelsError(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
tm.gradientAI.EXPECT().ListAvailableModels().Return(nil, assert.AnError)
err := RunGradientAIListModels(config)
assert.Error(t, err)
})
}
func TestRunGradientAIListModelsFormatNoHeader(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
tm.gradientAI.EXPECT().ListAvailableModels().Return(testModels, nil)
var buf bytes.Buffer
config.NS = "gradient.list-models"
config.Out = &buf
config.Doit.Set(config.NS, doctl.ArgFormat, "ID,Name")
config.Doit.Set(config.NS, doctl.ArgNoHeader, true)
err := RunGradientAIListModels(config)
assert.NoError(t, err)
assert.Equal(t, "model-1 GPT-4 Turbo\nmodel-2 Claude 3.5 Sonnet\n", buf.String())
})
}