From 2daf24a1ea653351f9188fc03c999ccc61924a7d Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Wed, 18 Dec 2019 16:31:59 +0200 Subject: [PATCH] private/testcontext: remove version dependency Change-Id: Ibabf5ec774dcdb1e4fc2f200368281c69b62e6c2 --- cmd/storagenode-updater/main_test.go | 17 +++++++++++++++-- private/testcontext/compile.go | 18 ------------------ 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/cmd/storagenode-updater/main_test.go b/cmd/storagenode-updater/main_test.go index abc8ec4f1..72c4340a1 100644 --- a/cmd/storagenode-updater/main_test.go +++ b/cmd/storagenode-updater/main_test.go @@ -13,6 +13,7 @@ import ( "os" "os/exec" "path/filepath" + "strconv" "testing" "time" @@ -54,7 +55,7 @@ func TestAutoUpdater(t *testing.T) { } // build real bin with old version, will be used for both storagenode and updater - oldBin := ctx.CompileWithVersion("storj.io/storj/cmd/storagenode-updater", oldInfo) + oldBin := CompileWithVersion(ctx, "storj.io/storj/cmd/storagenode-updater", oldInfo) storagenodePath := ctx.File("fake", "storagenode.exe") copyBin(ctx, t, oldBin, storagenodePath) @@ -68,7 +69,7 @@ func TestAutoUpdater(t *testing.T) { Version: newSemVer, Release: false, } - newBin := ctx.CompileWithVersion("storj.io/storj/cmd/storagenode-updater", newInfo) + newBin := CompileWithVersion(ctx, "storj.io/storj/cmd/storagenode-updater", newInfo) updateBins := map[string]string{ "storagenode": newBin, @@ -128,6 +129,18 @@ func TestAutoUpdater(t *testing.T) { require.NotZero(t, backupUpdaterInfo.Size()) } +// CompileWithVersion compiles the specified package with the version variables set +// to the passed version info values and returns the executable name. +func CompileWithVersion(ctx *testcontext.Context, pkg string, info version.Info) string { + ldFlagsX := map[string]string{ + "storj.io/storj/private/version.buildTimestamp": strconv.Itoa(int(info.Timestamp.Unix())), + "storj.io/storj/private/version.buildCommitHash": info.CommitHash, + "storj.io/storj/private/version.buildVersion": info.Version.String(), + "storj.io/storj/private/version.buildRelease": strconv.FormatBool(info.Release), + } + return ctx.CompileWithLDFlagsX(pkg, ldFlagsX) +} + func move(t *testing.T, src, dst string) { err := os.Rename(src, dst) require.NoError(t, err) diff --git a/private/testcontext/compile.go b/private/testcontext/compile.go index a480ac0ae..928caf23d 100644 --- a/private/testcontext/compile.go +++ b/private/testcontext/compile.go @@ -9,10 +9,7 @@ import ( "path" "path/filepath" "runtime" - "strconv" "testing" - - "storj.io/storj/private/version" ) // CLibMath is the standard C math library (see `man math.h`). @@ -63,21 +60,6 @@ func (ctx *Context) Compile(pkg string, preArgs ...string) string { return exe } -// CompileWithVersion compiles the specified package with the version variables set -// to the passed version info values and returns the executable name. -func (ctx *Context) CompileWithVersion(pkg string, info version.Info) string { - ctx.test.Helper() - - ldFlagsX := map[string]string{ - "storj.io/storj/private/version.buildTimestamp": strconv.Itoa(int(info.Timestamp.Unix())), - "storj.io/storj/private/version.buildCommitHash": info.CommitHash, - "storj.io/storj/private/version.buildVersion": info.Version.String(), - "storj.io/storj/private/version.buildRelease": strconv.FormatBool(info.Release), - } - - return ctx.CompileWithLDFlagsX(pkg, ldFlagsX) -} - // CompileWithLDFlagsX compiles the specified package with the -ldflags flag set to // "-s -w [-X =,...]" given the passed map and returns the executable name. func (ctx *Context) CompileWithLDFlagsX(pkg string, ldFlagsX map[string]string) string {