diff --git a/.golangci.yml b/.golangci.yml index 847e86e..e6435e0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -17,7 +17,7 @@ linters-settings: - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf lll: - line-length: 140 + line-length: 160 misspell: locale: US nolintlint: @@ -72,4 +72,4 @@ issues: run: timeout: 5m - skip-dirs: [] \ No newline at end of file + skip-dirs: [] diff --git a/internal/provider/client.go b/internal/provider/client.go index 41a09a5..f6fc0fa 100644 --- a/internal/provider/client.go +++ b/internal/provider/client.go @@ -31,7 +31,6 @@ func NewClient(host string, username *string, password *string, insecureSkipVeri Password: password, } - tr := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: insecureSkipVerify}, } diff --git a/internal/provider/group_resource.go b/internal/provider/group_resource.go index 5edab63..3ac05c2 100644 --- a/internal/provider/group_resource.go +++ b/internal/provider/group_resource.go @@ -125,7 +125,7 @@ func (d *GroupResourceModel) ParseHttpResponse(body []byte) error { /* Unmarshal the json string */ result := make(map[string]interface{}) - err := json.Unmarshal([]byte(body), &result) + err := json.Unmarshal(body, &result) if err != nil { return err } @@ -147,7 +147,7 @@ func (d *GroupResourceModel) ParseHttpResponse(body []byte) error { } // Configure adds the provider configured client to the resource. -func (d *GroupResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +func (d *GroupResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { if req.ProviderData == nil { return } diff --git a/internal/provider/group_resource_test.go b/internal/provider/group_resource_test.go index 6c93e1a..586d5c5 100644 --- a/internal/provider/group_resource_test.go +++ b/internal/provider/group_resource_test.go @@ -48,7 +48,6 @@ func TestGroupParseHttpResponse(t *testing.T) { body := []byte("Not valid JSON") err := g.ParseHttpResponse(body) assert.Error(t, err) - }) } @@ -77,7 +76,6 @@ func TestGroupCreateRequestBody(t *testing.T) { } bytes.Equal(result, []byte(nil)) - }) t.Run("All Values", func(t *testing.T) { g := GroupResourceModel{ @@ -87,31 +85,39 @@ func TestGroupCreateRequestBody(t *testing.T) { Variables: jsontypes.NewNormalizedValue("{\"ansible_network_os\":\"ios\"}"), Description: types.StringValue("New Group"), } - body := []byte(`{"name": "group1", "inventory": 5, "url": "/api/v2/groups/24/", "description": "New Group", "variables": "{\"ansible_network_os\":\"ios\"}"}`) + body := []byte(`{"name": "group1", "inventory": 5, + "url": "/api/v2/groups/24/", + "description": "New Group", + "variables": "{\"ansible_network_os\":\"ios\"}"}`) result, diags := g.CreateRequestBody() if diags.HasError() { t.Fatal(diags.Errors()) } assert.JSONEq(t, string(body), string(result)) - }) t.Run("Multiple values for Variables", func(t *testing.T) { g := GroupResourceModel{ InventoryId: basetypes.NewInt64Value(5), Name: types.StringValue("group1"), URL: types.StringValue("/api/v2/groups/24/"), - Variables: jsontypes.NewNormalizedValue("{\"ansible_network_os\":\"ios\", \"ansible_connection\":\"network_cli\", \"ansible_ssh_user\":\"ansible\", \"ansible_ssh_pass\":\"ansible\"}"), + Variables: jsontypes.NewNormalizedValue( + "{\"ansible_network_os\":\"ios\",\"ansible_connection\":\"network_cli\", \"ansible_ssh_user\":\"ansible\", \"ansible_ssh_pass\":\"ansible\"}", + ), Description: types.StringValue("New Group"), } - body := []byte(`{"name": "group1", "inventory": 5, "url": "/api/v2/groups/24/", "description": "New Group", "variables": "{\"ansible_network_os\":\"ios\", \"ansible_connection\":\"network_cli\", \"ansible_ssh_user\":\"ansible\", \"ansible_ssh_pass\":\"ansible\"}"}`) + body := []byte(`{"name": "group1", "inventory": 5, + "url": "/api/v2/groups/24/", + "description": "New Group", + "variables": + "{\"ansible_network_os\":\"ios\", \"ansible_connection\":\"network_cli\", \"ansible_ssh_user\":\"ansible\", \"ansible_ssh_pass\":\"ansible\"}"}`, + ) result, diags := g.CreateRequestBody() if diags.HasError() { t.Fatal(diags.Errors()) } assert.JSONEq(t, string(body), string(result)) - }) } @@ -232,6 +238,5 @@ func TestReadGroup(t *testing.T) { if err == nil { t.Errorf("Failure expected but the ReadJob did not fail!!") } - }) } diff --git a/internal/provider/test_utils.go b/internal/provider/test_utils.go index 461b3bf..ae33d85 100644 --- a/internal/provider/test_utils.go +++ b/internal/provider/test_utils.go @@ -45,7 +45,6 @@ func mergeStringMaps(m1 map[string]string, m2 map[string]string) map[string]stri } func (c *MockHTTPClient) doRequest(method string, path string, data io.Reader) (*http.Response, []byte, error) { - if !slices.Contains(c.acceptMethods, method) { return nil, nil, nil }