Skip to content

Commit

Permalink
update client APIs, add retention client functionality (#72)
Browse files Browse the repository at this point in the history
* draft: update client APIs, add retention client functionality

* add proper integration tests for retention client

* update mockery version, reference it in Makefile

* simplify ci steps
  • Loading branch information
elenz97 authored Jan 19, 2021
1 parent 0729e3a commit 4abdbe1
Show file tree
Hide file tree
Showing 34 changed files with 421 additions and 351 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/verify-codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Run swagger code generation
run: make swagger-generate

- name: Run mockery code generation
run: make mock
- name: Run code generation
run: make generate

- name: Test diff
run: |
Expand Down
28 changes: 18 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
.PHONY: swagger-generate mock harbor-v1 harbor-v2 teardown-harbor test swagger-cleanup \
.PHONY: generate swagger-generate mock harbor-v1 harbor-v2 harbor-teardown test swagger-cleanup \
mock-cleanup integration-test-v1 integration-test-v2

V1_VERSION = v1.10.5
V2_VERSION = v2.1.1
V1_VERSION = v1.10.6
V2_VERSION = v2.1.3
MOCKERY_VERSION = v2.5.1

# Run all code generation targets
generate: swagger-generate mock-generate

# Run go-swagger code generation
swagger-generate: swagger-cleanup
scripts/swagger-gen.sh $(V1_VERSION)
scripts/swagger-gen.sh $(V2_VERSION)

mock: mock-cleanup
scripts/gen-mock.sh v1
scripts/gen-mock.sh v2
# Run mockery
mock-generate: mock-cleanup
scripts/gen-mock.sh v1 $(MOCKERY_VERSION)
scripts/gen-mock.sh v2 $(MOCKERY_VERSION)

# Creates a Harbor instance as a docker container via Kind.
# Create a Harbor instance as a docker container via Kind.
# Delete cluster via scripts/teardown-harbor.sh
harbor-v1:
scripts/setup-harbor.sh $(V1_VERSION)

harbor-v2:
scripts/setup-harbor.sh $(V2_VERSION)

teardown-harbor:
harbor-teardown:
scripts/teardown-harbor.sh

test:
Expand All @@ -29,17 +35,19 @@ test:
swagger-cleanup:
rm -rf ./apiv*/internal ./apiv*/model/

# Delete all auto-generated mock files
mock-cleanup:
rm -rf ./apiv*/mocks/*

# Testing on Harbor v1
# Integration testing on Harbor v1
integration-test-v1: harbor-v1
CGO_ENABLED=0 go test -p 1 -count 1 -v github.com/mittwald/goharbor-client/v3/apiv1/... -tags integration

# Testing on Harbor v2
# Integration testing on Harbor v2
integration-test-v2: harbor-v2
CGO_ENABLED=0 go test -p 1 -count 1 -v github.com/mittwald/goharbor-client/v3/apiv2/... -tags integration

# Exclude auto-generated code to be formatted by gofmt
gofmt:
find . \( -path "./apiv*/internal" -o -path "./apiv*/mocks" -o -path "./apiv*/model" \) \
-prune -false -o -name '*.go' -exec gofmt -l -w {} \;
2 changes: 1 addition & 1 deletion apiv1/mocks/client_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions apiv2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func NewRESTClient(legacyClient *client.Harbor, v2Client *v2client.Harbor, authI
registry: registry.NewClient(legacyClient, v2Client, authInfo),
replication: replication.NewClient(legacyClient, v2Client, authInfo),
system: system.NewClient(legacyClient, v2Client, authInfo),
retention: retention.NewClient(legacyClient, v2Client, authInfo),
}
}

Expand Down Expand Up @@ -301,3 +302,13 @@ func (c *RESTClient) NewRetentionPolicy(ctx context.Context, rep *model.Retentio
func (c *RESTClient) GetRetentionPolicyByProject(ctx context.Context, project *modelv2.Project) (*model.RetentionPolicy, error) {
return c.retention.GetRetentionPolicyByProject(ctx, project)
}

// UpdateRetentionPolicy wraps the UpdateRetentionPolicy method of the retention sub-package.
func (c *RESTClient) UpdateRetentionPolicy(ctx context.Context, ret *model.RetentionPolicy) error {
return c.retention.UpdateRetentionPolicy(ctx, ret)
}

// DisableRetentionPolicy wraps the DisableRetentionPolicy method of the retention sub-package.
func (c *RESTClient) DisableRetentionPolicy(ctx context.Context, ret *model.RetentionPolicy) error {
return c.retention.DisableRetentionPolicy(ctx, ret)
}
24 changes: 12 additions & 12 deletions apiv2/internal/api/client/preheat/create_instance_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 7 additions & 13 deletions apiv2/internal/api/client/preheat/delete_instance_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 6 additions & 12 deletions apiv2/internal/api/client/preheat/update_instance_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apiv2/mocks/artifact_client_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apiv2/mocks/auditlog_client_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apiv2/mocks/icon_client_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apiv2/mocks/preheat_client_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apiv2/mocks/products_client_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apiv2/mocks/project_client_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apiv2/mocks/repository_client_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apiv2/mocks/scan_client_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4abdbe1

Please sign in to comment.