From 100ca35a3ff4b86158480ba5f2e5d10540006867 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Wed, 29 Oct 2025 05:51:35 +0100 Subject: [PATCH] Apply PR reviews --- .github/workflows/ci.yml | 7 +- .vscode/settings.json | 2 +- Makefile | 9 ++- README.md | 65 ++++++++++++++++++- ...dex_archive_downloader_integration_test.go | 2 +- communities/codex_client_integration_test.go | 2 +- communities/codex_client_test.go | 2 +- ...codex_index_downloader_integration_test.go | 2 +- communities/{testutil.go => testutil_test.go} | 7 +- 9 files changed, 83 insertions(+), 15 deletions(-) rename communities/{testutil.go => testutil_test.go} (77%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb08f4b..172445f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,10 @@ jobs: with: go-version: '1.23' cache: true - + + - name: Install gotestsum + run: go install gotest.tools/gotestsum@latest + - name: Install gomock (for code generation) run: go install go.uber.org/mock/mockgen@latest @@ -46,7 +49,7 @@ jobs: run: make build - name: Run unit tests - run: make test + run: make test-ci - name: Run integration tests run: make test-integration diff --git a/.vscode/settings.json b/.vscode/settings.json index 62cfde8..81aa3c3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,7 @@ "go.testTags": "codex_integration", "gopls": { "buildFlags": [ - "-tags=integration" + "-tags=codex_integration" ] }, "go.toolsEnvVars": { diff --git a/Makefile b/Makefile index 0836c7e..f1d341d 100644 --- a/Makefile +++ b/Makefile @@ -34,15 +34,20 @@ build: build-upload build-download test: @echo "Running unit tests..." - CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go test -v ./communities + CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" gotestsum --packages="./communities" -f standard-verbose -- -v + +test-ci: + @echo "Running unit tests..." + CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" gotestsum --packages="./communities" -f standard-verbose -- -race -v test-integration: @echo "Running tests..." - CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go test -v -tags=codex_integration ./communities -run Integration -timeout 60s + CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" gotestsum --packages="./communities" -f standard-verbose -- -tags=codex_integration -run Integration -timeout 60s coverage: @echo "Running unit tests with coverage..." CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go test -coverprofile=coverage.out ./communities + go tool cover -func=coverage.out clean: rm -f $(BIN_NAME) diff --git a/README.md b/README.md index 97c51e6..bf88ea9 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,10 @@ A lightweight Go client utility for interacting with Codex client. We will be running codex client, and then use a small testing utility to check if the low level abstraction - CodexClient - correctly uploads and downloads the content. -### Integration Codex library +### Integration with Codex library You need to download the library file by using: - -```sh +bash make fetch ``` @@ -89,6 +88,66 @@ To run the integration test, use `test-integration`: make test-integration ``` +You can use your own Go test commands but you will need to export the `CGO` variables first: + +```bash +export LIBS_DIR="$(realpath ./libs)" +export CGO_CFLAGS=-I$LIBS_DIR +export CGO_LDFLAGS="-L$LIBS_DIR -lcodex -Wl,-rpath,$LIBS_DIR" +``` + +Then you can use: + +```bash +❯ go test -v ./communities -count 1 +``` + +To be more selective, e.g. in order to run all the tests from +`CodexArchiveDownloaderSuite`, run: + +```bash +go test -v ./communities -run CodexArchiveDownloader -count 1 +``` + +or for an individual test from that suite: + +```bash +go test -v ./communities -run TestCodexArchiveDownloaderSuite/TestCancellationDuringPolling -count 1 +``` + +You can also use `gotestsum` to run the tests (you may need to install it first, e.g. `go install gotest.tools/gotestsum@v1.13.0`): + +```bash +gotestsum --packages="./communities" -f testname --rerun-fails -- -count 1 +``` + +For a more verbose output including logs use `-f standard-verbose`, e.g.: + +```bash +gotestsum --packages="./communities" -f standard-verbose --rerun-fails -- -v -count 1 +``` + +To be more selective, e.g. in order to run all the tests from +`CodexArchiveDownloaderSuite`, run: + +```bash +gotestsum --packages="./communities" -f testname --rerun-fails -- -run CodexArchiveDownloader -count 1 +``` + +or for an individual test from that suite: + +```bash +gotestsum --packages="./communities" -f testname --rerun-fails -- -run TestCodexArchiveDownloaderSuite/TestCancellationDuringPolling -count 1 +``` + +Notice, that the `-run` flag accepts a regular expression that matches against the full test path, so you can be more concise in naming if necessary, e.g.: + +```bash +gotestsum --packages="./communities" -f testname --rerun-fails -- -run CodexArchiveDownloader/Cancellation -count 1 +``` + +This also applies to native `go test` command. + ### Regenerating artifacts Everything you need comes included in the repo. But if you decide to change things, diff --git a/communities/codex_archive_downloader_integration_test.go b/communities/codex_archive_downloader_integration_test.go index e6672b1..803ed1f 100644 --- a/communities/codex_archive_downloader_integration_test.go +++ b/communities/codex_archive_downloader_integration_test.go @@ -42,7 +42,7 @@ func (suite *CodexArchiveDownloaderIntegrationSuite) SetupSuite() { suite.T().Fatalf("Failed to create CodexClient: %v", err) } - suite.T().Logf("CodexClient configured for") + suite.T().Logf("CodexClient configured") } // TearDownSuite runs once after all tests in the suite diff --git a/communities/codex_client_integration_test.go b/communities/codex_client_integration_test.go index 902a22d..8509e88 100644 --- a/communities/codex_client_integration_test.go +++ b/communities/codex_client_integration_test.go @@ -107,7 +107,7 @@ func (suite *CodexClientIntegrationTestSuite) TestIntegration_CheckNonExistingCI } func (suite *CodexClientIntegrationTestSuite) TestIntegration_TriggerDownload() { - client := communities.NewCodexClientTest(suite.T()) + client := NewCodexClientTest(suite.T()) // Generate random payload to ensure proper round-trip verification payload := make([]byte, 1024) diff --git a/communities/codex_client_test.go b/communities/codex_client_test.go index cf4fbc2..0db7d01 100644 --- a/communities/codex_client_test.go +++ b/communities/codex_client_test.go @@ -37,7 +37,7 @@ type CodexClientTestSuite struct { // SetupTest runs before each test method func (suite *CodexClientTestSuite) SetupTest() { - suite.client = communities.NewCodexClientTest(suite.T()) + suite.client = NewCodexClientTest(suite.T()) } // TearDownTest runs after each test method diff --git a/communities/codex_index_downloader_integration_test.go b/communities/codex_index_downloader_integration_test.go index 1680546..7b8c8a7 100644 --- a/communities/codex_index_downloader_integration_test.go +++ b/communities/codex_index_downloader_integration_test.go @@ -35,7 +35,7 @@ type CodexIndexDownloaderIntegrationTestSuite struct { // SetupSuite runs once before all tests in the suite func (suite *CodexIndexDownloaderIntegrationTestSuite) SetupSuite() { - suite.client = communities.NewCodexClientTest(suite.T()) + suite.client = NewCodexClientTest(suite.T()) // Create logger suite.logger, _ = zap.NewDevelopment() diff --git a/communities/testutil.go b/communities/testutil_test.go similarity index 77% rename from communities/testutil.go rename to communities/testutil_test.go index fbe8aff..d38e652 100644 --- a/communities/testutil.go +++ b/communities/testutil_test.go @@ -1,13 +1,14 @@ -package communities +package communities_test import ( + "go-codex-client/communities" "testing" "github.com/codex-storage/codex-go-bindings/codex" ) -func NewCodexClientTest(t *testing.T) *CodexClient { - client, err := NewCodexClient(codex.Config{ +func NewCodexClientTest(t *testing.T) *communities.CodexClient { + client, err := communities.NewCodexClient(codex.Config{ DataDir: t.TempDir(), LogFormat: codex.LogFormatNoColors, MetricsEnabled: false,