Update ConnectorOptions handling in tests and types
- Changed the `Optional` field in `ConnectorOptions` from a boolean to a pointer to allow for nil values, enhancing flexibility in option handling. - Updated tests in `load_test.go`, `convert_test.go`, and `assistant_test.go` to reflect the new pointer type for `Optional`, ensuring proper assertions and error handling. - Added new test cases to validate behavior when `Optional` is nil or false, improving test coverage and robustness of the ConnectorOptions functionality.
This commit is contained in:
parent
bbba6b9fdb
commit
ede240302a
4 changed files with 55 additions and 13 deletions
|
|
@ -73,7 +73,8 @@ func TestLoadPath(t *testing.T) {
|
||||||
|
|
||||||
// ConnectorOptions
|
// ConnectorOptions
|
||||||
assert.NotNil(t, assistant.ConnectorOptions)
|
assert.NotNil(t, assistant.ConnectorOptions)
|
||||||
assert.True(t, assistant.ConnectorOptions.Optional)
|
assert.NotNil(t, assistant.ConnectorOptions.Optional)
|
||||||
|
assert.True(t, *assistant.ConnectorOptions.Optional)
|
||||||
assert.NotNil(t, assistant.ConnectorOptions.Connectors)
|
assert.NotNil(t, assistant.ConnectorOptions.Connectors)
|
||||||
assert.Contains(t, assistant.ConnectorOptions.Connectors, "gpt-4o")
|
assert.Contains(t, assistant.ConnectorOptions.Connectors, "gpt-4o")
|
||||||
assert.Contains(t, assistant.ConnectorOptions.Connectors, "gpt-4o-mini")
|
assert.Contains(t, assistant.ConnectorOptions.Connectors, "gpt-4o-mini")
|
||||||
|
|
@ -370,7 +371,8 @@ func TestUpdate(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.NotNil(t, assistant.ConnectorOptions)
|
assert.NotNil(t, assistant.ConnectorOptions)
|
||||||
assert.False(t, assistant.ConnectorOptions.Optional)
|
assert.NotNil(t, assistant.ConnectorOptions.Optional)
|
||||||
|
assert.False(t, *assistant.ConnectorOptions.Optional)
|
||||||
assert.Contains(t, assistant.ConnectorOptions.Connectors, "new-connector")
|
assert.Contains(t, assistant.ConnectorOptions.Connectors, "new-connector")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -609,7 +609,7 @@ func TestToAssistantModel(t *testing.T) {
|
||||||
if result.ConnectorOptions == nil {
|
if result.ConnectorOptions == nil {
|
||||||
t.Error("Expected ConnectorOptions to be set")
|
t.Error("Expected ConnectorOptions to be set")
|
||||||
} else {
|
} else {
|
||||||
if !result.ConnectorOptions.Optional {
|
if result.ConnectorOptions.Optional == nil || !*result.ConnectorOptions.Optional {
|
||||||
t.Error("Expected ConnectorOptions.Optional to be true")
|
t.Error("Expected ConnectorOptions.Optional to be true")
|
||||||
}
|
}
|
||||||
if len(result.ConnectorOptions.Connectors) != 2 {
|
if len(result.ConnectorOptions.Connectors) != 2 {
|
||||||
|
|
@ -849,7 +849,7 @@ func TestToAssistantModelNewFields(t *testing.T) {
|
||||||
t.Fatal("Expected ConnectorOptions to be set")
|
t.Fatal("Expected ConnectorOptions to be set")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !result.ConnectorOptions.Optional {
|
if result.ConnectorOptions.Optional == nil || !*result.ConnectorOptions.Optional {
|
||||||
t.Error("Expected Optional to be true")
|
t.Error("Expected Optional to be true")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1349,8 +1349,9 @@ func TestToConnectorOptions(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("ConnectorOptionsPointer", func(t *testing.T) {
|
t.Run("ConnectorOptionsPointer", func(t *testing.T) {
|
||||||
|
optionalTrue := true
|
||||||
opts := &ConnectorOptions{
|
opts := &ConnectorOptions{
|
||||||
Optional: true,
|
Optional: &optionalTrue,
|
||||||
Connectors: []string{"openai", "anthropic"},
|
Connectors: []string{"openai", "anthropic"},
|
||||||
Filters: []ModelCapability{CapVision, CapToolCalls},
|
Filters: []ModelCapability{CapVision, CapToolCalls},
|
||||||
}
|
}
|
||||||
|
|
@ -1364,8 +1365,9 @@ func TestToConnectorOptions(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("ConnectorOptionsValue", func(t *testing.T) {
|
t.Run("ConnectorOptionsValue", func(t *testing.T) {
|
||||||
|
optionalTrue := true
|
||||||
opts := ConnectorOptions{
|
opts := ConnectorOptions{
|
||||||
Optional: true,
|
Optional: &optionalTrue,
|
||||||
Connectors: []string{"openai", "anthropic"},
|
Connectors: []string{"openai", "anthropic"},
|
||||||
Filters: []ModelCapability{CapVision, CapToolCalls},
|
Filters: []ModelCapability{CapVision, CapToolCalls},
|
||||||
}
|
}
|
||||||
|
|
@ -1373,7 +1375,7 @@ func TestToConnectorOptions(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Expected no error, got: %v", err)
|
t.Errorf("Expected no error, got: %v", err)
|
||||||
}
|
}
|
||||||
if !result.Optional {
|
if result.Optional == nil || !*result.Optional {
|
||||||
t.Error("Expected Optional to be true")
|
t.Error("Expected Optional to be true")
|
||||||
}
|
}
|
||||||
if len(result.Connectors) != 2 {
|
if len(result.Connectors) != 2 {
|
||||||
|
|
@ -1394,7 +1396,7 @@ func TestToConnectorOptions(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Expected no error, got: %v", err)
|
t.Errorf("Expected no error, got: %v", err)
|
||||||
}
|
}
|
||||||
if !result.Optional {
|
if result.Optional == nil || !*result.Optional {
|
||||||
t.Error("Expected Optional to be true")
|
t.Error("Expected Optional to be true")
|
||||||
}
|
}
|
||||||
if len(result.Connectors) != 3 {
|
if len(result.Connectors) != 3 {
|
||||||
|
|
@ -1413,7 +1415,7 @@ func TestToConnectorOptions(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Expected no error, got: %v", err)
|
t.Errorf("Expected no error, got: %v", err)
|
||||||
}
|
}
|
||||||
if !result.Optional {
|
if result.Optional == nil || !*result.Optional {
|
||||||
t.Error("Expected Optional to be true")
|
t.Error("Expected Optional to be true")
|
||||||
}
|
}
|
||||||
if result.Connectors != nil {
|
if result.Connectors != nil {
|
||||||
|
|
@ -1424,6 +1426,42 @@ func TestToConnectorOptions(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("MapInputOptionalFalse", func(t *testing.T) {
|
||||||
|
data := map[string]interface{}{
|
||||||
|
"optional": false,
|
||||||
|
"connectors": []string{"openai"},
|
||||||
|
"filters": []string{"vision"},
|
||||||
|
}
|
||||||
|
result, err := ToConnectorOptions(data)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Expected no error, got: %v", err)
|
||||||
|
}
|
||||||
|
if result.Optional == nil {
|
||||||
|
t.Error("Expected Optional to be set")
|
||||||
|
} else if *result.Optional {
|
||||||
|
t.Error("Expected Optional to be false")
|
||||||
|
}
|
||||||
|
if len(result.Connectors) != 1 {
|
||||||
|
t.Errorf("Expected 1 connector, got %d", len(result.Connectors))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("MapInputOptionalNil", func(t *testing.T) {
|
||||||
|
data := map[string]interface{}{
|
||||||
|
"connectors": []string{"openai"},
|
||||||
|
}
|
||||||
|
result, err := ToConnectorOptions(data)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Expected no error, got: %v", err)
|
||||||
|
}
|
||||||
|
if result.Optional != nil {
|
||||||
|
t.Errorf("Expected Optional to be nil (not set), got: %v", *result.Optional)
|
||||||
|
}
|
||||||
|
if len(result.Connectors) != 1 {
|
||||||
|
t.Errorf("Expected 1 connector, got %d", len(result.Connectors))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("InvalidInput", func(t *testing.T) {
|
t.Run("InvalidInput", func(t *testing.T) {
|
||||||
// Test with data that can't be marshaled
|
// Test with data that can't be marshaled
|
||||||
invalidData := make(chan int)
|
invalidData := make(chan int)
|
||||||
|
|
|
||||||
|
|
@ -245,7 +245,7 @@ const (
|
||||||
// ConnectorOptions the connector selection options
|
// ConnectorOptions the connector selection options
|
||||||
// Allows defining optional connector selection with filtering capabilities
|
// Allows defining optional connector selection with filtering capabilities
|
||||||
type ConnectorOptions struct {
|
type ConnectorOptions struct {
|
||||||
Optional bool `json:"optional,omitempty"` // Whether connector is optional for user selection
|
Optional *bool `json:"optional"` // Whether connector is optional for user selection (nil=default, false=hidden, true=shown)
|
||||||
Connectors []string `json:"connectors,omitempty"` // List of available connectors, empty means all connectors are available
|
Connectors []string `json:"connectors,omitempty"` // List of available connectors, empty means all connectors are available
|
||||||
Filters []ModelCapability `json:"filters,omitempty"` // Filter by model capabilities, conditions can be stacked
|
Filters []ModelCapability `json:"filters,omitempty"` // Filter by model capabilities, conditions can be stacked
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -454,13 +454,14 @@ func TestSaveAssistant(t *testing.T) {
|
||||||
|
|
||||||
t.Run("ConnectorOptions", func(t *testing.T) {
|
t.Run("ConnectorOptions", func(t *testing.T) {
|
||||||
// Test assistant with connector options
|
// Test assistant with connector options
|
||||||
|
optionalTrue := true
|
||||||
assistant := &types.AssistantModel{
|
assistant := &types.AssistantModel{
|
||||||
Name: "Connector Options Test",
|
Name: "Connector Options Test",
|
||||||
Type: "assistant",
|
Type: "assistant",
|
||||||
Connector: "openai",
|
Connector: "openai",
|
||||||
Share: "private",
|
Share: "private",
|
||||||
ConnectorOptions: &types.ConnectorOptions{
|
ConnectorOptions: &types.ConnectorOptions{
|
||||||
Optional: true,
|
Optional: &optionalTrue,
|
||||||
Connectors: []string{"openai", "anthropic"},
|
Connectors: []string{"openai", "anthropic"},
|
||||||
Filters: []types.ModelCapability{types.CapVision, types.CapToolCalls},
|
Filters: []types.ModelCapability{types.CapVision, types.CapToolCalls},
|
||||||
},
|
},
|
||||||
|
|
@ -481,7 +482,7 @@ func TestSaveAssistant(t *testing.T) {
|
||||||
t.Fatal("Expected connector options to be set")
|
t.Fatal("Expected connector options to be set")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !retrieved.ConnectorOptions.Optional {
|
if retrieved.ConnectorOptions.Optional == nil || !*retrieved.ConnectorOptions.Optional {
|
||||||
t.Error("Expected optional to be true")
|
t.Error("Expected optional to be true")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -596,13 +597,14 @@ func TestSaveAssistant(t *testing.T) {
|
||||||
|
|
||||||
t.Run("AllNewFieldsTogether", func(t *testing.T) {
|
t.Run("AllNewFieldsTogether", func(t *testing.T) {
|
||||||
// Test assistant with all new fields together
|
// Test assistant with all new fields together
|
||||||
|
optionalFalse := false
|
||||||
assistant := &types.AssistantModel{
|
assistant := &types.AssistantModel{
|
||||||
Name: "All New Fields Test",
|
Name: "All New Fields Test",
|
||||||
Type: "assistant",
|
Type: "assistant",
|
||||||
Connector: "openai",
|
Connector: "openai",
|
||||||
Share: "private",
|
Share: "private",
|
||||||
ConnectorOptions: &types.ConnectorOptions{
|
ConnectorOptions: &types.ConnectorOptions{
|
||||||
Optional: false,
|
Optional: &optionalFalse,
|
||||||
Connectors: []string{"openai"},
|
Connectors: []string{"openai"},
|
||||||
Filters: []types.ModelCapability{types.CapVision},
|
Filters: []types.ModelCapability{types.CapVision},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue