|
| 1 | +/* |
| 2 | +Copyright 2018 The Doctl Authors All rights reserved. |
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. |
| 5 | +You may obtain a copy of the License at |
| 6 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +Unless required by applicable law or agreed to in writing, software |
| 8 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +See the License for the specific language governing permissions and |
| 11 | +limitations under the License. |
| 12 | +*/ |
| 13 | + |
| 14 | +package commands |
| 15 | + |
| 16 | +import ( |
| 17 | + "testing" |
| 18 | + "time" |
| 19 | + |
| 20 | + "github.com/digitalocean/doctl/do" |
| 21 | + "github.com/digitalocean/godo" |
| 22 | + "github.com/stretchr/testify/assert" |
| 23 | +) |
| 24 | + |
| 25 | +// Test data |
| 26 | +var ( |
| 27 | + testModel1 = do.Model{ |
| 28 | + Model: &godo.Model{ |
| 29 | + Uuid: "model-1", |
| 30 | + Name: "GPT-4 Turbo", |
| 31 | + IsFoundational: true, |
| 32 | + Provider: "OpenAI", |
| 33 | + InferenceName: "gpt-4-turbo", |
| 34 | + InferenceVersion: "2024-04-09", |
| 35 | + UploadComplete: true, |
| 36 | + Url: "https://api.openai.com/v1/models/gpt-4-turbo", |
| 37 | + CreatedAt: &godo.Timestamp{Time: time.Now().AddDate(0, -2, 0)}, |
| 38 | + UpdatedAt: &godo.Timestamp{Time: time.Now().AddDate(0, -1, 0)}, |
| 39 | + Usecases: []string{"text-generation", "chat"}, |
| 40 | + Agreement: &godo.Agreement{ |
| 41 | + Name: "OpenAI Terms of Service", |
| 42 | + Description: "Standard OpenAI API terms and conditions", |
| 43 | + }, |
| 44 | + Version: &godo.ModelVersion{ |
| 45 | + Major: 4, |
| 46 | + Minor: 0, |
| 47 | + Patch: 0, |
| 48 | + }, |
| 49 | + }, |
| 50 | + } |
| 51 | + |
| 52 | + testModel2 = do.Model{ |
| 53 | + Model: &godo.Model{ |
| 54 | + Uuid: "model-2", |
| 55 | + Name: "Claude 3.5 Sonnet", |
| 56 | + IsFoundational: true, |
| 57 | + Provider: "Anthropic", |
| 58 | + InferenceName: "claude-3-5-sonnet", |
| 59 | + InferenceVersion: "20240620", |
| 60 | + UploadComplete: true, |
| 61 | + Url: "https://api.anthropic.com/v1/models/claude-3-5-sonnet", |
| 62 | + CreatedAt: &godo.Timestamp{Time: time.Now().AddDate(0, -1, -15)}, |
| 63 | + UpdatedAt: &godo.Timestamp{Time: time.Now().AddDate(0, 0, -10)}, |
| 64 | + Usecases: []string{"text-generation", "analysis", "coding"}, |
| 65 | + Agreement: &godo.Agreement{ |
| 66 | + Name: "Anthropic Service Terms", |
| 67 | + Description: "Anthropic API service agreement", |
| 68 | + }, |
| 69 | + Version: &godo.ModelVersion{ |
| 70 | + Major: 3, |
| 71 | + Minor: 5, |
| 72 | + Patch: 0, |
| 73 | + }, |
| 74 | + }, |
| 75 | + } |
| 76 | + |
| 77 | + testModels = do.Models{testModel1, testModel2} |
| 78 | +) |
| 79 | + |
| 80 | +func TestListModelsCommand(t *testing.T) { |
| 81 | + cmd := ListModelsCmd() |
| 82 | + assert.NotNil(t, cmd) |
| 83 | + assert.Equal(t, "list-models", cmd.Use) |
| 84 | + assert.Contains(t, cmd.Aliases, "models") |
| 85 | + assert.Contains(t, cmd.Aliases, "lm") |
| 86 | + assert.Equal(t, "List GenAI models", cmd.Short) |
| 87 | + assert.Contains(t, cmd.Long, "doctl genai list-models") |
| 88 | +} |
| 89 | + |
| 90 | +func TestRunGenAIListModels(t *testing.T) { |
| 91 | + withTestClient(t, func(config *CmdConfig, tm *tcMocks) { |
| 92 | + tm.genAI.EXPECT().ListAvailableModels().Return(testModels, nil) |
| 93 | + |
| 94 | + err := RunGenAIListModels(config) |
| 95 | + assert.NoError(t, err) |
| 96 | + }) |
| 97 | +} |
| 98 | + |
| 99 | +func TestRunGenAIListModelsError(t *testing.T) { |
| 100 | + withTestClient(t, func(config *CmdConfig, tm *tcMocks) { |
| 101 | + tm.genAI.EXPECT().ListAvailableModels().Return(nil, assert.AnError) |
| 102 | + |
| 103 | + err := RunGenAIListModels(config) |
| 104 | + assert.Error(t, err) |
| 105 | + }) |
| 106 | +} |
0 commit comments