github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/publisher/estuary/publisher_test.go (about) 1 //go:build integration 2 3 package estuary 4 5 import ( 6 "context" 7 "os" 8 "path/filepath" 9 "testing" 10 11 "github.com/filecoin-project/bacalhau/pkg/model" 12 "github.com/filecoin-project/bacalhau/pkg/publisher" 13 "github.com/stretchr/testify/require" 14 ) 15 16 func getPublisherWithGoodConfig(t *testing.T) publisher.Publisher { 17 apiKey, isSet := os.LookupEnv("ESTUARY_API_KEY") 18 if !isSet { 19 t.Skip("No ESTUARY_API_KEY set") 20 } 21 22 return NewEstuaryPublisher(EstuaryPublisherConfig{APIKey: apiKey}) 23 } 24 25 func getPublisherWithErrorConfig(*testing.T) publisher.Publisher { 26 return NewEstuaryPublisher(EstuaryPublisherConfig{APIKey: "TEST"}) 27 } 28 29 func TestIsInstalled(t *testing.T) { 30 publisher := getPublisherWithGoodConfig(t) 31 isInstalled, err := publisher.IsInstalled(context.Background()) 32 require.True(t, isInstalled) 33 require.NoError(t, err) 34 } 35 36 func TestNotInstalledWithBadKey(t *testing.T) { 37 publisher := getPublisherWithErrorConfig(t) 38 isInstalled, err := publisher.IsInstalled(context.Background()) 39 require.False(t, isInstalled) 40 require.NoError(t, err) 41 } 42 43 func TestUpload(t *testing.T) { 44 tempDir := t.TempDir() 45 err := os.WriteFile(filepath.Join(tempDir, "hello.txt"), []byte("hello, world!"), os.ModePerm) 46 require.NoError(t, err) 47 48 publisher := getPublisherWithGoodConfig(t) 49 spec, err := publisher.PublishShardResult( 50 context.Background(), 51 model.JobShard{ 52 Job: model.NewJob(), 53 Index: 0, 54 }, 55 "host", 56 tempDir, 57 ) 58 require.NoError(t, err) 59 require.Equal(t, spec.StorageSource, model.StorageSourceEstuary) 60 require.NotEmpty(t, spec.CID) 61 }