Skip to content

Commit

Permalink
style: format makefile
Browse files Browse the repository at this point in the history
Signed-off-by: Rory Z <[email protected]>
  • Loading branch information
Rory-Z committed Oct 17, 2023
1 parent 1888df8 commit 523ec9b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
26 changes: 11 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Ensure that 'all' is the default target otherwise it will be the first target from Makefile.common.
all::
all: build

ARCH = $(shell go env GOARCH)
OS = $(shell go env GOOS)

.PHONY: build LOCALBIN
.PHONY: build
build:
CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH} go build -o .build/${OS}-${ARCH}/emqx-exporter
go build -o $(LOCALBIN)/$(PROJECT_NAME)

.PHONY: test
test:
test: build
go test -race --cover -covermode=atomic -coverpkg=./... -coverprofile=cover.out ./...

DOCKER_IMAGE_NAME ?= emqx-exporter
.PHONY: docker-build
docker-build:
docker build -t ${DOCKER_IMAGE_NAME} .
.PHONY: docker
docker:
docker build -t $(PROJECT_NAME) .

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/.build/${OS}-${ARCH}
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
PROJECT_NAME := emqx-exporter
LOCALBIN ?= $(PROJECT_DIR)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
mkdir -p $(LOCALBIN)
19 changes: 10 additions & 9 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,28 @@ import (
"github.com/prometheus/procfs"
)

var (
binary = filepath.Join(os.Getenv("GOPATH"), "bin/emqx-exporter")
)

const (
address = "localhost:19100"
address = "localhost:19100"
binary = "bin/emqx-exporter"
configFile = "config/example/config.yaml"
)

func TestFileDescriptorLeak(t *testing.T) {
if _, err := os.Stat(binary); err != nil {
t.Skipf("emqx-exporter binary not available, try to run `make build` first: %s", err)
// t.Skipf("emqx-exporter binary not available, try to run `make build` first: %s", err)
t.Errorf("emqx-exporter binary not available, try to run `make build` first: %s", err)
}

fs, err := procfs.NewDefaultFS()
if err != nil {
t.Skipf("proc filesystem is not available, but currently required to read number of open file descriptors: %s", err)
// t.Skipf("proc filesystem is not available, but currently required to read number of open file descriptors: %s", err)
t.Errorf("proc filesystem is not available, but currently required to read number of open file descriptors: %s", err)
}
if _, err := fs.Stat(); err != nil {
t.Errorf("unable to read process stats: %s", err)
}

exporter := exec.Command(binary, "--web.listen-address", address)
exporter := exec.Command(binary, "--web.listen-address", address, "--config.file", configFile)
test := func(pid int) error {
if err := queryExporter(address); err != nil {
return err
Expand Down Expand Up @@ -84,7 +85,7 @@ func TestHandlingOfDuplicatedMetrics(t *testing.T) {
t.Skipf("emqx-exporter binary not available, try to run `make build` first: %s", err)
}

dir, err := os.MkdirTemp("", "node-exporter")
dir, err := os.MkdirTemp("", "emqx-exporter")
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 523ec9b

Please sign in to comment.