diff --git a/Makefile b/Makefile index cc214e5..054a9e6 100644 --- a/Makefile +++ b/Makefile @@ -33,10 +33,9 @@ install: build # # traditional testing # -GOLANGCI_LINT_VERSION ?= v1.45.2 +GOLANGCI_LINT_VERSION ?= v1.46.2 install-linter: - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \ - sh -s -- -b $$(go env GOPATH)/bin $(GOLANGCI_LINT_VERSION) + go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) lint: golangci-lint run diff --git a/internal/license/license.go b/internal/license/license.go index 572fb37..6adf62f 100644 --- a/internal/license/license.go +++ b/internal/license/license.go @@ -100,7 +100,7 @@ func getSourceLicense(source string) ([]byte, error) { if source[0:4] == "http" { // source is HTTP URL - resp, err := http.Get(source) //nolint:gosec,noctx + resp, err := http.Get(source) //nolint:gosec if err != nil { return []byte{}, fmt.Errorf("unable to get license source from %s, %w", source, err) } diff --git a/internal/plugins/workload/v1/scaffolds/templates/api/resources/definition.go b/internal/plugins/workload/v1/scaffolds/templates/api/resources/definition.go index 21d2c7e..7537e39 100644 --- a/internal/plugins/workload/v1/scaffolds/templates/api/resources/definition.go +++ b/internal/plugins/workload/v1/scaffolds/templates/api/resources/definition.go @@ -39,8 +39,8 @@ func (f *Definition) SetTemplateDefaults() error { ) // determine if we need to import the strconv package - for _, child := range f.Manifest.ChildResources { - if child.UseStrConv { + for i := range f.Manifest.ChildResources { + if f.Manifest.ChildResources[i].UseStrConv { f.UseStrConv = true break diff --git a/internal/workload/v1/markers/collection_field_marker_internal_test.go b/internal/workload/v1/markers/collection_field_marker_internal_test.go index ecc8b9b..7de8d89 100644 --- a/internal/workload/v1/markers/collection_field_marker_internal_test.go +++ b/internal/workload/v1/markers/collection_field_marker_internal_test.go @@ -15,7 +15,7 @@ func TestCollectionFieldMarker_String(t *testing.T) { t.Parallel() testString := "cfm test" - testName := "test" + testName := "cfmtest" type fields struct { Name *string @@ -37,7 +37,7 @@ func TestCollectionFieldMarker_String(t *testing.T) { Description: &testString, Default: testName, }, - want: "CollectionFieldMarker{Name: test Type: string Description: \"cfm test\" Default: test}", + want: "CollectionFieldMarker{Name: cfmtest Type: string Description: \"cfm test\" Default: cfmtest}", }, { name: "ensure collection field with nil values output matches expected", @@ -47,7 +47,7 @@ func TestCollectionFieldMarker_String(t *testing.T) { Description: nil, Default: testName, }, - want: "CollectionFieldMarker{Name: test Type: string Description: \"\" Default: test}", + want: "CollectionFieldMarker{Name: cfmtest Type: string Description: \"\" Default: cfmtest}", }, } @@ -147,7 +147,7 @@ func TestCollectionFieldMarker_GetDefault(t *testing.T) { func TestCollectionFieldMarker_GetName(t *testing.T) { t.Parallel() - name := "test" + name := "getNameTest" emptyName := "" type fields struct { @@ -164,7 +164,7 @@ func TestCollectionFieldMarker_GetName(t *testing.T) { fields: fields{ Name: &name, }, - want: "test", + want: name, }, { name: "ensure collection field name with empty value returns as expected", @@ -347,6 +347,8 @@ func TestCollectionFieldMarker_GetSpecPrefix(t *testing.T) { func TestCollectionFieldMarker_GetOriginalValue(t *testing.T) { t.Parallel() + originalValue := "originalValueTest" + type fields struct { originalValue interface{} } @@ -359,9 +361,9 @@ func TestCollectionFieldMarker_GetOriginalValue(t *testing.T) { { name: "ensure collection field original value string returns as expected", fields: fields{ - originalValue: "test", + originalValue: originalValue, }, - want: "test", + want: originalValue, }, { name: "ensure collection field original value integer returns as expected", diff --git a/internal/workload/v1/markers/field_marker_internal_test.go b/internal/workload/v1/markers/field_marker_internal_test.go index f14c91e..00a0a93 100644 --- a/internal/workload/v1/markers/field_marker_internal_test.go +++ b/internal/workload/v1/markers/field_marker_internal_test.go @@ -14,7 +14,7 @@ import ( func TestFieldMarker_String(t *testing.T) { t.Parallel() - testName := "test" + testName := "fmtest" testString := "fm test" type fields struct { @@ -37,7 +37,7 @@ func TestFieldMarker_String(t *testing.T) { Description: &testString, Default: testName, }, - want: "FieldMarker{Name: test Type: string Description: \"fm test\" Default: test}", + want: "FieldMarker{Name: fmtest Type: string Description: \"fm test\" Default: fmtest}", }, { name: "ensure field with nil values output matches expected", @@ -47,7 +47,7 @@ func TestFieldMarker_String(t *testing.T) { Description: nil, Default: testName, }, - want: "FieldMarker{Name: test Type: string Description: \"\" Default: test}", + want: "FieldMarker{Name: fmtest Type: string Description: \"\" Default: fmtest}", }, } @@ -147,7 +147,7 @@ func TestFieldMarker_GetDefault(t *testing.T) { func TestFieldMarker_GetName(t *testing.T) { t.Parallel() - name := "test" + name := "testGetFmName" emptyName := "" type fields struct { @@ -164,7 +164,7 @@ func TestFieldMarker_GetName(t *testing.T) { fields: fields{ Name: &name, }, - want: "test", + want: name, }, { name: "ensure field name with empty value returns as expected", @@ -347,6 +347,8 @@ func TestFieldMarker_GetSpecPrefix(t *testing.T) { func TestFieldMarker_GetOriginalValue(t *testing.T) { t.Parallel() + name := "fmOriginalName" + type fields struct { originalValue interface{} } @@ -359,9 +361,9 @@ func TestFieldMarker_GetOriginalValue(t *testing.T) { { name: "ensure field original value string returns as expected", fields: fields{ - originalValue: "test", + originalValue: name, }, - want: "test", + want: name, }, { name: "ensure field original value integer returns as expected", @@ -531,6 +533,7 @@ func TestFieldMarker_SetOriginalValue(t *testing.T) { t.Parallel() fmOriginalValue := "testUpdateOriginal" + fmFake := "testFmFake" type fields struct { originalValue interface{} @@ -549,7 +552,7 @@ func TestFieldMarker_SetOriginalValue(t *testing.T) { { name: "ensure field original value with string already set is set as expected", fields: fields{ - originalValue: "test", + originalValue: fmFake, }, args: args{ value: fmOriginalValue, diff --git a/internal/workload/v1/markers/markers_internal_test.go b/internal/workload/v1/markers/markers_internal_test.go index 3402df9..7930f8a 100644 --- a/internal/workload/v1/markers/markers_internal_test.go +++ b/internal/workload/v1/markers/markers_internal_test.go @@ -242,7 +242,7 @@ func Test_getSourceCodeFieldVariable(t *testing.T) { failTest := &FieldMarker{ Name: &failTestString, sourceCodeVar: "parent.Spec.Field.Fail", - Type: FieldBool, + Type: FieldUnknownType, } type args struct { @@ -276,7 +276,7 @@ func Test_getSourceCodeFieldVariable(t *testing.T) { args: args{ marker: intTest, }, - want: "!!start string(rune(parent.Spec.Field.Integer)) !!end", + want: "!!start strconv.Itoa(parent.Spec.Field.Integer) !!end", wantErr: false, }, { @@ -732,6 +732,7 @@ func Test_transformYAML(t *testing.T) { badReplaceText := "*&^%" realField := "real.field" collectionName := "collection.name" + testString := "transformTest" type args struct { results []*inspect.YAMLResult @@ -748,15 +749,15 @@ func Test_transformYAML(t *testing.T) { results: []*inspect.YAMLResult{ { Result: &parser.Result{ - MarkerText: "test", + MarkerText: testString, Object: FieldMarker{ Name: &realField, }, }, Nodes: []*yaml.Node{ { - Tag: "test", - Value: "test", + Tag: testString, + Value: testString, }, }, }, @@ -770,7 +771,7 @@ func Test_transformYAML(t *testing.T) { results: []*inspect.YAMLResult{ { Result: &parser.Result{ - MarkerText: "test", + MarkerText: testString, Object: "this is a string no a marker", }, }, @@ -784,7 +785,7 @@ func Test_transformYAML(t *testing.T) { results: []*inspect.YAMLResult{ { Result: &parser.Result{ - MarkerText: "test", + MarkerText: testString, Object: FieldMarker{ Name: &collectionName, }, @@ -800,7 +801,7 @@ func Test_transformYAML(t *testing.T) { results: []*inspect.YAMLResult{ { Result: &parser.Result{ - MarkerText: "test", + MarkerText: testString, Object: CollectionFieldMarker{ Name: &collectionName, }, @@ -816,7 +817,7 @@ func Test_transformYAML(t *testing.T) { results: []*inspect.YAMLResult{ { Result: &parser.Result{ - MarkerText: "test", + MarkerText: testString, Object: CollectionFieldMarker{ Name: &realField, Replace: &badReplaceText, @@ -824,8 +825,8 @@ func Test_transformYAML(t *testing.T) { }, Nodes: []*yaml.Node{ { - Tag: "test", - Value: "test", + Tag: testString, + Value: testString, }, }, }, diff --git a/internal/workload/v1/markers/resource_marker_internal_test.go b/internal/workload/v1/markers/resource_marker_internal_test.go index 60d1db5..6855bfb 100644 --- a/internal/workload/v1/markers/resource_marker_internal_test.go +++ b/internal/workload/v1/markers/resource_marker_internal_test.go @@ -14,7 +14,7 @@ import ( func TestResourceMarker_String(t *testing.T) { t.Parallel() - testField := "test" + testField := "rmtest" testIncludeTrue := true type fields struct { @@ -33,19 +33,19 @@ func TestResourceMarker_String(t *testing.T) { name: "ensure resource marker with set field values output matches expected", fields: fields{ Field: &testField, - Value: "test", + Value: testField, Include: &testIncludeTrue, }, - want: "ResourceMarker{Field: test CollectionField: Value: test Include: true}", + want: "ResourceMarker{Field: rmtest CollectionField: Value: rmtest Include: true}", }, { name: "ensure resource marker with set collection field values output matches expected", fields: fields{ CollectionField: &testField, - Value: "test", + Value: testField, Include: &testIncludeTrue, }, - want: "ResourceMarker{Field: CollectionField: test Value: test Include: true}", + want: "ResourceMarker{Field: CollectionField: rmtest Value: rmtest Include: true}", }, { name: "ensure resource marker with nil values output matches expected",