Skip to content

Commit

Permalink
Use ownerType instead of string
Browse files Browse the repository at this point in the history
  • Loading branch information
grezar committed Nov 1, 2021
1 parent ac25458 commit b5cbf93
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
14 changes: 11 additions & 3 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ type contexts struct {
client *Client
}

type ownerType string

const (
OwnerTypeOrganization ownerType = "organization"
OwnerTypeAccount ownerType = "account"
)

type Context struct {
ID string `json:"id"`
Name string `json:"name"`
Expand Down Expand Up @@ -73,15 +80,16 @@ type ContextCreateOptions struct {
}

type OwnerOptions struct {
ID *string `json:"id,omitempty"`
Slug *string `json:"slug,omitempty"`
Type *string `json:"type,omitempty"`
ID *string `json:"id,omitempty"`
Slug *string `json:"slug,omitempty"`
Type *ownerType `json:"type,omitempty"`
}

func (o ContextCreateOptions) valid() error {
if !validString(o.Owner.ID) && !validString(o.Owner.Slug) {
return ErrRequiredEitherIDOrSlug
}

return nil
}

Expand Down
3 changes: 2 additions & 1 deletion context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Test_contexts_Create(t *testing.T) {
testMethod(t, r, "POST")
testHeader(t, r, "Accept", "application/vnd.api+json")
testHeader(t, r, "Circle-Token", client.token)
testBody(t, r, `{"name":"ctx","owner":{"slug":"org"}}`+"\n")
testBody(t, r, `{"name":"ctx","owner":{"slug":"org","type":"organization"}}`+"\n")
fmt.Fprint(w, `{"id": "1"}`)
})

Expand All @@ -60,6 +60,7 @@ func Test_contexts_Create(t *testing.T) {
Name: String("ctx"),
Owner: &OwnerOptions{
Slug: String("org"),
Type: OwnerType("organization"),
},
})
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions type_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ func Time(v time.Time) *time.Time {
func ReportingWindow(v reportingWindow) *reportingWindow {
return &v
}

// OwnerType returs a pointer to the given ownerType.
func OwnerType(v ownerType) *ownerType {
return &v
}

0 comments on commit b5cbf93

Please sign in to comment.