Skip to content

Commit

Permalink
private/testcontext: remove version dependency
Browse files Browse the repository at this point in the history
Change-Id: Ibabf5ec774dcdb1e4fc2f200368281c69b62e6c2
  • Loading branch information
egonelbre committed Dec 18, 2019
1 parent 9ed9d35 commit 2daf24a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
17 changes: 15 additions & 2 deletions cmd/storagenode-updater/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -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)

Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 0 additions & 18 deletions private/testcontext/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down Expand Up @@ -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 <key>=<value>,...]" given the passed map and returns the executable name.
func (ctx *Context) CompileWithLDFlagsX(pkg string, ldFlagsX map[string]string) string {
Expand Down

0 comments on commit 2daf24a

Please sign in to comment.