github.com/kubeshop/testkube@v1.17.23/pkg/executor/scraper/minio_uploader_integration_test.go (about) 1 package scraper_test 2 3 import ( 4 "bytes" 5 "context" 6 "strings" 7 "testing" 8 "time" 9 10 "github.com/kubeshop/testkube/pkg/utils/test" 11 12 "github.com/stretchr/testify/assert" 13 14 "github.com/kubeshop/testkube/pkg/api/v1/testkube" 15 "github.com/kubeshop/testkube/pkg/archive" 16 "github.com/kubeshop/testkube/pkg/executor/scraper" 17 "github.com/kubeshop/testkube/pkg/storage/minio" 18 ) 19 20 func TestMinIOUploader_Upload_Tarball_Integration(t *testing.T) { 21 test.IntegrationTest(t) 22 t.Parallel() 23 24 // Create a new MinIO uploader with the appropriate configuration 25 uploader, err := scraper.NewMinIOUploader( 26 "localhost:9000", 27 "minio99", 28 "minio123", 29 "us-east-1", 30 "", 31 "test-bucket-fsgds", 32 false, 33 false, 34 "", 35 "", 36 "", 37 ) 38 if err != nil { 39 t.Fatalf("failed to create MinIO loader: %v", err) 40 } 41 42 files := []*archive.File{ 43 {Name: "test/testfile.txt", Mode: 0644, Size: 9, ModTime: time.Now(), Data: bytes.NewBufferString("testdata\n")}, 44 } 45 46 var buf bytes.Buffer 47 tarballService := archive.NewTarballService() 48 if err = tarballService.Create(&buf, files); err != nil { 49 t.Fatalf("error creating tarball: %v", err) 50 } 51 52 size := int64(buf.Len()) 53 // Create a test object to save to MinIO 54 testObject := &scraper.Object{ 55 Name: "artifacts.tar.gz", 56 Data: &buf, 57 Size: size, 58 DataType: scraper.DataTypeTarball, 59 } 60 61 execution := testkube.Execution{Id: "test-execution-id"} 62 // Call the Upload function to save the object to MinIO 63 err = uploader.Upload(context.Background(), testObject, execution) 64 if err != nil { 65 t.Fatalf("failed to save file to MinIO: %v", err) 66 } 67 68 m := minio.NewClient( 69 "localhost:9000", 70 "minio99", 71 "minio123", 72 "us-east-1", 73 "", 74 "test-bucket-fsgds", 75 ) 76 if err := m.Connect(); err != nil { 77 t.Fatalf("error conecting to minio: %v", err) 78 } 79 artifacts, err := m.ListFiles(context.Background(), "test-execution-id") 80 assert.NoError(t, err) 81 assert.Equal(t, 1, len(artifacts)) 82 assert.Equal(t, "test/testfile.txt", artifacts[0].Name) 83 assert.Equal(t, files[0].Size, int64(artifacts[0].Size)) 84 } 85 86 func TestMinIOUploader_Upload_Raw_Integration(t *testing.T) { 87 test.IntegrationTest(t) 88 t.Parallel() 89 90 // Create a new MinIO loader with the appropriate configuration 91 uploader, err := scraper.NewMinIOUploader( 92 "localhost:9000", 93 "minio99", 94 "minio123", 95 "us-east-1", 96 "", 97 "test-bucket-hgfhfg", 98 false, 99 false, 100 "", 101 "", 102 "", 103 ) 104 if err != nil { 105 t.Fatalf("failed to create MinIO loader: %v", err) 106 } 107 108 // Create a test context 109 ctx := context.Background() 110 111 // Create a test object to save to MinIO 112 size := int64(len("test data")) 113 testObject := &scraper.Object{ 114 Name: "test-file.txt", 115 Data: strings.NewReader("test data"), 116 Size: size, 117 DataType: scraper.DataTypeRaw, 118 } 119 120 execution := testkube.Execution{Id: "test-execution-id"} 121 // Call the Upload function to save the object to MinIO 122 err = uploader.Upload(ctx, testObject, execution) 123 if err != nil { 124 t.Fatalf("failed to save file to MinIO: %v", err) 125 } 126 127 m := minio.NewClient( 128 "localhost:9000", 129 "minio99", 130 "minio123", 131 "us-east-1", 132 "", 133 "test-bucket-hgfhfg", 134 ) 135 if err := m.Connect(); err != nil { 136 t.Fatalf("error conecting to minio: %v", err) 137 } 138 artifacts, err := m.ListFiles(context.Background(), "test-execution-id") 139 assert.NoError(t, err) 140 assert.Equal(t, 1, len(artifacts)) 141 assert.Equal(t, "test-file.txt", artifacts[0].Name) 142 assert.Equal(t, size, int64(artifacts[0].Size)) 143 }