private/testcontext: remove version dependency

Change-Id: Ibabf5ec774dcdb1e4fc2f200368281c69b62e6c2
This commit is contained in:
Egon Elbre 2019-12-18 16:31:59 +02:00
parent 9ed9d3516f
commit 2daf24a1ea
2 changed files with 15 additions and 20 deletions

View File

@ -13,6 +13,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strconv"
"testing" "testing"
"time" "time"
@ -54,7 +55,7 @@ func TestAutoUpdater(t *testing.T) {
} }
// build real bin with old version, will be used for both storagenode and updater // 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") storagenodePath := ctx.File("fake", "storagenode.exe")
copyBin(ctx, t, oldBin, storagenodePath) copyBin(ctx, t, oldBin, storagenodePath)
@ -68,7 +69,7 @@ func TestAutoUpdater(t *testing.T) {
Version: newSemVer, Version: newSemVer,
Release: false, 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{ updateBins := map[string]string{
"storagenode": newBin, "storagenode": newBin,
@ -128,6 +129,18 @@ func TestAutoUpdater(t *testing.T) {
require.NotZero(t, backupUpdaterInfo.Size()) 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) { func move(t *testing.T, src, dst string) {
err := os.Rename(src, dst) err := os.Rename(src, dst)
require.NoError(t, err) require.NoError(t, err)

View File

@ -9,10 +9,7 @@ import (
"path" "path"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strconv"
"testing" "testing"
"storj.io/storj/private/version"
) )
// CLibMath is the standard C math library (see `man math.h`). // 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 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 // CompileWithLDFlagsX compiles the specified package with the -ldflags flag set to
// "-s -w [-X <key>=<value>,...]" given the passed map and returns the executable name. // "-s -w [-X <key>=<value>,...]" given the passed map and returns the executable name.
func (ctx *Context) CompileWithLDFlagsX(pkg string, ldFlagsX map[string]string) string { func (ctx *Context) CompileWithLDFlagsX(pkg string, ldFlagsX map[string]string) string {