-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add workspace and tag existence fns (#56)
- Loading branch information
Showing
6 changed files
with
101 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package kong | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
) | ||
|
||
// exists check the existence with a HEAD HTTP verb | ||
func (c *Client) exists(ctx context.Context, | ||
endpoint string) (bool, error) { | ||
req, err := c.NewRequest("HEAD", endpoint, nil, nil) | ||
if err != nil { | ||
return false, err | ||
} | ||
resp, err := c.Do(ctx, req, nil) | ||
if err != nil { | ||
if IsNotFoundErr(err) { | ||
return false, nil | ||
} | ||
return false, err | ||
} | ||
return resp.StatusCode == http.StatusOK, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package kong | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// AbstractTagService handles Tags in Kong. | ||
type AbstractTagService interface { | ||
//Exists checks if the tags exists | ||
Exists(ctx context.Context) (bool, error) | ||
} | ||
|
||
// TagService handles Tags in Kong. | ||
type TagService service | ||
|
||
// Exists checks exitence of the Tags in Kong. | ||
func (s *TagService) Exists(ctx context.Context) (bool, error) { | ||
return s.client.exists(ctx, "/tags") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package kong | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTagExists(T *testing.T) { | ||
runWhenKong(T, ">=1.1.0") | ||
assert := assert.New(T) | ||
|
||
client, err := NewTestClient(nil, nil) | ||
assert.Nil(err) | ||
assert.NotNil(client) | ||
|
||
exists, err := client.Tags.Exists(defaultCtx) | ||
assert.Nil(err) | ||
assert.True(exists) | ||
} | ||
|
||
func TestTagDoesNotExists(T *testing.T) { | ||
runWhenKong(T, "<1.1.0") | ||
assert := assert.New(T) | ||
|
||
client, err := NewTestClient(nil, nil) | ||
assert.Nil(err) | ||
assert.NotNil(client) | ||
|
||
exists, err := client.Tags.Exists(defaultCtx) | ||
assert.Nil(err) | ||
assert.False(exists) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters