mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-04-04 22:14:28 +02:00
commit
1109e689f7
@ -2,7 +2,6 @@ package checksum
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -13,20 +12,11 @@ func TestChecksums(t *testing.T) {
|
|||||||
var assert = assert.New(t)
|
var assert = assert.New(t)
|
||||||
folder, err := ioutil.TempDir("", "gorelasertest")
|
folder, err := ioutil.TempDir("", "gorelasertest")
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
file, err := os.OpenFile(
|
var file = filepath.Join(folder, "subject")
|
||||||
filepath.Join(folder, "subject"),
|
assert.NoError(ioutil.WriteFile(file, []byte("lorem ipsum"), 0644))
|
||||||
os.O_APPEND|os.O_WRONLY|os.O_CREATE|os.O_EXCL,
|
sum, err := SHA256(file)
|
||||||
0600,
|
|
||||||
)
|
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
_, err = file.WriteString("lorem ipsum")
|
assert.Equal("5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269", sum)
|
||||||
assert.NoError(err)
|
|
||||||
assert.NoError(file.Close())
|
|
||||||
t.Run("sha256", func(t *testing.T) {
|
|
||||||
sum, err := SHA256(file.Name())
|
|
||||||
assert.NoError(err)
|
|
||||||
assert.Equal("5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269", sum)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOpenFailure(t *testing.T) {
|
func TestOpenFailure(t *testing.T) {
|
||||||
|
@ -4,8 +4,8 @@ package checksums
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/checksum"
|
"github.com/goreleaser/goreleaser/checksum"
|
||||||
@ -36,23 +36,18 @@ func (Pipe) Run(ctx *context.Context) (err error) {
|
|||||||
func checksums(ctx *context.Context, name string) error {
|
func checksums(ctx *context.Context, name string) error {
|
||||||
log.Println("Checksumming", name)
|
log.Println("Checksumming", name)
|
||||||
var artifact = filepath.Join(ctx.Config.Dist, name)
|
var artifact = filepath.Join(ctx.Config.Dist, name)
|
||||||
var checksums = fmt.Sprintf("%v.%v", name, "checksums")
|
|
||||||
sha, err := checksum.SHA256(artifact)
|
sha, err := checksum.SHA256(artifact)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
file, err := os.OpenFile(
|
var file = filepath.Join(
|
||||||
filepath.Join(ctx.Config.Dist, checksums),
|
ctx.Config.Dist,
|
||||||
os.O_APPEND|os.O_WRONLY|os.O_CREATE|os.O_TRUNC,
|
fmt.Sprintf("%v.%v", name, "checksums"),
|
||||||
0600,
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
var content = fmt.Sprintf("%v\t%v\n", sha, name)
|
||||||
|
if err := ioutil.WriteFile(file, []byte(content), 0644); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer func() { _ = file.Close() }()
|
ctx.AddArtifact(file)
|
||||||
if _, err = file.WriteString(fmt.Sprintf("%v\t%v\n", sha, name)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
ctx.AddArtifact(file.Name())
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package checksums
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -19,21 +18,14 @@ func TestPipe(t *testing.T) {
|
|||||||
var assert = assert.New(t)
|
var assert = assert.New(t)
|
||||||
folder, err := ioutil.TempDir("", "gorelasertest")
|
folder, err := ioutil.TempDir("", "gorelasertest")
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
file, err := os.OpenFile(
|
var file = filepath.Join(folder, "binary")
|
||||||
filepath.Join(folder, "binary"),
|
assert.NoError(ioutil.WriteFile(file, []byte("some string"), 0644))
|
||||||
os.O_APPEND|os.O_WRONLY|os.O_CREATE|os.O_EXCL,
|
|
||||||
0600,
|
|
||||||
)
|
|
||||||
assert.NoError(err)
|
|
||||||
_, err = file.WriteString("some string")
|
|
||||||
assert.NoError(err)
|
|
||||||
assert.NoError(file.Close())
|
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{
|
Config: config.Project{
|
||||||
Dist: folder,
|
Dist: folder,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctx.AddArtifact(file.Name())
|
ctx.AddArtifact(file)
|
||||||
assert.NoError(Pipe{}.Run(ctx))
|
assert.NoError(Pipe{}.Run(ctx))
|
||||||
assert.Contains(ctx.Artifacts, "binary.checksums", "binary")
|
assert.Contains(ctx.Artifacts, "binary.checksums", "binary")
|
||||||
bts, err := ioutil.ReadFile(filepath.Join(folder, "binary.checksums"))
|
bts, err := ioutil.ReadFile(filepath.Join(folder, "binary.checksums"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user