Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions testcontainers/atmoz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package testcontainers

import (
"context"
"fmt"
"testing"

"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
"golang.org/x/crypto/ssh"

"github.com/c2fo/vfs/v7/backend"
"github.com/c2fo/vfs/v7/backend/sftp"
)

const (
atmozPort = "22/tcp"
atmozUsername = "dummy"
atmozPassword = "dummy"
)

func registerAtmoz(t *testing.T) string {
ctx := context.Background()
is := require.New(t)

req := testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Name: "vfs-atmoz-sftp",
Image: "atmoz/sftp:alpine",
Env: map[string]string{"SFTP_USERS": fmt.Sprintf("%s:%s:::upload", atmozUsername, atmozPassword)},
WaitingFor: wait.ForListeningPort(atmozPort),
},
Started: true,
}
ctr, err := testcontainers.GenericContainer(ctx, req)
testcontainers.CleanupContainer(t, ctr)
is.NoError(err)

host, err := ctr.Host(ctx)
is.NoError(err)

port, err := ctr.MappedPort(ctx, atmozPort)
is.NoError(err)

authority := fmt.Sprintf("sftp://%s@%s:%s/upload/", atmozUsername, host, port.Port())
backend.Register(authority, sftp.NewFileSystem(sftp.WithOptions(sftp.Options{
Password: vsftpdPassword,
KnownHostsCallback: ssh.InsecureIgnoreHostKey(), //nolint:gosec
})))
return authority
}
52 changes: 52 additions & 0 deletions testcontainers/azurite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package testcontainers

import (
"context"
"net/url"
"testing"

"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/azure/azurite"

"github.com/c2fo/vfs/v7/backend"
"github.com/c2fo/vfs/v7/backend/azure"
)

func registerAzurite(t *testing.T) string {
ctx := context.Background()
is := require.New(t)

ctr, err := azurite.Run(ctx, "mcr.microsoft.com/azure-storage/azurite:latest",
testcontainers.WithName("vfs-azurite"),
azurite.WithEnabledServices(azurite.BlobService),
)
testcontainers.CleanupContainer(t, ctr)
is.NoError(err)

ep, err := ctr.BlobServiceURL(ctx)
is.NoError(err)

cred, err := azblob.NewSharedKeyCredential(azurite.AccountName, azurite.AccountKey)
is.NoError(err)

u, err := url.JoinPath(ep, azurite.AccountName)
is.NoError(err)

cli, err := azblob.NewClientWithSharedKeyCredential(u, cred, nil)
is.NoError(err)

_, err = cli.CreateContainer(ctx, "azurite", nil)
is.NoError(err)

c, err := azure.NewClient(&azure.Options{
ServiceURL: u,
AccountName: azurite.AccountName,
AccountKey: azurite.AccountKey,
})
is.NoError(err)

backend.Register("https://azurite/", azure.NewFileSystem(azure.WithClient(c)))
return "https://azurite/"
}
Loading
Loading