MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / Rename

Function Rename

internal/providers/store.go:130–150  ·  view source on GitHub ↗

Rename moves an endpoint key from oldName to newName. Errors when source is missing or destination already exists, so the caller never accidentally overwrites a different provider.

(file *File, oldName, newName string)

Source from the content-addressed store, hash-verified

128// is missing or destination already exists, so the caller never accidentally
129// overwrites a different provider.
130func Rename(file *File, oldName, newName string) error {
131 if file == nil {
132 return errors.New("providers: nil file")
133 }
134 if err := validateName(newName); err != nil {
135 return err
136 }
137 ep, ok := file.Endpoints[oldName]
138 if !ok {
139 return fmt.Errorf("provider %q not found: %w", oldName, ErrNotFound)
140 }
141 if oldName == newName {
142 return nil
143 }
144 if _, exists := file.Endpoints[newName]; exists {
145 return fmt.Errorf("provider %q already exists: %w", newName, ErrAlreadyExists)
146 }
147 delete(file.Endpoints, oldName)
148 file.Endpoints[newName] = ep
149 return nil
150}
151
152// SetEnabled toggles the Enabled field on the named endpoint. Returns
153// ErrNotFound if no such endpoint exists.

Callers 4

TestRenameHappyFunction · 0.92
TestRenameSourceMissingFunction · 0.92
TestRenameDestExistsFunction · 0.92
RenameProviderMethod · 0.92

Calls 1

validateNameFunction · 0.70

Tested by 3

TestRenameHappyFunction · 0.74
TestRenameSourceMissingFunction · 0.74
TestRenameDestExistsFunction · 0.74