From 79d96437454226a234300553c8e89ecf7e0cd8d9 Mon Sep 17 00:00:00 2001 From: Marcin Czenko Date: Thu, 27 Nov 2025 21:22:35 +0100 Subject: [PATCH 1/6] adds launch configuration for more convenient debugging --- .vscode/launch.json | 77 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..153cf4e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,77 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Debug Current Test", + "type": "go", + "request": "launch", + "mode": "test", + "program": "${fileDirname}", + "args": ["-test.v", "-test.run", "^${selectedText}$"], + "env": { + "CGO_ENABLED": "1" + } + }, + { + "name": "Debug Current Test Function", + "type": "go", + "request": "launch", + "mode": "test", + "program": "${fileDirname}", + "env": { + "CGO_ENABLED": "1" + } + }, + { + "name": "Debug All Tests in Current File", + "type": "go", + "request": "launch", + "mode": "test", + "program": "${fileDirname}", + "args": ["-test.v"], + "env": { + "CGO_ENABLED": "1" + } + }, + { + "name": "Debug All Tests in Current Package", + "type": "go", + "request": "launch", + "mode": "test", + "program": "${fileDirname}", + "args": ["-test.v", "-count=1"], + "env": { + "CGO_ENABLED": "1" + } + }, + { + "name": "Debug Codex Tests", + "type": "go", + "request": "launch", + "mode": "test", + "program": "${workspaceFolder}/codex", + "args": ["-test.v"], + "env": { + "CGO_ENABLED": "1" + } + }, + { + "name": "Debug Specific Test (e.g., TestUpload)", + "type": "go", + "request": "launch", + "mode": "test", + "program": "${workspaceFolder}/codex", + "args": [ + "-test.v", + "-test.run", + "TestUpload" + ], + "env": { + "CGO_ENABLED": "1" + } + } + ] +} From 99cffb1829ed40e931c8f4a0b326e73c8d41439f Mon Sep 17 00:00:00 2001 From: Marcin Czenko Date: Thu, 27 Nov 2025 21:23:24 +0100 Subject: [PATCH 2/6] adds possibility to run selected tests with "make test " --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d7ddf34..4656b5a 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,10 @@ build: test: @echo "Running tests..." - CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" GOTESTFLAGS="-timeout=2m" go test ./... + CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" GOTESTFLAGS="-timeout=2m" gotestsum --packages="./..." -f testname -- $(if $(filter-out test,$(MAKECMDGOALS)),-run "$(filter-out test,$(MAKECMDGOALS))") + +%: + @: clean: @echo "Cleaning up..." From be94580b23c8e05d0c1aa9218afbd4aa7c9561b4 Mon Sep 17 00:00:00 2001 From: Marcin Czenko Date: Fri, 28 Nov 2025 00:59:05 +0100 Subject: [PATCH 3/6] adds extra make target to Makefile allowing you to pass parameters to go test --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 4656b5a..0770cda 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,10 @@ test: @echo "Running tests..." CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" GOTESTFLAGS="-timeout=2m" gotestsum --packages="./..." -f testname -- $(if $(filter-out test,$(MAKECMDGOALS)),-run "$(filter-out test,$(MAKECMDGOALS))") +test-with-params: + @echo "Running tests..." + CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" GOTESTFLAGS="-timeout=2m" gotestsum --packages="./..." -f testname -- $(ARGS) + %: @: From 316d2bde6cf72a69fecc54aa03bcefe0c194f0eb Mon Sep 17 00:00:00 2001 From: Marcin Czenko Date: Fri, 28 Nov 2025 01:05:21 +0100 Subject: [PATCH 4/6] adds make target to build the lib with debug API --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 0770cda..8678dea 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,10 @@ libcodex: @echo "Building libcodex..." @$(MAKE) -C $(NIM_CODEX_DIR) libcodex +libcodex-with-debug-api: + @echo "Building libcodex..." + @$(MAKE) -C $(NIM_CODEX_DIR) libcodex CODEX_LIB_PARAMS="-d:codex_enable_api_debug_peers" + build: @echo "Building Codex Go Bindings..." CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go build -o codex-go ./codex From d8b21f20874352aae7af2791fc000794f31bda06 Mon Sep 17 00:00:00 2001 From: Marcin Czenko Date: Fri, 28 Nov 2025 01:08:18 +0100 Subject: [PATCH 5/6] Installs gotestsum on the CI --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 524feac..090c70b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,5 +46,8 @@ jobs: - name: Build codex go run: make + - name: Install gotestsum + run: go install gotest.tools/gotestsum@latest + - name: Go test run: make test From 2cd2df0beb115b51ea19f3c99e669f7add7c7c2a Mon Sep 17 00:00:00 2001 From: Marcin Czenko Date: Fri, 28 Nov 2025 01:48:34 +0100 Subject: [PATCH 6/6] Updates README --- README.md | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 29e3c20..ae7c92b 100644 --- a/README.md +++ b/README.md @@ -78,22 +78,63 @@ Follow these steps to install and set up the module: 1. Make sure your system has the [prerequisites](https://github.com/codex-storage/nim-codex) to run a local Codex node. 2. Fetch the dependencies: - ``` + ```sh make update ``` 3. Build the library: - ``` + ```sh make libcodex ``` You can pass flags to the Codex building step by using `CODEX_LIB_PARAMS`. For example, if you want to enable debug API for peers, you can build the library using: -``` +```sh CODEX_LIB_PARAMS="-d:codex_enable_api_debug_peers=true" make libcodex ``` +or you can use a convenience `libcodex-with-debug-api` make target: + +```sh +make libcodex-with-debug-api +``` + +To run the test, you have to make sure you have `gotestsum` installed on your system, e.g.: + +```sh +go install gotest.tools/gotestsum@latest +``` + +Then you can run the tests as follows. + +To run all the tests: + +```sh +make test +``` + +To run selected test only: + +```sh +make test "TestDownloadManifest$" +``` + +> We use `$` to make sure we run only the `TestDownloadManifest` test. +> Without `$` we would run all the tests starting with `TestDownloadManifest` and +> so also `TestDownloadManifestWithNotExistingCid` +> + +If you need to pass more arguments to the underlying `go test` (`gotestsum` passes +everything after `--` to `go test`), you can use: `test-with-params` make target, e.g.: + +```sh +make test-with-params ARGS='-run "TestDownloadManifest$$" -count=2' +``` + +> Here, we use double escape `$$` instead of just `$`, otherwise make +> will interpret `$` as a make variable inside `ARGS`. + Now the module is ready for use in your project. The release process is defined [here](./RELEASE.md).