Something went wrong on our end
Select Git revision
update-web-test.nix
-
Volker Schukai authoredVolker Schukai authored
runnable-sftp_test.go 6.94 KiB
// Copyright 2023 schukai GmbH
// SPDX-License-Identifier: AGPL-3.0
//go:build !bench && !race && !runOnTask
// the creation of the container is not working on the CI server
// nor on the task command. use this test manually to test the
// sftp functionality
package jobqueue
import (
"context"
"fmt"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"github.com/stretchr/testify/assert"
"net"
"os"
"testing"
"time"
)
func startSFTPTestDockerImageAndContainer(t *testing.T, host string, port string, volume string, ctx context.Context) error {
t.Helper()
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return err
}
imageName := "atmoz/sftp:alpine"
reader, err := cli.ImagePull(ctx, imageName, types.ImagePullOptions{})
if err != nil {
return err
}
//if debug image pull, comment out the following lines
//_, _ = io.Copy(os.Stdout, reader)
_ = reader
hostConfig := &container.HostConfig{
PortBindings: nat.PortMap{
"22/tcp": []nat.PortBinding{
{
HostIP: host,
HostPort: port,
},
},
},
}
if volume != "" {
hostConfig.Binds = append(hostConfig.Binds, volume+":/home/demo/upload")
}
resp, err := cli.ContainerCreate(ctx, &container.Config{
Image: imageName,
Cmd: []string{"demo:secret:::upload"},
}, hostConfig, nil, nil, "")
if err != nil {
return err
}
if err := cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil {
return err