Skip to content

Commit 6fa0f67

Browse files
authored
Fix tests (#436)
S3 tests were not working due to the disappearance of a public S3 bucket. A lotus API test was not working with an invalid token. - Run S3 tests against local s3 emulator. - Ignore for now test that creates folders in s3 (403 error) - Expect error when passing invalid token to lotus api - Update postgres test setup
1 parent 1384093 commit 6fa0f67

File tree

8 files changed

+267
-93
lines changed

8 files changed

+267
-93
lines changed

.github/actions/go-test-setup/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ runs:
1313
restore-keys: |
1414
${{ matrix.os }}-golang-${{ matrix.go }}-
1515
- name: Setup PostgreSQL database
16-
uses: ikalnytskyi/action-setup-postgres@v4
16+
uses: ikalnytskyi/action-setup-postgres@v6
1717
with:
1818
username: 'singularity'
1919
password: 'singularity'

.github/workflows/go-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ concurrency:
1515

1616
jobs:
1717
go-test:
18-
uses: ipdxco/unified-github-workflows/.github/workflows/go-test.yml@v0.0
18+
uses: ipdxco/unified-github-workflows/.github/workflows/go-test.yml@v1.0.2

cmd/functional_test.go

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import (
66
"io"
77
"os"
88
"path/filepath"
9+
"strings"
910
"testing"
1011

1112
"github.com/data-preservation-programs/singularity/model"
1213
"github.com/data-preservation-programs/singularity/storagesystem"
1314
"github.com/data-preservation-programs/singularity/util"
1415
"github.com/data-preservation-programs/singularity/util/testutil"
1516
uio "github.com/ipfs/go-unixfs/io"
17+
"github.com/orlangure/gnomock"
18+
"github.com/orlangure/gnomock/preset/localstack"
1619
"github.com/stretchr/testify/require"
1720
"gorm.io/gorm"
1821
)
@@ -209,18 +212,38 @@ func TestRescan(t *testing.T) {
209212
// 8. Extract into folder and compare with the original source
210213
// 9. Repeat above with different maxSize and inline
211214
func TestDataPrep(t *testing.T) {
215+
const (
216+
bucketName = "testbucket"
217+
)
218+
212219
// Prepare local source
213-
tmp := t.TempDir()
214220
s3tmp := t.TempDir()
215221

222+
err := os.MkdirAll(filepath.Join(s3tmp, bucketName), 0777)
223+
require.NoError(t, err)
224+
225+
p := localstack.Preset(
226+
localstack.WithServices(localstack.S3),
227+
localstack.WithS3Files(s3tmp),
228+
)
229+
localS3, err := gnomock.Start(p)
230+
if err != nil && strings.HasPrefix(err.Error(), "can't start container") {
231+
t.Skip("Docker required for s3 tests")
232+
}
233+
require.NoError(t, err)
234+
defer func() { _ = gnomock.Stop(localS3) }()
235+
216236
s3Handler, err := storagesystem.NewRCloneHandler(context.Background(), model.Storage{
217237
Type: "s3",
218-
Path: "public-dataset-test",
238+
Path: bucketName,
219239
Config: map[string]string{
220-
"region": "us-west-2",
221-
"provider": "AWS",
222-
"chunk_size": "5Mi",
223-
"list_chunk": "1000",
240+
"region": "us-east-1",
241+
"provider": "Other",
242+
"force_path_style": "true",
243+
"chunk_size": "5Mi",
244+
"list_chunk": "1000",
245+
"endpoint": fmt.Sprint("http://", localS3.Address(localstack.APIPort)),
246+
"env_auth": "false",
224247
},
225248
})
226249
require.NoError(t, err)
@@ -250,6 +273,7 @@ func TestDataPrep(t *testing.T) {
250273
uio.HAMTShardingSize = 1024
251274
defer func() { uio.HAMTShardingSize = originalShardingSize }()
252275

276+
tmp := t.TempDir()
253277
err = os.MkdirAll(filepath.Join(tmp, "smallfiles"), 0777)
254278
require.NoError(t, err)
255279
// create 100 random files
@@ -285,15 +309,17 @@ func TestDataPrep(t *testing.T) {
285309
sourceFlags string
286310
downloadFlags string
287311
compare string
312+
skip string
288313
}{
289314
{
290315
name: "s3-public",
291316
maxSize: 3 << 20,
292-
sourceType: "s3 aws",
293-
sourcePath: "public-dataset-test",
317+
sourceType: "s3 other",
318+
sourcePath: bucketName,
294319
sourceFlags: "--region us-west-2",
295320
downloadFlags: "",
296321
compare: s3tmp,
322+
skip: "Need to fix 403 on create",
297323
},
298324
{
299325
name: "local-60",
@@ -314,6 +340,9 @@ func TestDataPrep(t *testing.T) {
314340
}
315341

316342
for _, tt := range tests {
343+
if tt.skip != "" {
344+
t.Skip(tt.skip)
345+
}
317346
maxSize := tt.maxSize
318347
pieceSize := util.NextPowerOfTwo(uint64(maxSize))
319348
t.Run(tt.name, func(t *testing.T) {
@@ -327,7 +356,8 @@ func TestDataPrep(t *testing.T) {
327356
runner := Runner{mode: Normal}
328357
defer runner.Save(t, tmp, outDir, downloadDir, downloadDir2, extractDir)
329358
// Create source storage
330-
_, _, err := runner.Run(ctx, fmt.Sprintf("singularity storage create %s %s --name source --path %s", tt.sourceType, tt.sourceFlags, testutil.EscapePath(tt.sourcePath)))
359+
cmdStr := fmt.Sprintf("singularity storage create %s %s --name source --path %s", tt.sourceType, tt.sourceFlags, testutil.EscapePath(tt.sourcePath))
360+
_, _, err := runner.Run(ctx, cmdStr)
331361
require.NoError(t, err)
332362

333363
var outputStorage string

go.mod

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/data-preservation-programs/singularity
22

3-
go 1.20
3+
go 1.21
44

55
require (
66
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137
@@ -10,7 +10,7 @@ require (
1010
github.com/cockroachdb/errors v1.10.1-0.20230823160506-3a3abaca5af3
1111
github.com/data-preservation-programs/table v0.0.3
1212
github.com/dustin/go-humanize v1.0.1
13-
github.com/fatih/color v1.15.0
13+
github.com/fatih/color v1.16.0
1414
github.com/filecoin-project/go-address v1.1.0
1515
github.com/filecoin-project/go-cbor-util v0.0.1
1616
github.com/filecoin-project/go-fil-commcid v0.1.0
@@ -27,7 +27,7 @@ require (
2727
github.com/go-openapi/strfmt v0.21.7
2828
github.com/go-openapi/swag v0.22.4
2929
github.com/go-openapi/validate v0.22.1
30-
github.com/google/uuid v1.3.0
30+
github.com/google/uuid v1.3.1
3131
github.com/gotidy/ptr v1.4.0
3232
github.com/hashicorp/golang-lru/v2 v2.0.6
3333
github.com/ipfs/boxo v0.11.1-0.20230817065640-7ec68c5e5adf
@@ -64,6 +64,7 @@ require (
6464
github.com/multiformats/go-multicodec v0.9.0
6565
github.com/multiformats/go-multihash v0.2.3
6666
github.com/multiformats/go-varint v0.0.7
67+
github.com/orlangure/gnomock v0.30.0
6768
github.com/parnurzeal/gorequest v0.2.16
6869
github.com/rclone/rclone v1.62.2
6970
github.com/rjNemo/underscore v0.5.0
@@ -74,11 +75,11 @@ require (
7475
github.com/swaggo/swag v1.16.1
7576
github.com/urfave/cli/v2 v2.25.1
7677
github.com/ybbus/jsonrpc/v3 v3.1.4
77-
go.mongodb.org/mongo-driver v1.11.4
78+
go.mongodb.org/mongo-driver v1.12.1
7879
go.uber.org/multierr v1.11.0
7980
go.uber.org/zap v1.25.0
8081
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
81-
golang.org/x/text v0.12.0
82+
golang.org/x/text v0.14.0
8283
gorm.io/driver/mysql v1.5.0
8384
gorm.io/driver/postgres v1.5.0
8485
gorm.io/driver/sqlite v1.5.2
@@ -88,18 +89,19 @@ require (
8889
require (
8990
cloud.google.com/go/compute v1.18.0 // indirect
9091
cloud.google.com/go/compute/metadata v0.2.3 // indirect
91-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 // indirect
92-
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2 // indirect
93-
github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 // indirect
94-
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.0.0 // indirect
92+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0 // indirect
93+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 // indirect
94+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
95+
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.1.0 // indirect
96+
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
9597
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 // indirect
96-
github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0 // indirect
98+
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 // indirect
9799
github.com/KyleBanks/depth v1.2.1 // indirect
98100
github.com/Max-Sum/base32768 v0.0.0-20230304063302-18e6ce5945fd // indirect
99101
github.com/Microsoft/go-winio v0.5.2 // indirect
100102
github.com/abbot/go-http-auth v0.4.0 // indirect
101103
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
102-
github.com/aws/aws-sdk-go v1.44.218 // indirect
104+
github.com/aws/aws-sdk-go v1.44.332 // indirect
103105
github.com/benbjohnson/clock v1.3.5 // indirect
104106
github.com/beorn7/perks v1.0.1 // indirect
105107
github.com/bep/debounce v1.2.1 // indirect
@@ -118,7 +120,9 @@ require (
118120
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
119121
github.com/dchest/blake2b v1.0.0 // indirect
120122
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
121-
github.com/dnaeon/go-vcr v1.2.0 // indirect
123+
github.com/docker/distribution v2.8.2+incompatible // indirect
124+
github.com/docker/docker v24.0.5+incompatible // indirect
125+
github.com/docker/go-connections v0.4.0 // indirect
122126
github.com/docker/go-units v0.5.0 // indirect
123127
github.com/drand/kyber v1.1.4 // indirect
124128
github.com/drand/kyber-bls12381 v0.2.1 // indirect
@@ -139,6 +143,7 @@ require (
139143
github.com/filecoin-project/specs-actors v0.9.13 // indirect
140144
github.com/flynn/noise v1.0.0 // indirect
141145
github.com/francoispqt/gojay v1.2.13 // indirect
146+
github.com/fsnotify/fsnotify v1.7.0 // indirect
142147
github.com/gammazero/deque v0.2.0 // indirect
143148
github.com/geoffgarside/ber v1.1.0 // indirect
144149
github.com/getsentry/sentry-go v0.18.0 // indirect
@@ -152,7 +157,7 @@ require (
152157
github.com/go-openapi/jsonreference v0.20.2 // indirect
153158
github.com/go-openapi/loads v0.21.2 // indirect
154159
github.com/go-openapi/spec v0.20.9 // indirect
155-
github.com/go-sql-driver/mysql v1.7.0 // indirect
160+
github.com/go-sql-driver/mysql v1.7.1 // indirect
156161
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
157162
github.com/godbus/dbus/v5 v5.1.0 // indirect
158163
github.com/gofrs/flock v0.8.1 // indirect
@@ -163,6 +168,7 @@ require (
163168
github.com/golang/mock v1.6.0 // indirect
164169
github.com/golang/protobuf v1.5.3 // indirect
165170
github.com/golang/snappy v0.0.4 // indirect
171+
github.com/google/go-cmp v0.6.0 // indirect
166172
github.com/google/go-querystring v1.1.0 // indirect
167173
github.com/google/gopacket v1.1.19 // indirect
168174
github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b // indirect
@@ -236,7 +242,7 @@ require (
236242
github.com/mailru/easyjson v0.7.7 // indirect
237243
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
238244
github.com/mattn/go-colorable v0.1.13 // indirect
239-
github.com/mattn/go-isatty v0.0.19 // indirect
245+
github.com/mattn/go-isatty v0.0.20 // indirect
240246
github.com/mattn/go-sqlite3 v1.14.17 // indirect
241247
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
242248
github.com/miekg/dns v1.1.55 // indirect
@@ -256,6 +262,8 @@ require (
256262
github.com/ncw/swift/v2 v2.0.1 // indirect
257263
github.com/oklog/ulid v1.3.1 // indirect
258264
github.com/onsi/ginkgo/v2 v2.11.0 // indirect
265+
github.com/opencontainers/go-digest v1.0.0 // indirect
266+
github.com/opencontainers/image-spec v1.0.2 // indirect
259267
github.com/opencontainers/runtime-spec v1.1.0 // indirect
260268
github.com/opentracing/opentracing-go v1.2.0 // indirect
261269
github.com/oracle/oci-go-sdk/v65 v65.32.0 // indirect
@@ -281,7 +289,7 @@ require (
281289
github.com/raulk/go-watchdog v1.3.0 // indirect
282290
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
283291
github.com/rfjakob/eme v1.1.2 // indirect
284-
github.com/rogpeppe/go-internal v1.9.0 // indirect
292+
github.com/rogpeppe/go-internal v1.11.0 // indirect
285293
github.com/russross/blackfriday/v2 v2.1.0 // indirect
286294
github.com/shirou/gopsutil/v3 v3.23.3 // indirect
287295
github.com/shoenig/go-m1cpu v0.1.4 // indirect
@@ -305,8 +313,8 @@ require (
305313
github.com/x448/float16 v0.8.4 // indirect
306314
github.com/xanzy/ssh-agent v0.3.3 // indirect
307315
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
308-
github.com/xdg-go/scram v1.1.1 // indirect
309-
github.com/xdg-go/stringprep v1.0.3 // indirect
316+
github.com/xdg-go/scram v1.1.2 // indirect
317+
github.com/xdg-go/stringprep v1.0.4 // indirect
310318
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
311319
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
312320
github.com/yunify/qingstor-sdk-go/v3 v3.2.0 // indirect
@@ -319,15 +327,15 @@ require (
319327
go.uber.org/atomic v1.11.0 // indirect
320328
go.uber.org/dig v1.17.0 // indirect
321329
go.uber.org/fx v1.20.0 // indirect
322-
golang.org/x/crypto v0.12.0 // indirect
323-
golang.org/x/mod v0.12.0 // indirect
324-
golang.org/x/net v0.14.0 // indirect
325-
golang.org/x/oauth2 v0.6.0 // indirect
326-
golang.org/x/sync v0.3.0 // indirect
327-
golang.org/x/sys v0.11.0 // indirect
328-
golang.org/x/term v0.11.0 // indirect
330+
golang.org/x/crypto v0.21.0 // indirect
331+
golang.org/x/mod v0.16.0 // indirect
332+
golang.org/x/net v0.22.0 // indirect
333+
golang.org/x/oauth2 v0.8.0 // indirect
334+
golang.org/x/sync v0.6.0 // indirect
335+
golang.org/x/sys v0.18.0 // indirect
336+
golang.org/x/term v0.18.0 // indirect
329337
golang.org/x/time v0.3.0 // indirect
330-
golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect
338+
golang.org/x/tools v0.19.0 // indirect
331339
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
332340
google.golang.org/api v0.112.0 // indirect
333341
google.golang.org/appengine v1.6.7 // indirect
@@ -336,6 +344,7 @@ require (
336344
google.golang.org/protobuf v1.30.0 // indirect
337345
gopkg.in/yaml.v2 v2.4.0 // indirect
338346
gopkg.in/yaml.v3 v3.0.1 // indirect
347+
gotest.tools/v3 v3.5.1 // indirect
339348
lukechampine.com/blake3 v1.2.1 // indirect
340349
modernc.org/libc v1.22.3 // indirect
341350
modernc.org/mathutil v1.5.0 // indirect

0 commit comments

Comments
 (0)