Skip to content

Commit

Permalink
chore: fix linter errors and update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Dustin Scott <dustin.scott18@gmail.com>
  • Loading branch information
scottd018 committed Jun 20, 2022
1 parent 811d008 commit b6d9d85
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 37 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/license/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestCollectionFieldMarker_String(t *testing.T) {
t.Parallel()

testString := "cfm test"
testName := "test"
testName := "cfmtest"

type fields struct {
Name *string
Expand All @@ -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",
Expand All @@ -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}",
},
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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",
Expand Down Expand Up @@ -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{}
}
Expand All @@ -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",
Expand Down
19 changes: 11 additions & 8 deletions internal/workload/v1/markers/field_marker_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func TestFieldMarker_String(t *testing.T) {
t.Parallel()

testName := "test"
testName := "fmtest"
testString := "fm test"

type fields struct {
Expand All @@ -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",
Expand All @@ -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}",
},
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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",
Expand Down Expand Up @@ -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{}
}
Expand All @@ -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",
Expand Down Expand Up @@ -531,6 +533,7 @@ func TestFieldMarker_SetOriginalValue(t *testing.T) {
t.Parallel()

fmOriginalValue := "testUpdateOriginal"
fmFake := "testFmFake"

type fields struct {
originalValue interface{}
Expand All @@ -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,
Expand Down
23 changes: 12 additions & 11 deletions internal/workload/v1/markers/markers_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
},
{
Expand Down Expand Up @@ -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
Expand All @@ -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,
},
},
},
Expand All @@ -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",
},
},
Expand All @@ -784,7 +785,7 @@ func Test_transformYAML(t *testing.T) {
results: []*inspect.YAMLResult{
{
Result: &parser.Result{
MarkerText: "test",
MarkerText: testString,
Object: FieldMarker{
Name: &collectionName,
},
Expand All @@ -800,7 +801,7 @@ func Test_transformYAML(t *testing.T) {
results: []*inspect.YAMLResult{
{
Result: &parser.Result{
MarkerText: "test",
MarkerText: testString,
Object: CollectionFieldMarker{
Name: &collectionName,
},
Expand All @@ -816,16 +817,16 @@ func Test_transformYAML(t *testing.T) {
results: []*inspect.YAMLResult{
{
Result: &parser.Result{
MarkerText: "test",
MarkerText: testString,
Object: CollectionFieldMarker{
Name: &realField,
Replace: &badReplaceText,
},
},
Nodes: []*yaml.Node{
{
Tag: "test",
Value: "test",
Tag: testString,
Value: testString,
},
},
},
Expand Down
10 changes: 5 additions & 5 deletions internal/workload/v1/markers/resource_marker_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func TestResourceMarker_String(t *testing.T) {
t.Parallel()

testField := "test"
testField := "rmtest"
testIncludeTrue := true

type fields struct {
Expand All @@ -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",
Expand Down

0 comments on commit b6d9d85

Please sign in to comment.