-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
135 additions
and
4 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
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
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
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
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,48 @@ | ||
package ping | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-openapi/runtime" | ||
v2client "github.com/mittwald/goharbor-client/v5/apiv2/internal/api/client" | ||
"github.com/mittwald/goharbor-client/v5/apiv2/internal/api/client/ping" | ||
"github.com/mittwald/goharbor-client/v5/apiv2/pkg/config" | ||
) | ||
|
||
// RESTClient is a subclient for handling ping related actions. | ||
type RESTClient struct { | ||
// Options contains optional configuration when making API calls. | ||
Options *config.Options | ||
|
||
// The new client of the harbor v2 API | ||
V2Client *v2client.Harbor | ||
|
||
// AuthInfo contains the auth information that is provided on API calls. | ||
AuthInfo runtime.ClientAuthInfoWriter | ||
} | ||
|
||
func NewClient(v2Client *v2client.Harbor, opts *config.Options, authInfo runtime.ClientAuthInfoWriter) *RESTClient { | ||
return &RESTClient{ | ||
Options: opts, | ||
V2Client: v2Client, | ||
AuthInfo: authInfo, | ||
} | ||
} | ||
|
||
type Client interface { | ||
GetPing(ctx context.Context) (string, error) | ||
} | ||
|
||
func (c *RESTClient) GetPing(ctx context.Context) (string, error) { | ||
params := &ping.GetPingParams{ | ||
Context: ctx, | ||
} | ||
params.WithTimeout(c.Options.Timeout) | ||
|
||
resp, err := c.V2Client.Ping.GetPing(params, c.AuthInfo) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return resp.Payload, 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,20 @@ | ||
//go:build integration | ||
|
||
package ping | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
clienttesting "github.com/mittwald/goharbor-client/v5/apiv2/pkg/testing" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAPIGetPing(t *testing.T) { | ||
ctx := context.Background() | ||
c := NewClient(clienttesting.V2SwaggerClient, clienttesting.DefaultOpts, clienttesting.AuthInfo) | ||
|
||
res, err := c.GetPing(ctx) | ||
require.NoError(t, err) | ||
require.Equal(t, "Pong", res) | ||
} |
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,44 @@ | ||
//go:build !integration | ||
|
||
package ping | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/mittwald/goharbor-client/v5/apiv2/internal/api/client/ping" | ||
"github.com/mittwald/goharbor-client/v5/apiv2/mocks" | ||
clienttesting "github.com/mittwald/goharbor-client/v5/apiv2/pkg/testing" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var ctx = context.Background() | ||
|
||
func APIandMockClientsForTests() (*RESTClient, *clienttesting.MockClients) { | ||
desiredMockClients := &clienttesting.MockClients{ | ||
Project: mocks.MockProjectClientService{}, | ||
} | ||
|
||
v2Client := clienttesting.BuildV2ClientWithMocks(desiredMockClients) | ||
|
||
cl := NewClient(v2Client, clienttesting.DefaultOpts, clienttesting.AuthInfo) | ||
|
||
return cl, desiredMockClients | ||
} | ||
func TestRESTClient_GetPing(t *testing.T) { | ||
apiClient, mockClient := APIandMockClientsForTests() | ||
|
||
getParams := &ping.GetPingParams{ | ||
Context: ctx, | ||
} | ||
|
||
getParams.WithTimeout(apiClient.Options.Timeout) | ||
|
||
mockClient.Ping.On("GetPing", getParams, mock.AnythingOfType("runtime.ClientAuthInfoWriterFunc")).Return(&ping.GetPingOK{}, nil) | ||
|
||
_, err := apiClient.GetPing(ctx) | ||
require.NoError(t, err) | ||
|
||
mockClient.Ping.AssertExpectations(t) | ||
} |
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
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