From 3a1f737747e6e2183ba6fb94395fd14848884402 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Mon, 18 Dec 2017 21:15:32 -0200 Subject: [PATCH] refactor: move archiveformat code inside archive pipe It was being used only in that pipe anyway. --- internal/archiveformat/format.go | 20 -------------------- internal/archiveformat/format_test.go | 27 --------------------------- pipeline/archive/archive.go | 12 ++++++++++-- pipeline/archive/archive_test.go | 18 ++++++++++++++++++ 4 files changed, 28 insertions(+), 49 deletions(-) delete mode 100644 internal/archiveformat/format.go delete mode 100644 internal/archiveformat/format_test.go diff --git a/internal/archiveformat/format.go b/internal/archiveformat/format.go deleted file mode 100644 index 564ea5094..000000000 --- a/internal/archiveformat/format.go +++ /dev/null @@ -1,20 +0,0 @@ -// Package archiveformat provides functions to get the format of given package -// based on the config -// TODO: this can be moved inside the archive pipe package -package archiveformat - -import ( - "strings" - - "github.com/goreleaser/goreleaser/context" -) - -// For return the archive format, considering overrides and all that -func For(ctx *context.Context, platform string) string { - for _, override := range ctx.Config.Archive.FormatOverrides { - if strings.HasPrefix(platform, override.Goos) { - return override.Format - } - } - return ctx.Config.Archive.Format -} diff --git a/internal/archiveformat/format_test.go b/internal/archiveformat/format_test.go deleted file mode 100644 index 4e201cc76..000000000 --- a/internal/archiveformat/format_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package archiveformat - -import ( - "testing" - - "github.com/goreleaser/goreleaser/config" - "github.com/goreleaser/goreleaser/context" - "github.com/stretchr/testify/assert" -) - -func TestFormatFor(t *testing.T) { - var ctx = &context.Context{ - Config: config.Project{ - Archive: config.Archive{ - Format: "tar.gz", - FormatOverrides: []config.FormatOverride{ - { - Goos: "windows", - Format: "zip", - }, - }, - }, - }, - } - assert.Equal(t, "zip", For(ctx, "windowsamd64")) - assert.Equal(t, "tar.gz", For(ctx, "linux386")) -} diff --git a/pipeline/archive/archive.go b/pipeline/archive/archive.go index 3724f1cc6..20bad2eda 100644 --- a/pipeline/archive/archive.go +++ b/pipeline/archive/archive.go @@ -15,7 +15,6 @@ import ( "github.com/goreleaser/archive" "github.com/goreleaser/goreleaser/context" - "github.com/goreleaser/goreleaser/internal/archiveformat" "github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/nametemplate" ) @@ -67,7 +66,7 @@ func (Pipe) Default(ctx *context.Context) error { } func create(ctx *context.Context, artifacts []artifact.Artifact) error { - var format = archiveformat.For(ctx, artifacts[0].Goos) + var format = packageFormat(ctx, artifacts[0].Goos) folder, err := nametemplate.Apply(ctx, artifacts[0], ctx.Config.ProjectName) if err != nil { return err @@ -140,3 +139,12 @@ func wrap(ctx *context.Context, name, folder string) string { } return name } + +func packageFormat(ctx *context.Context, platform string) string { + for _, override := range ctx.Config.Archive.FormatOverrides { + if strings.HasPrefix(platform, override.Goos) { + return override.Format + } + } + return ctx.Config.Archive.Format +} diff --git a/pipeline/archive/archive_test.go b/pipeline/archive/archive_test.go index 9c8df4b9d..253dae6f4 100644 --- a/pipeline/archive/archive_test.go +++ b/pipeline/archive/archive_test.go @@ -284,3 +284,21 @@ func TestDefaultSet(t *testing.T) { assert.Equal(t, "zip", ctx.Config.Archive.Format) assert.Equal(t, "foo", ctx.Config.Archive.Files[0]) } + +func TestFormatFor(t *testing.T) { + var ctx = &context.Context{ + Config: config.Project{ + Archive: config.Archive{ + Format: "tar.gz", + FormatOverrides: []config.FormatOverride{ + { + Goos: "windows", + Format: "zip", + }, + }, + }, + }, + } + assert.Equal(t, "zip", packageFormat(ctx, "windows")) + assert.Equal(t, "tar.gz", packageFormat(ctx, "linux")) +}