Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion command/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ func runPasswordChange(username, pass string) {
newPass["NewPassword"] = pass
_, err, emessages := force.ChangePassword(id, newPass)
if err != nil {
ErrorAndExit(err.Error(), emessages[0].ErrorCode)
if len(emessages) > 0 {
ErrorAndExit(err.Error(), emessages[0].ErrorCode)
}
ErrorAndExit(err.Error())
} else {
fmt.Println("\nPassword changed\n ")
}
Expand Down
5 changes: 4 additions & 1 deletion command/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ func runRecordCreate(object string, fields []string) {
attrs := parseArgumentAttrs(fields)
id, err, emessages := force.CreateRecord(object, attrs)
if err != nil {
ErrorAndExit("Failed to create record: %s (%s)", err.Error(), emessages[0].ErrorCode)
if len(emessages) > 0 {
ErrorAndExit("Failed to create record: %s (%s)", err.Error(), emessages[0].ErrorCode)
}
ErrorAndExit("Failed to create record: %s", err.Error())
}
fmt.Printf("Record created: %s\n", id)
}
Expand Down
58 changes: 58 additions & 0 deletions command/record_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package command

import (
"testing"
)

func TestParseArgumentAttrs(t *testing.T) {
tests := []struct {
name string
input []string
expected map[string]string
}{
{
name: "parses_single_field",
input: []string{"Name:Acme"},
expected: map[string]string{"Name": "Acme"},
},
{
name: "parses_multiple_fields",
input: []string{"Name:Acme", "Industry:Technology"},
expected: map[string]string{"Name": "Acme", "Industry": "Technology"},
},
{
name: "handles_empty_input",
input: []string{},
expected: map[string]string{},
},
{
name: "handles_value_with_colons",
input: []string{"Description:Value:with:colons"},
expected: map[string]string{"Description": "Value:with:colons"},
},
{
name: "handles_empty_value",
input: []string{"Name:"},
expected: map[string]string{"Name": ""},
},
{
name: "handles_quoted_value_with_spaces",
input: []string{"Name:Acme Corp"},
expected: map[string]string{"Name": "Acme Corp"},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := parseArgumentAttrs(tt.input)
if len(result) != len(tt.expected) {
t.Errorf("Expected %d fields, got %d", len(tt.expected), len(result))
}
for key, expectedValue := range tt.expected {
if result[key] != expectedValue {
t.Errorf("Expected %s=%q, got %s=%q", key, expectedValue, key, result[key])
}
}
})
}
}