package s3 import ( "io/ioutil" "os" "os/exec" "path/filepath" "testing" "time" "github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/internal/artifact" "github.com/stretchr/testify/assert" ) func TestDescription(t *testing.T) { assert.NotEmpty(t, Pipe{}.String()) } func TestNoS3(t *testing.T) { assert.NoError(t, Pipe{}.Run(context.New(config.Project{}))) } func TestDefaultsNoS3(t *testing.T) { var assert = assert.New(t) var ctx = context.New(config.Project{ S3: []config.S3{ config.S3{}, }, }) assert.NoError(Pipe{}.Default(ctx)) assert.Equal([]config.S3{config.S3{}}, ctx.Config.S3) } func TestDefaults(t *testing.T) { var assert = assert.New(t) var ctx = context.New(config.Project{ S3: []config.S3{ { Bucket: "foo", }, }, }) assert.NoError(Pipe{}.Default(ctx)) assert.Equal([]config.S3{config.S3{ Bucket: "foo", Region: "us-east-1", Folder: "{{ .ProjectName }}/{{ .Tag }}", }}, ctx.Config.S3) } func TestUpload(t *testing.T) { folder, err := ioutil.TempDir("", "goreleasertest") assert.NoError(t, err) tgzpath := filepath.Join(folder, "bin.tar.gz") debpath := filepath.Join(folder, "bin.deb") assert.NoError(t, ioutil.WriteFile(tgzpath, []byte("fake\ntargz"), 0744)) assert.NoError(t, ioutil.WriteFile(debpath, []byte("fake\ndeb"), 0744)) var ctx = context.New(config.Project{ Dist: folder, ProjectName: "testupload", S3: []config.S3{ { Bucket: "test", Endpoint: "http://localhost:6000", }, }, }) ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"} ctx.Artifacts.Add(artifact.Artifact{ Type: artifact.UploadableArchive, Name: "bin.tar.gz", Path: tgzpath, }) ctx.Artifacts.Add(artifact.Artifact{ Type: artifact.LinuxPackage, Name: "bin.deb", Path: debpath, }) start(t) defer stop(t) setCredentials(t) assert.NoError(t, Pipe{}.Default(ctx)) assert.NoError(t, Pipe{}.Run(ctx)) } func setCredentials(t *testing.T) { // this comes from the testdata/config/config.json file - not real aws keys os.Setenv("AWS_ACCESS_KEY_ID", "IWA0WZQ1QJ2I8I1ALW64") os.Setenv("AWS_SECRET_ACCESS_KEY", "zcK4QQegvYwVGJaBm2E6k20WRLIQZqHOKOPP2npT") os.Setenv("AWS_REGION", "us-east-1") } func start(t *testing.T) { dir, err := os.Getwd() assert.NoError(t, err) t.Log("wd:", dir) if out, err := exec.Command( "docker", "run", "-d", "--rm", "--name", "minio", "-p", "6000:6000", "-v", dir+"/testdata/data:/data", "-v", dir+"/testdata/config:/root/.minio", "minio/minio", "server", "/data", ).CombinedOutput(); err != nil { t.Log("failed to start minio", string(out), err) t.FailNow() } // TODO: check if the container is healthy instead of sleeping an arbitrary amount of time t.Log("waiting for minio to be healthy") time.Sleep(5 * time.Second) } func stop(t *testing.T) { if out, err := exec.Command("docker", "stop", "minio").CombinedOutput(); err != nil { t.Log("failed to stop minio", string(out), err) t.FailNow() } }