mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
test: covered s3 pipe with tests
This commit is contained in:
parent
87926dacbd
commit
f7dbb05f29
125
pipeline/s3/pipeline/s3/testdata/config/config.json
vendored
Normal file
125
pipeline/s3/pipeline/s3/testdata/config/config.json
vendored
Normal file
@ -0,0 +1,125 @@
|
||||
{
|
||||
"version": "23",
|
||||
"credential": {
|
||||
"accessKey": "WPXKJC7CZQCFPKY5727N",
|
||||
"secretKey": "eHCSajxLvl94l36gIMlzZ/oW2O0rYYK+cVn5jNT2"
|
||||
},
|
||||
"region": "",
|
||||
"browser": "on",
|
||||
"domain": "",
|
||||
"storageclass": {
|
||||
"standard": "",
|
||||
"rrs": ""
|
||||
},
|
||||
"cache": {
|
||||
"drives": [],
|
||||
"expiry": 90,
|
||||
"exclude": []
|
||||
},
|
||||
"notify": {
|
||||
"amqp": {
|
||||
"1": {
|
||||
"enable": false,
|
||||
"url": "",
|
||||
"exchange": "",
|
||||
"routingKey": "",
|
||||
"exchangeType": "",
|
||||
"deliveryMode": 0,
|
||||
"mandatory": false,
|
||||
"immediate": false,
|
||||
"durable": false,
|
||||
"internal": false,
|
||||
"noWait": false,
|
||||
"autoDeleted": false
|
||||
}
|
||||
},
|
||||
"elasticsearch": {
|
||||
"1": {
|
||||
"enable": false,
|
||||
"format": "",
|
||||
"url": "",
|
||||
"index": ""
|
||||
}
|
||||
},
|
||||
"kafka": {
|
||||
"1": {
|
||||
"enable": false,
|
||||
"brokers": null,
|
||||
"topic": ""
|
||||
}
|
||||
},
|
||||
"mqtt": {
|
||||
"1": {
|
||||
"enable": false,
|
||||
"broker": "",
|
||||
"topic": "",
|
||||
"qos": 0,
|
||||
"clientId": "",
|
||||
"username": "",
|
||||
"password": "",
|
||||
"reconnectInterval": 0,
|
||||
"keepAliveInterval": 0
|
||||
}
|
||||
},
|
||||
"mysql": {
|
||||
"1": {
|
||||
"enable": false,
|
||||
"format": "",
|
||||
"dsnString": "",
|
||||
"table": "",
|
||||
"host": "",
|
||||
"port": "",
|
||||
"user": "",
|
||||
"password": "",
|
||||
"database": ""
|
||||
}
|
||||
},
|
||||
"nats": {
|
||||
"1": {
|
||||
"enable": false,
|
||||
"address": "",
|
||||
"subject": "",
|
||||
"username": "",
|
||||
"password": "",
|
||||
"token": "",
|
||||
"secure": false,
|
||||
"pingInterval": 0,
|
||||
"streaming": {
|
||||
"enable": false,
|
||||
"clusterID": "",
|
||||
"clientID": "",
|
||||
"async": false,
|
||||
"maxPubAcksInflight": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
"postgresql": {
|
||||
"1": {
|
||||
"enable": false,
|
||||
"format": "",
|
||||
"connectionString": "",
|
||||
"table": "",
|
||||
"host": "",
|
||||
"port": "",
|
||||
"user": "",
|
||||
"password": "",
|
||||
"database": ""
|
||||
}
|
||||
},
|
||||
"redis": {
|
||||
"1": {
|
||||
"enable": false,
|
||||
"format": "",
|
||||
"address": "",
|
||||
"password": "",
|
||||
"key": ""
|
||||
}
|
||||
},
|
||||
"webhook": {
|
||||
"1": {
|
||||
"enable": false,
|
||||
"endpoint": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -59,12 +59,12 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
}
|
||||
|
||||
func upload(ctx *context.Context, conf config.S3) error {
|
||||
var awsConfig = aws.Config{}
|
||||
var awsConfig = aws.NewConfig()
|
||||
if conf.Endpoint != "" {
|
||||
awsConfig.Endpoint = aws.String(conf.Endpoint)
|
||||
awsConfig.S3ForcePathStyle = aws.Bool(true)
|
||||
}
|
||||
sess := session.Must(session.NewSession(&awsConfig))
|
||||
sess := session.Must(session.NewSession(awsConfig))
|
||||
svc := s3.New(sess, &aws.Config{
|
||||
Region: aws.String(conf.Region),
|
||||
})
|
||||
|
@ -1,10 +1,16 @@
|
||||
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"
|
||||
)
|
||||
|
||||
@ -43,3 +49,68 @@ func TestDefaults(t *testing.T) {
|
||||
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:9000",
|
||||
},
|
||||
},
|
||||
})
|
||||
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)
|
||||
assert.NoError(t, Pipe{}.Default(ctx))
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
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", "9000:9000",
|
||||
"-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
|
||||
time.Sleep(5 * time.Second)
|
||||
// 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 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()
|
||||
}
|
||||
}
|
||||
|
1
pipeline/s3/testdata/config/.gitignore
vendored
Normal file
1
pipeline/s3/testdata/config/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
certs
|
7
pipeline/s3/testdata/config/config.json
vendored
Normal file
7
pipeline/s3/testdata/config/config.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"version": "23",
|
||||
"credential": {
|
||||
"accessKey": "IWA0WZQ1QJ2I8I1ALW64",
|
||||
"secretKey": "zcK4QQegvYwVGJaBm2E6k20WRLIQZqHOKOPP2npT"
|
||||
}
|
||||
}
|
1
pipeline/s3/testdata/data/.gitignore
vendored
Normal file
1
pipeline/s3/testdata/data/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.minio.sys
|
1
pipeline/s3/testdata/data/test/.gitignore
vendored
Normal file
1
pipeline/s3/testdata/data/test/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
testupload
|
0
pipeline/s3/testdata/data/test/.gitkeep
vendored
Normal file
0
pipeline/s3/testdata/data/test/.gitkeep
vendored
Normal file
Loading…
x
Reference in New Issue
Block a user