From e66de8c4cea1213cda1db609f07cbb0c8f6591c3 Mon Sep 17 00:00:00 2001 From: Peter Pan Date: Mon, 15 May 2023 13:53:59 +0800 Subject: [PATCH] chore: gofmt fix and enable in CI (#414) * gofmt the files Signed-off-by: Peter Pan * add UT and goFMT to PR Gate (Github Action for PR) Signed-off-by: Peter Pan --------- Signed-off-by: Peter Pan Co-authored-by: Alex Jones --- .github/workflows/test.yaml | 8 ++++++-- pkg/ai/noopai.go | 2 +- pkg/analyzer/hpaAnalyzer_test.go | 28 ++++++++++++++-------------- pkg/analyzer/node.go | 2 +- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 207a2e9..9c6460d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -23,5 +23,9 @@ jobs: with: go-version: ${{ env.GO_VERSION }} - - name: Test - run: go test -v ./... \ No newline at end of file + - name: Unit Test + run: make test + + - name: Fmt Test + run: fmtFiles=$(make fmt); if [ "$fmtFiles" != "" ];then exit 1; fi + diff --git a/pkg/ai/noopai.go b/pkg/ai/noopai.go index b6797a6..ff0877f 100644 --- a/pkg/ai/noopai.go +++ b/pkg/ai/noopai.go @@ -57,7 +57,7 @@ func (a *NoOpAIClient) Parse(ctx context.Context, prompt []string, cache cache.I return "", err } - err = cache.Store(cacheKey, base64.StdEncoding.EncodeToString([]byte(response))) + err = cache.Store(cacheKey, base64.StdEncoding.EncodeToString([]byte(response))) if err != nil { color.Red("error storing value to cache: %v", err) diff --git a/pkg/analyzer/hpaAnalyzer_test.go b/pkg/analyzer/hpaAnalyzer_test.go index 226f670..68055e1 100644 --- a/pkg/analyzer/hpaAnalyzer_test.go +++ b/pkg/analyzer/hpaAnalyzer_test.go @@ -205,15 +205,15 @@ func TestHPAAnalyzerWithExistingScaleTargetRefAsDeployment(t *testing.T) { Spec: corev1.PodSpec{ Containers: []corev1.Container{ { - Name: "example", + Name: "example", Image: "nginx", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ - "cpu": resource.MustParse("100m"), + "cpu": resource.MustParse("100m"), "memory": resource.MustParse("128Mi"), }, Limits: corev1.ResourceList{ - "cpu": resource.MustParse("200m"), + "cpu": resource.MustParse("200m"), "memory": resource.MustParse("256Mi"), }, }, @@ -269,15 +269,15 @@ func TestHPAAnalyzerWithExistingScaleTargetRefAsReplicationController(t *testing Spec: corev1.PodSpec{ Containers: []corev1.Container{ { - Name: "example", + Name: "example", Image: "nginx", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ - "cpu": resource.MustParse("100m"), + "cpu": resource.MustParse("100m"), "memory": resource.MustParse("128Mi"), }, Limits: corev1.ResourceList{ - "cpu": resource.MustParse("200m"), + "cpu": resource.MustParse("200m"), "memory": resource.MustParse("256Mi"), }, }, @@ -333,15 +333,15 @@ func TestHPAAnalyzerWithExistingScaleTargetRefAsReplicaSet(t *testing.T) { Spec: corev1.PodSpec{ Containers: []corev1.Container{ { - Name: "example", + Name: "example", Image: "nginx", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ - "cpu": resource.MustParse("100m"), + "cpu": resource.MustParse("100m"), "memory": resource.MustParse("128Mi"), }, Limits: corev1.ResourceList{ - "cpu": resource.MustParse("200m"), + "cpu": resource.MustParse("200m"), "memory": resource.MustParse("256Mi"), }, }, @@ -397,15 +397,15 @@ func TestHPAAnalyzerWithExistingScaleTargetRefAsStatefulSet(t *testing.T) { Spec: corev1.PodSpec{ Containers: []corev1.Container{ { - Name: "example", + Name: "example", Image: "nginx", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ - "cpu": resource.MustParse("100m"), + "cpu": resource.MustParse("100m"), "memory": resource.MustParse("128Mi"), }, Limits: corev1.ResourceList{ - "cpu": resource.MustParse("200m"), + "cpu": resource.MustParse("200m"), "memory": resource.MustParse("256Mi"), }, }, @@ -461,7 +461,7 @@ func TestHPAAnalyzerWithExistingScaleTargetRefWithoutSpecifyingResources(t *test Spec: corev1.PodSpec{ Containers: []corev1.Container{ { - Name: "example", + Name: "example", Image: "nginx", }, }, @@ -487,7 +487,7 @@ func TestHPAAnalyzerWithExistingScaleTargetRefWithoutSpecifyingResources(t *test var errorFound bool for _, analysis := range analysisResults { for _, err := range analysis.Error { - if strings.Contains(err.Text, "does not have resource configured."){ + if strings.Contains(err.Text, "does not have resource configured.") { errorFound = true break } diff --git a/pkg/analyzer/node.go b/pkg/analyzer/node.go index af9f1b0..0edc76a 100644 --- a/pkg/analyzer/node.go +++ b/pkg/analyzer/node.go @@ -58,7 +58,7 @@ func (NodeAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) { } if len(failures) > 0 { - preAnalysis[node.Name]= common.PreAnalysis{ + preAnalysis[node.Name] = common.PreAnalysis{ Node: node, FailureDetails: failures, }