Skip to content

Commit

Permalink
Tagargs changes - from a TODO comment (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
Taimoor Ahmad authored Feb 15, 2024
1 parent acbfee8 commit e8d6084
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Refactor-20240214-132831.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Refactor
body: NewTagArgs(string) will return error if string is not in exact format 'key:value'
time: 2024-02-14T13:28:31.000636-05:00
12 changes: 5 additions & 7 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,22 +555,20 @@ func (client *Client) ListServicesWithProduct(product string, variables *Payload
return &q.Account.Services, nil
}

func NewTagArgs(tag string) TagArgs {
func NewTagArgs(tag string) (TagArgs, error) {
kv := strings.Split(tag, ":")
switch len(kv) {
case 1:
return TagArgs{
Key: RefOf(kv[0]),
}
}, nil
case 2:
return TagArgs{
Key: RefOf(kv[0]),
Value: RefOf(kv[1]),
}
default: // TODO: is this the best we can do?
return TagArgs{
Key: RefOf(tag),
}
}, nil
default:
return TagArgs{}, fmt.Errorf("cannot make a valid TagArg from: '%s' (not in format key:value)", tag)
}
}

Expand Down
4 changes: 3 additions & 1 deletion service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,9 @@ func TestListServicesWithTag(t *testing.T) {

client := BestTestClient(t, "service/list_with_tag", requests...)
// Act
response, err := client.ListServicesWithTag(ol.NewTagArgs("app:worker"), nil)
tagArgs, err := ol.NewTagArgs("app:worker")
autopilot.Ok(t, err)
response, err := client.ListServicesWithTag(tagArgs, nil)
result := response.Nodes
// Assert
autopilot.Ok(t, err)
Expand Down

0 comments on commit e8d6084

Please sign in to comment.