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
3 changes: 3 additions & 0 deletions pkg/connector/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ func formatObjectID(resourceTypeID string, id int64) string {
}

func parseObjectID(id string) (int64, error) {
if len(id) < 2 {
return 0, fmt.Errorf("invalid resource id: %q", id)
Comment thread
luisina-santos marked this conversation as resolved.
}
return strconv.ParseInt(id[1:], 10, 64)
}

Expand Down
28 changes: 28 additions & 0 deletions pkg/connector/helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package connector

import "testing"

func TestParseObjectID(t *testing.T) {
tests := []struct {
name string
input string
wantID int64
wantErr bool
}{
{"empty string", "", 0, true},
{"single char prefix only", "u", 0, true},
{"valid user id", "u12345", 12345, false},
{"invalid non-numeric suffix", "uabc", 0, true},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
got, err := parseObjectID(tc.input)
if (err != nil) != tc.wantErr {
t.Fatalf("parseObjectID(%q) error = %v, wantErr %v", tc.input, err, tc.wantErr)
}
if !tc.wantErr && got != tc.wantID {
t.Fatalf("parseObjectID(%q) = %d, want %d", tc.input, got, tc.wantID)
}
})
}
}
Loading