github.com/kubeshop/testkube@v1.17.23/pkg/executor/content/uploads.go (about)

     1  package content
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/kubeshop/testkube/pkg/executor/output"
     8  	"github.com/kubeshop/testkube/pkg/storage"
     9  	"github.com/kubeshop/testkube/pkg/ui"
    10  )
    11  
    12  // CopyFilesPlacer takes care of downloading the file into the execution
    13  type CopyFilesPlacer struct {
    14  	client storage.Client
    15  }
    16  
    17  const (
    18  	UploadsFolder = "/data/uploads/"
    19  )
    20  
    21  func NewCopyFilesPlacer(client storage.Client) *CopyFilesPlacer {
    22  	return &CopyFilesPlacer{
    23  		client: client,
    24  	}
    25  }
    26  
    27  // PlaceFiles downloads the files from minio and places them into the /data/uploads directory.
    28  // A warning will be shown in case there was an error placing the files.
    29  func (p CopyFilesPlacer) PlaceFiles(ctx context.Context, testName, executionBucket string) {
    30  	output.PrintEvent(fmt.Sprintf("%s Placing files from buckets into %s", ui.IconFile, UploadsFolder))
    31  
    32  	var buckets []string
    33  	if testName != "" {
    34  		buckets = append(buckets, p.client.GetValidBucketName("test", testName))
    35  	}
    36  	if executionBucket != "" {
    37  		buckets = append(buckets, p.client.GetValidBucketName("execution", executionBucket))
    38  	}
    39  
    40  	err := p.client.PlaceFiles(ctx, buckets, UploadsFolder)
    41  	if err != nil {
    42  		output.PrintLogf("%s Could not place files: %s", ui.IconWarning, err.Error())
    43  	}
    44  }