Skip to content
This repository was archived by the owner on Jun 17, 2024. It is now read-only.

Commit 44a9fad

Browse files
authored
Fix travis tests and changes to pass linting (#10)
1 parent 2b6f3cf commit 44a9fad

File tree

5 files changed

+49
-11
lines changed

5 files changed

+49
-11
lines changed

.golangci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
issues:
2+
max-per-linter: 0
3+
max-same-issues: 0
4+
5+
linters:
6+
disable-all: true
7+
enable:
8+
- deadcode
9+
- errcheck
10+
- gofmt
11+
- gosimple
12+
- ineffassign
13+
- misspell
14+
- staticcheck
15+
- structcheck
16+
- unconvert
17+
- unused
18+
- varcheck
19+
- vet
20+
21+
linters-settings:
22+
errcheck:
23+
ignore: github.com/hashicorp/terraform/helper/schema:ForceNew|Set,fmt:.*,io:Close
24+
25+
run:
26+
deadline: 5m
27+
modules-download-mode: vendor

GNUmakefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ errcheck:
4040
vendor-status:
4141
@govendor status
4242

43+
lint:
44+
@echo "==> Checking source code against linters..."
45+
@GOGC=30 golangci-lint run ./$(PKG_NAME)
46+
47+
tools:
48+
GO111MODULE=off go get -u github.com/client9/misspell/cmd/misspell
49+
GO111MODULE=off go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
50+
4351
test-compile:
4452
@if [ "$(TEST)" = "./..." ]; then \
4553
echo "ERROR: Set TEST to a specific package. For example,"; \

vra7/provider_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var (
2626
func init() {
2727

2828
fmt.Println("init")
29-
testAccProvider := Provider()
29+
testAccProvider = Provider().(*schema.Provider)
3030
testAccProviders = map[string]terraform.ResourceProvider{
3131
"vra7": testAccProvider,
3232
}

vra7/resource_vra7_deployment.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ func resourceVra7DeploymentUpdate(d *schema.ResourceData, meta interface{}) erro
281281
return fmt.Errorf("Error retrieving reconfigure action template for the component %v: %v ", componentName, err.Error())
282282
}
283283
configChanged := false
284-
returnFlag := false
285284
for configKey := range p.ResourceConfiguration {
285+
var returnFlag bool
286286
//compare resource list (resource_name) with user configuration fields
287287
if strings.HasPrefix(configKey, componentName+".") {
288288
//If user_configuration contains resource_list element
@@ -295,14 +295,14 @@ func resourceVra7DeploymentUpdate(d *schema.ResourceData, meta interface{}) erro
295295
resourceActionTemplate.Data,
296296
nameList[1],
297297
p.ResourceConfiguration[configKey])
298-
if returnFlag == true {
298+
if returnFlag {
299299
configChanged = true
300300
}
301301
}
302302
}
303303
oldData, _ := d.GetChange("resource_configuration")
304304
// If template value got changed then set post call and update resource child
305-
if configChanged != false {
305+
if configChanged {
306306
// This request id is for the reconfigure action on this machine and
307307
// will be used to track the status of the reconfigure request for this resource.
308308
// It will not replace the initial catalog item request id
@@ -377,9 +377,8 @@ func resourceVra7DeploymentRead(d *schema.ResourceData, meta interface{}) error
377377
}
378378
}
379379
resourceConfiguration, _ := d.Get("resource_configuration").(map[string]interface{})
380-
changed := false
381380

382-
resourceConfiguration, changed = utils.UpdateResourceConfigurationMap(resourceConfiguration, resourceDataMap)
381+
resourceConfiguration, changed := utils.UpdateResourceConfigurationMap(resourceConfiguration, resourceDataMap)
383382

384383
if changed {
385384
setError := d.Set("resource_configuration", resourceConfiguration)

vra7/resource_vra7_deployment_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ func init() {
2323

2424
func TestConfigValidityFunction(t *testing.T) {
2525

26-
mockRequestTemplate := GetMockRequestTemplate()
26+
mockRequestTemplate, err := GetMockRequestTemplate()
27+
utils.AssertNilError(t, err)
2728

2829
// a resource_configuration map is created with valid components
2930
// all combinations of components name and properties are created with dots
@@ -43,7 +44,7 @@ func TestConfigValidityFunction(t *testing.T) {
4344
p := readProviderConfiguration(mockResourceData)
4445

4546
readProviderConfiguration(mockResourceData)
46-
err := p.checkResourceConfigValidity(mockRequestTemplate)
47+
err = p.checkResourceConfigValidity(mockRequestTemplate)
4748
utils.AssertNilError(t, err)
4849

4950
mockConfigResourceMap["machine2.mock.cpu"] = 2
@@ -81,12 +82,15 @@ func TestConfigValidityFunction(t *testing.T) {
8182
}
8283

8384
// creates a mock request template from a request template template json file
84-
func GetMockRequestTemplate() *sdk.CatalogItemRequestTemplate {
85+
func GetMockRequestTemplate() (*sdk.CatalogItemRequestTemplate, error) {
8586

8687
mockRequestTemplateStruct := sdk.CatalogItemRequestTemplate{}
87-
json.Unmarshal([]byte(mockRequestTemplate), &mockRequestTemplateStruct)
88+
err := json.Unmarshal([]byte(mockRequestTemplate), &mockRequestTemplateStruct)
89+
if err != nil {
90+
return nil, err
91+
}
8892

89-
return &mockRequestTemplateStruct
93+
return &mockRequestTemplateStruct, nil
9094

9195
}
9296

0 commit comments

Comments
 (0)