From 29ac7d38d8d1ec2425a67ae6e364993a191b1096 Mon Sep 17 00:00:00 2001 From: Herman Schaaf Date: Thu, 30 Jun 2022 13:48:58 +0100 Subject: [PATCH] fix(docs): Update instructions for adding new resources and add install-tools command (#1128) --- Makefile | 6 ++++++ docs/contributing/adding_a_new_resource.md | 22 +++++++++++----------- tools/tool.go | 1 + 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index ad59a99a0..d1c948485 100644 --- a/Makefile +++ b/Makefile @@ -62,3 +62,9 @@ test-unit: .PHONY: test-integration test-integration: @if [[ "$(tableName)" == "" ]]; then go test -run=TestIntegration -timeout 3m -tags=integration ./...; else go test -run="TestIntegration/$(tableName)" -timeout 3m -tags=integration ./...; fi + +# Install tools +.PHONY: install-tools +install-tools: + @echo Installing tools from tools/tool.go + @cat tools/tool.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % go install % diff --git a/docs/contributing/adding_a_new_resource.md b/docs/contributing/adding_a_new_resource.md index ad2762ec9..31424225c 100644 --- a/docs/contributing/adding_a_new_resource.md +++ b/docs/contributing/adding_a_new_resource.md @@ -15,9 +15,9 @@ If the service to which the resource belongs has not been used before in cq-prov * Don't forget to add the new service interface name to the go:generate comment. 1. Add the service to the `Services` struct in the [client/client.go](../../client/client.go) 1. Init the service in the `initServices` function in [client/client.go](../../client/client.go) -1. Run `go generate client/services.go` to create a mock for your new service. This will update [client/mocks/.go](../../client/mocks) automatically +1. Run `go generate client/services.go` to create a mock for your new service. This will update [client/mocks/mock_.go](../../client/mocks) automatically -> On MacOS, if you get an error about not being able to find `mockgen`, `export PATH=${PATH}:`go env GOPATH`/bin` in you shell to set up your `PATH` environment properly +> If you get an error about not being able to find `mockgen`, run `make install-tools` to install it. If it still fails, run `export PATH=${PATH}:`go env GOPATH`/bin` in you shell to set up your `PATH` environment properly > You might need to update an existing AWS client by running `go get github.com/aws/aws-sdk-go-v2/service/@latest` and then `go mod tidy` @@ -25,13 +25,13 @@ If the service to which the resource belongs has not been used before in cq-prov ### Skeleton -1. In [client/services.go](./client/services.go), update the service interface and add the method(s) that you will be using to fetch the data from the aws sdk. -1. Run `go generate client/services.go` to create a mock for your new methods. This will update [client/mocks/services.go](./client/mocks/services.go) automatically -1. Create a file under `resources/` that follows the pattern of `_`. -1. In that file, create a function that returns a `*schema.Table` -1. In [resources/provider.go](./resources/provider.go), add a mapping between the function you just created and the name of the resource that will be used in the config yml file. -1. Add a test file at `resources/__test.go`. Follow other examples to create a test for the resource. -1. Run `go run docs/docs.go` to generate the documentation for the new resource +1. In [client/services.go](../../client/services.go), update the service interface and add the method(s) that you will be using to fetch the data from the aws sdk. +1. Run `go generate client/services.go` to create a mock for your new methods. This will update [client/mocks/mock_.go](../../client/mocks) automatically. +1. Create a file under [resources/services/](../../resources/services) that follows the pattern of `.go`. +1. In that file, create a function that returns a `*schema.Table`. +1. In [resources/provider.go](../../resources/provider/provider.go), add a mapping between the function you just created and the name of the resource that will be used in the config yml file. +1. Add a test file at [resources/services//_mock_test.go](../../resources/services). Follow other examples to create a test for the resource. +1. Run `go run docs/docs.go` to generate the documentation for the new resource. ### Implementation @@ -44,9 +44,9 @@ Now that the skeleton has been set up, you can start to actually implement the r It is recommended that you look at a few existing resources as examples and also read through the comments on the source code for the [Table](https://github.com/cloudquery/cq-provider-sdk/blob/main/provider/schema/table.go) and [Column](https://github.com/cloudquery/cq-provider-sdk/blob/main/provider/schema/column.go) implementations for details. -For noncomplex fields, the SDK can directly resolve them into `Column`s for you, so all you need to do is specify the `Name` and the `Type`. +For simple fields, the SDK can directly resolve them into `Column`s for you, so all you need to do is specify the `Name` and the `Type`. -For complex fields or fields that require further API calls, you can defined your own `Resolver` for the `Column`. +For complex fields or fields that require further API calls, you can define your own `Resolver` for the `Column`. #### Implementing Resolver Functions diff --git a/tools/tool.go b/tools/tool.go index 95a702f8a..b97ca5af7 100644 --- a/tools/tool.go +++ b/tools/tool.go @@ -5,4 +5,5 @@ package main import ( _ "github.com/cloudquery/cq-gen" + _ "github.com/golang/mock/mockgen" )