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