Skip to content
Snippets Groups Projects
Select Git revision
  • ce1dd137678aaee721c92dd3cfdf88a52001f9af
  • master default protected
  • 1.31
  • 4.24.3
  • 4.24.2
  • 4.24.1
  • 4.24.0
  • 4.23.6
  • 4.23.5
  • 4.23.4
  • 4.23.3
  • 4.23.2
  • 4.23.1
  • 4.23.0
  • 4.22.3
  • 4.22.2
  • 4.22.1
  • 4.22.0
  • 4.21.0
  • 4.20.1
  • 4.20.0
  • 4.19.0
  • 4.18.0
23 results

update-web-test.nix

Blame
  • 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