Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add formatter #356

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
- name: Lint Terraform
if: runner.os == 'Linux'
run: cd terraform && make check-fmt
- name: Lint Go
if: runner.os == 'Linux'
run: make simple-lint
- name: Compile tests
run: |
echo "Compile tests"
Expand Down
54 changes: 52 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
BASE_SPACE=$(shell pwd)
BUILD_SPACE=$(BASE_SPACE)/build

IMPORT_PATH=github.com/aws/amazon-cloudwatch-agent-test
ALL_SRC := $(shell find . -name '*.go' -type f | sort)
TOOLS_BIN_DIR := $(abspath ./build/tools)

GOIMPORTS = $(TOOLS_BIN_DIR)/goimports
LINTER = $(TOOLS_BIN_DIR)/golangci-lint
IMPI = $(TOOLS_BIN_DIR)/impi
ADDLICENSE = $(TOOLS_BIN_DIR)/addlicense

GOIMPORTS_OPT?= -w -local $(IMPORT_PATH)

WIN_BUILD = GOOS=windows GOARCH=amd64 go build -trimpath -o $(BUILD_SPACE)
LINUX_AMD64_BUILD = CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -o $(BUILD_SPACE)
Expand All @@ -22,14 +30,56 @@ LOADGEN_LINUX_ARM64_BUILD = $(LINUX_ARM64_BUILD)/linux/arm64
LOADGEN_DARWIN_AMD64_BUILD = $(DARWIN_AMD64_BUILD)/darwin/amd64
LOADGEN_DARWIN_ARM64_BUILD = $(DARWIN_ARM64_BUILD)/darwin/arm64

install-tools:
install-goimports:
GOBIN=$(TOOLS_BIN_DIR) go install golang.org/x/tools/cmd/goimports

install-impi:
GOBIN=$(TOOLS_BIN_DIR) go install github.com/pavius/impi/cmd/[email protected]

install-addlicense:
# Using 04bfe4e to get SPDX template changes that are not present in the most recent tag v1.0.0
# This is required to be able to easily omit the year in our license header.
GOBIN=$(TOOLS_BIN_DIR) go install github.com/google/addlicense@04bfe4e

install-golang-lint:
#Install from source for golangci-lint is not recommended based on https://golangci-lint.run/usage/install/#install-from-source so using binary
#installation
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TOOLS_BIN_DIR) v1.50.1

lint: install-tools
fmt: install-goimports addlicense
go fmt ./...
@echo $(ALL_SRC) | xargs -n 10 $(GOIMPORTS) $(GOIMPORTS_OPT)

impi: install-impi
@echo $(ALL_SRC) | xargs -n 10 $(IMPI) --local $(IMPORT_PATH) --scheme stdThirdPartyLocal
@echo "Check import order/grouping finished"

simple-lint: checklicense impi

lint: install-golang-lint simple-lint
${LINTER} run ./...

addlicense: install-addlicense
@ADDLICENSEOUT=`$(ADDLICENSE) -y="" -s=only -l="mit" -c="Amazon.com, Inc. or its affiliates. All Rights Reserved." $(ALL_SRC) 2>&1`; \
if [ "$$ADDLICENSEOUT" ]; then \
echo "$(ADDLICENSE) FAILED => add License errors:\n"; \
echo "$$ADDLICENSEOUT\n"; \
exit 1; \
else \
echo "Add License finished successfully"; \
fi

checklicense: install-addlicense
@ADDLICENSEOUT=`$(ADDLICENSE) -check $(ALL_SRC) 2>&1`; \
if [ "$$ADDLICENSEOUT" ]; then \
echo "$(ADDLICENSE) FAILED => add License errors:\n"; \
echo "$$ADDLICENSEOUT\n"; \
echo "Use 'make addlicense' to fix this."; \
exit 1; \
else \
echo "Check License finished successfully"; \
fi

compile:
# this is a workaround to compile and cache all of the tests without actually running any of them
go test -run=NO_MATCH ./...
Expand Down
3 changes: 3 additions & 0 deletions cmd/emf-generator/emf-generator.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package main

import (
Expand Down
3 changes: 3 additions & 0 deletions cmd/log-generator/log-generator.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package main

import (
Expand Down
3 changes: 3 additions & 0 deletions cmd/statsd-generator/statsd-generator.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package main

import (
Expand Down
3 changes: 2 additions & 1 deletion filesystem/unix_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ package filesystem

import (
"fmt"
"golang.org/x/sys/unix"
"os/user"

"golang.org/x/sys/unix"
)

type FilePermission string
Expand Down
3 changes: 2 additions & 1 deletion filesystem/windows_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ package filesystem

import (
"fmt"
"golang.org/x/sys/windows"
"os"
"unsafe"

"golang.org/x/sys/windows"
)

// CheckFileRights check that the given filename has access controls and system permission for Administrator, Local System
Expand Down
10 changes: 5 additions & 5 deletions install/install_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import (
)

const (
retryNumber = 10
retryTime = 30 * time.Second
debInstall = "deb"
rpmInstall = "rpm"
retryNumber = 10
retryTime = 30 * time.Second
debInstall = "deb"
rpmInstall = "rpm"
)

func main() {
installType := os.Args[1]
installCommand := ""

debInstallCommand := "sudo dpkg -i -E ./amazon-cloudwatch-agent.deb"
rpmInstallCommand := "sudo rpm -U ./amazon-cloudwatch-agent.rpm"
if os.Geteuid() == 0 {
Expand Down
10 changes: 6 additions & 4 deletions test/acceptance/filepermissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ package acceptance

import (
"fmt"
"log"
"testing"
"time"

"github.com/stretchr/testify/assert"

"github.com/aws/amazon-cloudwatch-agent-test/environment"
"github.com/aws/amazon-cloudwatch-agent-test/filesystem"
"github.com/aws/amazon-cloudwatch-agent-test/test/status"
"github.com/aws/amazon-cloudwatch-agent-test/util/common"
"github.com/stretchr/testify/assert"
"log"
"testing"
"time"
)

func init() {
Expand Down
3 changes: 2 additions & 1 deletion test/acceptance/filepermissions_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
"log"
"time"

"go.uber.org/multierr"

"github.com/aws/amazon-cloudwatch-agent-test/filesystem"
"github.com/aws/amazon-cloudwatch-agent-test/util/common"
"go.uber.org/multierr"
)

const (
Expand Down
5 changes: 3 additions & 2 deletions test/assume_role/assume_role_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ package assume_role
import (
"log"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"

"github.com/aws/amazon-cloudwatch-agent-test/environment"
"github.com/aws/amazon-cloudwatch-agent-test/test/metric"
"github.com/aws/amazon-cloudwatch-agent-test/test/metric/dimension"
"github.com/aws/amazon-cloudwatch-agent-test/test/status"
"github.com/aws/amazon-cloudwatch-agent-test/test/test_runner"
"github.com/aws/amazon-cloudwatch-agent-test/util/common"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
)

const (
Expand Down
5 changes: 3 additions & 2 deletions test/assume_role/assume_role_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import (
"log"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"

"github.com/aws/amazon-cloudwatch-agent-test/environment"
"github.com/aws/amazon-cloudwatch-agent-test/filesystem"
"github.com/aws/amazon-cloudwatch-agent-test/util/awsservice"
"github.com/aws/amazon-cloudwatch-agent-test/util/common"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
)

const (
Expand Down
9 changes: 5 additions & 4 deletions test/ca_bundle/ca_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ package ca_bundle
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
"github.com/aws/aws-sdk-go-v2/service/s3"
"log"
"os"
"strings"
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
"github.com/aws/aws-sdk-go-v2/service/s3"

"github.com/aws/amazon-cloudwatch-agent-test/environment"
"github.com/aws/amazon-cloudwatch-agent-test/util/common"
)
Expand Down
5 changes: 3 additions & 2 deletions test/canary/canary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (
"strings"
"testing"

"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
"github.com/stretchr/testify/require"

"github.com/aws/amazon-cloudwatch-agent-test/environment"
"github.com/aws/amazon-cloudwatch-agent-test/util/awsservice"
"github.com/aws/amazon-cloudwatch-agent-test/util/common"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
"github.com/stretchr/testify/require"
)

const (
Expand Down
12 changes: 7 additions & 5 deletions test/cloudformation/cloudformation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ package cloudformation
import (
"context"
"flag"
"github.com/aws/amazon-cloudwatch-agent-test/test/metric"
"github.com/aws/amazon-cloudwatch-agent-test/test/metric/dimension"
"github.com/aws/amazon-cloudwatch-agent-test/util/awsservice"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
"log"
"os"
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudformation/types"

"github.com/aws/amazon-cloudwatch-agent-test/test/metric"
"github.com/aws/amazon-cloudwatch-agent-test/test/metric/dimension"
"github.com/aws/amazon-cloudwatch-agent-test/util/awsservice"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion test/ecs/ecs_metadata/ecs_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
_ "embed"
"flag"
"fmt"
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types"
"log"
"strings"
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types"
"github.com/stretchr/testify/assert"

"github.com/aws/amazon-cloudwatch-agent-test/util/awsservice"
Expand Down
11 changes: 8 additions & 3 deletions test/emf/emf_container_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

//go:build !windows

package emf

import (
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"

"github.com/aws/amazon-cloudwatch-agent-test/test/metric"
"github.com/aws/amazon-cloudwatch-agent-test/test/metric/dimension"
"github.com/aws/amazon-cloudwatch-agent-test/test/status"
"github.com/aws/amazon-cloudwatch-agent-test/test/test_runner"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
"time"
)

type EMFTestRunner struct {
Expand Down
8 changes: 5 additions & 3 deletions test/emf/emf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ package emf

import (
"fmt"
"log"
"testing"

"github.com/stretchr/testify/suite"

"github.com/aws/amazon-cloudwatch-agent-test/environment"
"github.com/aws/amazon-cloudwatch-agent-test/environment/computetype"
"github.com/aws/amazon-cloudwatch-agent-test/test/metric/dimension"
"github.com/aws/amazon-cloudwatch-agent-test/test/status"
"github.com/aws/amazon-cloudwatch-agent-test/test/test_runner"
"github.com/stretchr/testify/suite"
"log"
"testing"
)

type MetricBenchmarkTestSuite struct {
Expand Down
3 changes: 3 additions & 0 deletions test/emf_concurrent/emf_concurrent_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package emf_concurrent

import (
Expand Down
3 changes: 3 additions & 0 deletions test/emf_concurrent/emitter.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package emf_concurrent

import (
Expand Down
3 changes: 2 additions & 1 deletion test/fips/fips_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/aws"

"github.com/aws/amazon-cloudwatch-agent-test/environment"
"github.com/aws/amazon-cloudwatch-agent-test/test/metric"
"github.com/aws/amazon-cloudwatch-agent-test/test/metric/dimension"
"github.com/aws/amazon-cloudwatch-agent-test/test/status"
"github.com/aws/amazon-cloudwatch-agent-test/util/common"
"github.com/aws/aws-sdk-go-v2/aws"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion test/lvm/lvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import (
"os"
"testing"

"github.com/aws/aws-sdk-go-v2/aws"

"github.com/aws/amazon-cloudwatch-agent-test/environment"
"github.com/aws/amazon-cloudwatch-agent-test/test/metric"
"github.com/aws/amazon-cloudwatch-agent-test/test/metric/dimension"
"github.com/aws/amazon-cloudwatch-agent-test/test/status"
"github.com/aws/amazon-cloudwatch-agent-test/test/test_runner"
"github.com/aws/amazon-cloudwatch-agent-test/util/common"
"github.com/aws/aws-sdk-go-v2/aws"
)

const namespace = "LVMTest"
Expand Down
8 changes: 5 additions & 3 deletions test/metric/dimension/container_insights_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
package dimension

import (
"github.com/aws/amazon-cloudwatch-agent-test/environment/computetype"
"github.com/aws/amazon-cloudwatch-agent-test/util/awsservice"
"log"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
"log"

"github.com/aws/amazon-cloudwatch-agent-test/environment/computetype"
"github.com/aws/amazon-cloudwatch-agent-test/util/awsservice"
)

type ContainerInsightsDimensionProvider struct {
Expand Down
Loading