Skip to content

Commit 183c71b

Browse files
arrestledleehr
andcommitted
remove changes to client.go and other review comments.
Co-authored-by: Dan Leehr <[email protected]>
1 parent 60e9f6f commit 183c71b

File tree

6 files changed

+17
-39
lines changed

6 files changed

+17
-39
lines changed

Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@ build: ## Compile the Go package. This is the default.
99
@echo "==> Building package..."
1010
go build
1111

12-
test: ## Execute all unit tests with verbose output."
12+
clean: ## Remove the .tools folder and binaries.
13+
@rm -rf .tools
14+
@rm terraform-provider-aap
15+
16+
test: ## Execute all unit tests with verbose output.
1317
@echo "==> Running unit tests..."
1418
go test -v ./...
1519

16-
testacc: ## Run acceptance tests against local aap-dev instance (https://localhost:8043)."
17-
@echo "==> Running acceptance tests..."
18-
TF_ACC=1 AAP_HOST="http://localhost:8043" go test -count=1 -v ./...
19-
20-
testacc-aapdev: ## Run acceptance tests against local aap-dev instance (EXPORT AAP_HOST="http://localhost:9080")
20+
testacc: ## Run Acceptance tests against aap instance (See README.md for env variables)
2121
@echo "==> Running acceptance tests..."
2222
TF_ACC=1 go test -count=1 -v ./...
2323

24-
generatedocs: ## Format example Terraform configurations and generate plugin documentation."
24+
generatedocs: ## Format example Terraform configurations and generate plugin documentation.
2525
@echo "==> Formatting examples and generating docs..."
2626
terraform fmt -recursive ./examples/
2727
go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs generate
2828

2929
.PHONY: help
3030
help: ## Show this help message
3131
@grep -hE '^[a-zA-Z0-9._-]+:.*?##' $(MAKEFILE_LIST) | \
32-
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-24s\033[0m %s\n", $$1, $$2}' | \
32+
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-16s\033[0m %s\n", $$1, $$2}' | \
3333
sort

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ Run `make test`
4242

4343
Acceptance tests apply test terraform configurations to a running AAP instance and make changes to resources in that instance, use with caution!
4444

45-
To run acceptance tests locally, you will need a running instance of Ansible Automation Platform (AAP). You can either use an existing instance or deploy a local test environment using any supported method (e.g., containerized or VM-based deployment from official Red Hat resources).
45+
To run acceptance tests locally, start a local AAP instance following the [docker-compose instructions for local AWX development](https://github.com/ansible/awx/blob/devel/tools/docker-compose/README.md). Create an admin user for the AAP instance and save the credentials to these environment variables:
4646

4747
Create an admin user for the AAP instance and set the following environment variables:
4848

4949
```bash
5050
export AAP_USERNAME=<your admin username>
5151
export AAP_PASSWORD=<your admin password>
52-
export AAP_HOST="http://localhost:9080" # if using aap-dev (Note: Subject to change)
52+
export AAP_INSECURE_SKIP_VERIFY=true
53+
export AAP_HOST=<your aap instance host url> # "http://localhost:9080" or "https://localhost:8043"
5354
```
5455

5556
In order to run the acceptance tests for the job resource, you must have a working job template already in your AAP instance. The job template must be set to require an inventory on launch. Export the id of this job template:

internal/provider/client.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ func (c *AAPClient) computeURLPath(path string) string {
116116

117117
func (c *AAPClient) doRequest(method string, path string, data io.Reader) (*http.Response, []byte, error) {
118118
ctx := context.Background()
119-
if c.httpClient == nil {
120-
return nil, nil, fmt.Errorf("internal error: httpClient is nil")
121-
}
122119
req, err := http.NewRequestWithContext(ctx, method, c.computeURLPath(path), data)
123120
if err != nil {
124121
return nil, []byte{}, err
@@ -153,28 +150,8 @@ func (c *AAPClient) Create(path string, data io.Reader) ([]byte, diag.Diagnostic
153150

154151
// Get sends a GET request to the provided path, checks for errors, and returns the response body with any errors as diagnostics.
155152
func (c *AAPClient) GetWithStatus(path string) ([]byte, diag.Diagnostics, int) {
156-
if c == nil {
157-
return nil, diag.Diagnostics{diag.NewErrorDiagnostic("AAPClient is nil", "Client was not initialized properly")}, 0
158-
}
159-
if path == "" {
160-
return nil, diag.Diagnostics{diag.NewErrorDiagnostic("Path is empty", "Path cannot be empty")}, 0
161-
}
162-
if c.httpClient == nil {
163-
return nil, diag.Diagnostics{diag.NewErrorDiagnostic("HttpClient is nil", "HttpClient was not initialized properly")}, 0
164-
}
165153
getResponse, body, err := c.doRequest("GET", path, nil)
166154
diags := ValidateResponse(getResponse, body, err, []int{http.StatusOK})
167-
if diags.HasError() {
168-
return nil, diags, getResponse.StatusCode
169-
}
170-
if getResponse == nil {
171-
diags.AddError("Get response is nil", "The response from the server is nil")
172-
return nil, diags, 0
173-
}
174-
if body == nil {
175-
diags.AddError("Get response body is nil", "The response body from the server is nil")
176-
return nil, diags, 0
177-
}
178155
return body, diags, getResponse.StatusCode
179156
}
180157

internal/provider/inventory_resource_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func TestAccInventoryResource(t *testing.T) {
188188
Check: resource.ComposeAggregateTestCheckFunc(
189189
testAccCheckInventoryResourceExists(resourceNameInventory, &inventory),
190190
testAccCheckInventoryResourceValues(&inventory, randomName, "", ""),
191-
checkBasicInventoryAttributes(t, resourceNameInventory, randomName),
191+
checkBasicInventoryAttributes(t, resourceNameInventory, randomName, "1", "Default"),
192192
),
193193
},
194194
// Update and Read testing
@@ -197,7 +197,7 @@ func TestAccInventoryResource(t *testing.T) {
197197
Check: resource.ComposeAggregateTestCheckFunc(
198198
testAccCheckInventoryResourceExists(resourceNameInventory, &inventory),
199199
testAccCheckInventoryResourceValues(&inventory, updatedName, updatedDescription, updatedVariables),
200-
checkBasicInventoryAttributes(t, resourceNameInventory, updatedName),
200+
checkBasicInventoryAttributes(t, resourceNameInventory, updatedName, "1", "Default"),
201201
resource.TestCheckResourceAttr(resourceNameInventory, "description", updatedDescription),
202202
resource.TestCheckResourceAttr(resourceNameInventory, "variables", updatedVariables),
203203
),

internal/provider/utils_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ func checkBasicGroupAttributes(t *testing.T, name, expectedName string) resource
6262
)
6363
}
6464

65-
func checkBasicInventoryAttributes(t *testing.T, name, expectedName string) resource.TestCheckFunc {
65+
func checkBasicInventoryAttributes(t *testing.T, name, expectedName string, expectedOrgId string, expectedOrgName string) resource.TestCheckFunc {
6666
t.Helper()
6767
return resource.ComposeAggregateTestCheckFunc(
6868
resource.TestCheckResourceAttr(name, "name", expectedName),
69-
resource.TestCheckResourceAttr(name, "organization", "1"),
70-
resource.TestCheckResourceAttr(name, "organization_name", "Default"),
69+
resource.TestCheckResourceAttr(name, "organization", expectedOrgId),
70+
resource.TestCheckResourceAttr(name, "organization_name", expectedOrgName),
7171
resource.TestMatchResourceAttr(name, "url", reInventoryURLPattern),
7272
resource.TestCheckResourceAttr(name, "named_url", fmt.Sprintf("/api/controller/v2/inventories/%s++%s/", expectedName, "Default")),
7373
resource.TestCheckResourceAttrSet(name, "id"),

makefiles/golangci.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ lint: lint-tools ## Run static analysis via golangci-lint
2020
@echo "==> Checking source code against linters..."
2121
$(GOLANGCI_LINT) run -v ./...
2222

23-
gofmt: ## Format Go source code in 'internal/provider' using gofmt."
23+
gofmt: ## Format Go source code in 'internal/provider' using gofmt.
2424
@echo "==> Format code using gofmt..."
2525
gofmt -s -w internal/provider
2626

0 commit comments

Comments
 (0)