func TestPrintVersion(t *testing.T) { version.Arch = "Linux-x86_64" version.Branch = "master" version.ShaLong = gotil.RandomString(32) version.Epoch = fmt.Sprintf("%d", time.Now().Unix()) version.SemVer = "1.0.0" _, _, thisAbsPath := gotil.GetThisPathParts() epochStr := version.EpochToRfc1123() t.Logf("thisAbsPath=%s", thisAbsPath) t.Logf("epochStr=%s", epochStr) var buff []byte b := bytes.NewBuffer(buff) PrintVersion(b) vs := b.String() evs := `Binary: ` + thisAbsPath + ` SemVer: ` + version.SemVer + ` OsArch: ` + version.Arch + ` Branch: ` + version.Branch + ` Commit: ` + version.ShaLong + ` Formed: ` + epochStr + ` ` if vs != evs { t.Fatalf("nexpectedVersionString=%s\n\nversionString=%s\n", evs, vs) } }
// PrintVersion prints the current version information to the provided writer. func PrintVersion(out io.Writer) { fmt.Fprintf(out, "Binary: %s\n", thisExeAbsPath) fmt.Fprintf(out, "SemVer: %s\n", version.SemVer) fmt.Fprintf(out, "OsArch: %s\n", version.Arch) fmt.Fprintf(out, "Branch: %s\n", version.Branch) fmt.Fprintf(out, "Commit: %s\n", version.ShaLong) fmt.Fprintf(out, "Formed: %s\n", version.EpochToRfc1123()) }