mirror of
https://github.com/logos-storage/logos-storage-go.git
synced 2026-01-04 06:13:07 +00:00
Apply PR reviews
This commit is contained in:
parent
3d00c81417
commit
100ca35a3f
7
.github/workflows/ci.yml
vendored
7
.github/workflows/ci.yml
vendored
@ -18,7 +18,10 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
go-version: '1.23'
|
go-version: '1.23'
|
||||||
cache: true
|
cache: true
|
||||||
|
|
||||||
|
- name: Install gotestsum
|
||||||
|
run: go install gotest.tools/gotestsum@latest
|
||||||
|
|
||||||
- name: Install gomock (for code generation)
|
- name: Install gomock (for code generation)
|
||||||
run: go install go.uber.org/mock/mockgen@latest
|
run: go install go.uber.org/mock/mockgen@latest
|
||||||
|
|
||||||
@ -46,7 +49,7 @@ jobs:
|
|||||||
run: make build
|
run: make build
|
||||||
|
|
||||||
- name: Run unit tests
|
- name: Run unit tests
|
||||||
run: make test
|
run: make test-ci
|
||||||
|
|
||||||
- name: Run integration tests
|
- name: Run integration tests
|
||||||
run: make test-integration
|
run: make test-integration
|
||||||
|
|||||||
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -2,7 +2,7 @@
|
|||||||
"go.testTags": "codex_integration",
|
"go.testTags": "codex_integration",
|
||||||
"gopls": {
|
"gopls": {
|
||||||
"buildFlags": [
|
"buildFlags": [
|
||||||
"-tags=integration"
|
"-tags=codex_integration"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"go.toolsEnvVars": {
|
"go.toolsEnvVars": {
|
||||||
|
|||||||
9
Makefile
9
Makefile
@ -34,15 +34,20 @@ build: build-upload build-download
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
@echo "Running unit tests..."
|
@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:
|
test-integration:
|
||||||
@echo "Running tests..."
|
@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:
|
coverage:
|
||||||
@echo "Running unit tests with coverage..."
|
@echo "Running unit tests with coverage..."
|
||||||
CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go test -coverprofile=coverage.out ./communities
|
CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go test -coverprofile=coverage.out ./communities
|
||||||
|
go tool cover -func=coverage.out
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(BIN_NAME)
|
rm -f $(BIN_NAME)
|
||||||
|
|||||||
65
README.md
65
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.
|
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:
|
You need to download the library file by using:
|
||||||
|
bash
|
||||||
```sh
|
|
||||||
make fetch
|
make fetch
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -89,6 +88,66 @@ To run the integration test, use `test-integration`:
|
|||||||
make 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
|
### Regenerating artifacts
|
||||||
|
|
||||||
Everything you need comes included in the repo. But if you decide to change things,
|
Everything you need comes included in the repo. But if you decide to change things,
|
||||||
|
|||||||
@ -42,7 +42,7 @@ func (suite *CodexArchiveDownloaderIntegrationSuite) SetupSuite() {
|
|||||||
suite.T().Fatalf("Failed to create CodexClient: %v", err)
|
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
|
// TearDownSuite runs once after all tests in the suite
|
||||||
|
|||||||
@ -107,7 +107,7 @@ func (suite *CodexClientIntegrationTestSuite) TestIntegration_CheckNonExistingCI
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *CodexClientIntegrationTestSuite) TestIntegration_TriggerDownload() {
|
func (suite *CodexClientIntegrationTestSuite) TestIntegration_TriggerDownload() {
|
||||||
client := communities.NewCodexClientTest(suite.T())
|
client := NewCodexClientTest(suite.T())
|
||||||
|
|
||||||
// Generate random payload to ensure proper round-trip verification
|
// Generate random payload to ensure proper round-trip verification
|
||||||
payload := make([]byte, 1024)
|
payload := make([]byte, 1024)
|
||||||
|
|||||||
@ -37,7 +37,7 @@ type CodexClientTestSuite struct {
|
|||||||
|
|
||||||
// SetupTest runs before each test method
|
// SetupTest runs before each test method
|
||||||
func (suite *CodexClientTestSuite) SetupTest() {
|
func (suite *CodexClientTestSuite) SetupTest() {
|
||||||
suite.client = communities.NewCodexClientTest(suite.T())
|
suite.client = NewCodexClientTest(suite.T())
|
||||||
}
|
}
|
||||||
|
|
||||||
// TearDownTest runs after each test method
|
// TearDownTest runs after each test method
|
||||||
|
|||||||
@ -35,7 +35,7 @@ type CodexIndexDownloaderIntegrationTestSuite struct {
|
|||||||
|
|
||||||
// SetupSuite runs once before all tests in the suite
|
// SetupSuite runs once before all tests in the suite
|
||||||
func (suite *CodexIndexDownloaderIntegrationTestSuite) SetupSuite() {
|
func (suite *CodexIndexDownloaderIntegrationTestSuite) SetupSuite() {
|
||||||
suite.client = communities.NewCodexClientTest(suite.T())
|
suite.client = NewCodexClientTest(suite.T())
|
||||||
|
|
||||||
// Create logger
|
// Create logger
|
||||||
suite.logger, _ = zap.NewDevelopment()
|
suite.logger, _ = zap.NewDevelopment()
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
package communities
|
package communities_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go-codex-client/communities"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/codex-storage/codex-go-bindings/codex"
|
"github.com/codex-storage/codex-go-bindings/codex"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCodexClientTest(t *testing.T) *CodexClient {
|
func NewCodexClientTest(t *testing.T) *communities.CodexClient {
|
||||||
client, err := NewCodexClient(codex.Config{
|
client, err := communities.NewCodexClient(codex.Config{
|
||||||
DataDir: t.TempDir(),
|
DataDir: t.TempDir(),
|
||||||
LogFormat: codex.LogFormatNoColors,
|
LogFormat: codex.LogFormatNoColors,
|
||||||
MetricsEnabled: false,
|
MetricsEnabled: false,
|
||||||
Loading…
x
Reference in New Issue
Block a user