Skip to content

Commit fdb73a7

Browse files
committed
chore(test): rename deps → check-deps and restructure dependency management
Rename `make deps` to `make check-deps` with consistent `check-deps-*` prefixes across scripts and Makefile targets. Add Makefile-level OS-dispatched `install-deps-*` targets for darwin and linux, a Docker memory check (`check-docker-available-memory`), and wire `check-deps` as a prerequisite for all test entry points. Key changes: - Rename 7 check scripts: check-{tool}.sh → check-deps-{tool}.sh - Restructure t/Makefile with three-way check flow (silent pass, auto-install, or report-and-fail) for each dependency - Add install-deps-*-darwin targets (all depend on Homebrew check) - Add install-deps-*-linux targets with package manager detection - Linux Go install prints instructions instead of auto-installing (avoids destructive sudo rm -rf /usr/local/go) - Add check-docker-available-memory.sh (warns if < 8GB, auto-fix on macOS with AUTO_INSTALL=true) - Add check-deps prereq to test and test-benchmark targets - Update TESTING.md references and validation list
1 parent d2adb32 commit fdb73a7

12 files changed

Lines changed: 293 additions & 41 deletions

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@ uninstall: ## Uninstall dgraph binary
8484
dgraph-installed:
8585
$(MAKE) install
8686

87-
.PHONY: deps
88-
deps: ## Check test dependencies (pass AUTO_INSTALL=true to auto-install missing ones)
89-
$(MAKE) -C t deps
87+
.PHONY: check-deps
88+
check-deps: ## Check test dependencies (pass AUTO_INSTALL=true to auto-install missing ones)
89+
$(MAKE) -C t check-deps
9090

9191
.PHONY: setup
9292
setup: ## Install all test dependencies automatically
93-
$(MAKE) deps AUTO_INSTALL=true
93+
$(MAKE) check-deps AUTO_INSTALL=true
9494

9595
.PHONY: test
96-
test: dgraph-installed local-image ## Run tests (default: integration + integration2)
96+
test: check-deps dgraph-installed local-image ## Run tests (default: integration + integration2)
9797
ifdef TAGS
9898
@echo "Running tests with tags: $(TAGS)"
9999
go test -v --tags="$(TAGS)" \
@@ -177,7 +177,7 @@ test-all: ## Every test: all t/ suites + integration2 + upgrade + fuzz
177177
$(MAKE) test-fuzz
178178

179179
.PHONY: test-benchmark
180-
test-benchmark: ## Go benchmarks (i.e. 'go test -bench')
180+
test-benchmark: check-deps ## Go benchmarks (i.e. 'go test -bench')
181181
go test -bench=. -benchmem $(if $(PKG),./$(PKG)/...,./...)
182182

183183
.PHONY: local-image

TESTING.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,28 @@ auto-install them:
142142
make setup
143143

144144
# Check dependencies without installing (reports what's missing)
145-
make deps
145+
make check-deps
146146

147-
# Same as 'make deps' but auto-installs anything missing
148-
make deps AUTO_INSTALL=true
147+
# Same as 'make check-deps' but auto-installs anything missing
148+
make check-deps AUTO_INSTALL=true
149149
```
150150

151151
The check scripts validate:
152152

153-
- Go version (1.21+)
154-
- Docker and Docker Compose versions and memory allocation
153+
- Go version (matches go.mod requirement)
154+
- Docker and Docker Compose versions
155+
- Docker available memory (warns if < 8GB, with auto-fix on macOS)
155156
- gotestsum installation
156157
- ack installation
158+
- Cross-compiler for non-Linux hosts (macOS)
159+
- protoc installation (Linux only)
157160
- Dgraph binary existence and correct architecture
158161

159162
### Required Tools
160163

161-
> **Note:** You don't need to install these manually. Running `make setup` from the repo root
162-
> automatically installs missing dependencies. The commands below are listed for reference.
164+
> **Note:** You do **not** need to install these manually. Running `make setup` or
165+
> `make check-deps AUTO_INSTALL=true` from the repo root automatically checks and installs all
166+
> missing dependencies. The commands below are listed only as reference for what gets installed.
163167
164168
#### 1. Go (1.21+)
165169

t/Makefile

Lines changed: 206 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# SPDX-License-Identifier: Apache-2.0
44
#
55

6+
# OS detection (lowercase: linux, darwin)
7+
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
8+
69
# linux || darwin
710
GOOS ?= $(shell go env GOOS)
811
export GOPATH ?= $(shell go env GOPATH)
@@ -18,15 +21,16 @@ endif
1821

1922
all: test
2023

21-
.PHONY: deps
22-
deps: check-go check-docker check-gotestsum check-ack check-cross-compiler
23-
@if [ "$(GOOS)" = "linux" ]; then \
24-
which protoc > /dev/null 2>&1 || (echo "Error: protoc is not installed or not in PATH" && exit 1); \
25-
fi
24+
# ===========================================================================
25+
# Dependency checking
26+
# ===========================================================================
27+
28+
.PHONY: check-deps
29+
check-deps: check-deps-go check-deps-docker check-deps-gotestsum check-deps-ack check-deps-cross-compiler check-deps-protoc check-docker-available-memory
2630
@echo "All dependencies are installed"
2731

2832
.PHONY: check
29-
check: deps
33+
check: check-deps
3034
@echo "LINUX_GOBIN=$(LINUX_GOBIN)"
3135
@if [ -f "$(LINUX_GOBIN)/dgraph" ]; then \
3236
file $(LINUX_GOBIN)/dgraph | grep -q "ELF.*executable" || (echo "Error: dgraph binary at $(LINUX_GOBIN)/dgraph is not a Linux executable" && exit 1); \
@@ -35,33 +39,208 @@ check: deps
3539
fi
3640
@echo "The dgraph binary is a Linux executable (as required)"
3741

38-
.PHONY: check-docker
39-
check-docker:
40-
@./scripts/check-docker.sh
42+
# ---- check-deps-{tool} targets ----
43+
#
44+
# Flow for each tool:
45+
# 1. Silent check → pass → done
46+
# 2. Silent check → fail + AUTO_INSTALL=true → install via OS target → re-check
47+
# 3. Silent check → fail + no AUTO_INSTALL → re-run with output → exit 1
48+
49+
.PHONY: check-deps-go
50+
check-deps-go:
51+
@if AUTO_INSTALL= ./scripts/check-deps-go.sh >/dev/null 2>&1; then \
52+
:; \
53+
elif [ "$(AUTO_INSTALL)" = "true" ]; then \
54+
$(MAKE) install-deps-go-$(OS) && \
55+
AUTO_INSTALL= ./scripts/check-deps-go.sh; \
56+
else \
57+
AUTO_INSTALL= ./scripts/check-deps-go.sh || exit 1; \
58+
fi
59+
60+
.PHONY: check-deps-docker
61+
check-deps-docker:
62+
@if AUTO_INSTALL= ./scripts/check-deps-docker.sh >/dev/null 2>&1; then \
63+
:; \
64+
elif [ "$(AUTO_INSTALL)" = "true" ]; then \
65+
$(MAKE) install-deps-docker-$(OS) && \
66+
AUTO_INSTALL= ./scripts/check-deps-docker.sh; \
67+
else \
68+
AUTO_INSTALL= ./scripts/check-deps-docker.sh || exit 1; \
69+
fi
70+
71+
.PHONY: check-deps-gotestsum
72+
check-deps-gotestsum:
73+
@if AUTO_INSTALL= ./scripts/check-deps-gotestsum.sh >/dev/null 2>&1; then \
74+
:; \
75+
elif [ "$(AUTO_INSTALL)" = "true" ]; then \
76+
$(MAKE) install-deps-gotestsum-$(OS) && \
77+
AUTO_INSTALL= ./scripts/check-deps-gotestsum.sh; \
78+
else \
79+
AUTO_INSTALL= ./scripts/check-deps-gotestsum.sh || exit 1; \
80+
fi
81+
82+
.PHONY: check-deps-ack
83+
check-deps-ack:
84+
@if AUTO_INSTALL= ./scripts/check-deps-ack.sh >/dev/null 2>&1; then \
85+
:; \
86+
elif [ "$(AUTO_INSTALL)" = "true" ]; then \
87+
$(MAKE) install-deps-ack-$(OS) && \
88+
AUTO_INSTALL= ./scripts/check-deps-ack.sh; \
89+
else \
90+
AUTO_INSTALL= ./scripts/check-deps-ack.sh || exit 1; \
91+
fi
92+
93+
.PHONY: check-deps-cross-compiler
94+
check-deps-cross-compiler:
95+
@if AUTO_INSTALL= ./scripts/check-deps-cross-compiler.sh >/dev/null 2>&1; then \
96+
:; \
97+
elif [ "$(AUTO_INSTALL)" = "true" ]; then \
98+
$(MAKE) install-deps-cross-compiler-$(OS) && \
99+
AUTO_INSTALL= ./scripts/check-deps-cross-compiler.sh; \
100+
else \
101+
AUTO_INSTALL= ./scripts/check-deps-cross-compiler.sh || exit 1; \
102+
fi
103+
104+
.PHONY: check-deps-protoc
105+
check-deps-protoc:
106+
@if [ "$(OS)" = "linux" ]; then \
107+
if AUTO_INSTALL= ./scripts/check-deps-protoc.sh >/dev/null 2>&1; then :; \
108+
elif [ "$(AUTO_INSTALL)" = "true" ]; then \
109+
$(MAKE) install-deps-protoc-$(OS) && \
110+
AUTO_INSTALL= ./scripts/check-deps-protoc.sh; \
111+
else \
112+
AUTO_INSTALL= ./scripts/check-deps-protoc.sh || exit 1; \
113+
fi; \
114+
fi
115+
116+
# ---- Docker memory check ----
117+
118+
.PHONY: check-docker-available-memory
119+
check-docker-available-memory: check-deps-docker
120+
@$(MAKE) check-docker-available-memory-$(OS)
121+
122+
.PHONY: check-docker-available-memory-darwin
123+
check-docker-available-memory-darwin:
124+
@./scripts/check-docker-available-memory.sh
125+
126+
.PHONY: check-docker-available-memory-linux
127+
check-docker-available-memory-linux:
128+
@./scripts/check-docker-available-memory.sh
129+
130+
# ===========================================================================
131+
# Install targets — Homebrew prerequisite (darwin)
132+
# ===========================================================================
133+
134+
.PHONY: check-install-deps-homebrew-darwin
135+
check-install-deps-homebrew-darwin:
136+
@[ "$(OS)" = "darwin" ] || { echo "ERROR: Homebrew is only available on macOS"; exit 1; }
137+
@AUTO_INSTALL=$(AUTO_INSTALL) ./scripts/check-deps-brew.sh
138+
139+
# ===========================================================================
140+
# Install targets — darwin
141+
# ===========================================================================
142+
143+
.PHONY: install-deps-go-darwin
144+
install-deps-go-darwin: check-install-deps-homebrew-darwin
145+
@brew upgrade go 2>/dev/null || brew install go
146+
147+
.PHONY: install-deps-docker-darwin
148+
install-deps-docker-darwin: check-install-deps-homebrew-darwin
149+
@brew install --cask docker
150+
151+
.PHONY: install-deps-gotestsum-darwin
152+
install-deps-gotestsum-darwin: check-install-deps-homebrew-darwin
153+
@go install gotest.tools/gotestsum@latest
154+
155+
.PHONY: install-deps-ack-darwin
156+
install-deps-ack-darwin: check-install-deps-homebrew-darwin
157+
@brew install ack
158+
159+
.PHONY: install-deps-cross-compiler-darwin
160+
install-deps-cross-compiler-darwin: check-install-deps-homebrew-darwin
161+
@brew tap messense/macos-cross-toolchains && \
162+
brew install messense/macos-cross-toolchains/$$(case $$(uname -m) in arm64|aarch64) echo aarch64-unknown-linux-gnu;; x86_64) echo x86_64-unknown-linux-gnu;; esac)
163+
164+
.PHONY: install-deps-protoc-darwin
165+
install-deps-protoc-darwin: check-install-deps-homebrew-darwin
166+
@brew install protobuf
167+
168+
# ===========================================================================
169+
# Install targets — linux
170+
# ===========================================================================
171+
172+
.PHONY: install-deps-go-linux
173+
install-deps-go-linux:
174+
@echo ""; \
175+
echo "Go is not installed or is below the required version."; \
176+
echo ""; \
177+
VERSION=$$(grep -E '^go [0-9]+\.[0-9]+' ../go.mod | awk '{print $$2}'); \
178+
echo "Required version: Go $${VERSION} (from go.mod)"; \
179+
echo ""; \
180+
echo "Install or upgrade Go using the official instructions:"; \
181+
echo " https://go.dev/doc/install"; \
182+
echo ""; \
183+
ARCH=$$(uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/'); \
184+
echo "Quick steps for Linux:"; \
185+
echo " curl -fsSLO https://go.dev/dl/go$${VERSION}.linux-$${ARCH}.tar.gz"; \
186+
echo " sudo rm -rf /usr/local/go"; \
187+
echo " sudo tar -C /usr/local -xzf go$${VERSION}.linux-$${ARCH}.tar.gz"; \
188+
echo " export PATH=\$$PATH:/usr/local/go/bin"; \
189+
echo ""; \
190+
exit 1
191+
192+
.PHONY: install-deps-docker-linux
193+
install-deps-docker-linux:
194+
@if command -v apt-get >/dev/null 2>&1; then $(MAKE) install-deps-docker-linux-apt; \
195+
elif command -v dnf >/dev/null 2>&1; then $(MAKE) install-deps-docker-linux-dnf; \
196+
elif command -v pacman >/dev/null 2>&1; then $(MAKE) install-deps-docker-linux-pacman; \
197+
else echo "ERROR: No supported package manager found (tried: apt, dnf, pacman)"; exit 1; fi
198+
199+
.PHONY: install-deps-docker-linux-apt
200+
install-deps-docker-linux-apt:
201+
@sudo apt-get update && sudo apt-get install -y ca-certificates curl gnupg && \
202+
sudo install -m 0755 -d /etc/apt/keyrings && \
203+
curl -fsSL https://download.docker.com/linux/$$(. /etc/os-release && echo "$${ID:-ubuntu}")/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
204+
sudo chmod a+r /etc/apt/keyrings/docker.gpg && \
205+
echo "deb [arch=$$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/$$(. /etc/os-release && echo "$${ID:-ubuntu}") $$(. /etc/os-release && echo "$${VERSION_CODENAME}") stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null && \
206+
sudo apt-get update && \
207+
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
208+
209+
.PHONY: install-deps-docker-linux-dnf
210+
install-deps-docker-linux-dnf:
211+
@sudo dnf -y install dnf-plugins-core && \
212+
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo && \
213+
sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
41214

42-
.PHONY: check-gotestsum
43-
check-gotestsum:
44-
@./scripts/check-gotestsum.sh
215+
.PHONY: install-deps-docker-linux-pacman
216+
install-deps-docker-linux-pacman:
217+
@sudo pacman -S --noconfirm docker docker-compose
45218

46-
.PHONY: check-ack
47-
check-ack:
48-
@./scripts/check-ack.sh
219+
.PHONY: install-deps-gotestsum-linux
220+
install-deps-gotestsum-linux:
221+
@go install gotest.tools/gotestsum@latest
49222

50-
.PHONY: check-cross-compiler
51-
check-cross-compiler:
52-
@./scripts/check-cross-compiler.sh
223+
.PHONY: install-deps-ack-linux
224+
install-deps-ack-linux:
225+
@if command -v apt-get >/dev/null 2>&1; then sudo apt-get update && sudo apt-get install -y ack; \
226+
elif command -v dnf >/dev/null 2>&1; then sudo dnf install -y ack; \
227+
elif command -v pacman >/dev/null 2>&1; then sudo pacman -S --noconfirm ack; \
228+
else echo "ERROR: No supported package manager found (tried: apt, dnf, pacman)"; exit 1; fi
53229

54-
.PHONY: check-protoc
55-
check-protoc:
56-
@./scripts/check-protoc.sh
230+
.PHONY: install-deps-cross-compiler-linux
231+
install-deps-cross-compiler-linux:
232+
@: # Cross-compiler not needed on Linux
57233

58-
.PHONY: check-go
59-
check-go:
60-
@./scripts/check-go.sh
234+
.PHONY: install-deps-protoc-linux
235+
install-deps-protoc-linux:
236+
@if command -v apt-get >/dev/null 2>&1; then sudo apt-get update && sudo apt-get install -y protobuf-compiler; \
237+
elif command -v dnf >/dev/null 2>&1; then sudo dnf install -y protobuf-compiler; \
238+
elif command -v pacman >/dev/null 2>&1; then sudo pacman -S --noconfirm protobuf; \
239+
else echo "ERROR: No supported package manager found (tried: apt, dnf, pacman)"; exit 1; fi
61240

62-
.PHONY: check-brew
63-
check-brew:
64-
@./scripts/check-brew.sh
241+
# ===========================================================================
242+
# Build & test
243+
# ===========================================================================
65244

66245
.PHONY: dgraph-installed
67246
dgraph-installed:

0 commit comments

Comments
 (0)