2022-05-21 00:49:13 +02:00
|
|
|
// Copyright 2022 wanderer <a_mirre at utb dot cz>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-05-12 15:54:16 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"os"
|
|
|
|
"regexp"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNixFlake_GosrcVersionStringEquivalence(t *testing.T) {
|
|
|
|
want := GetShortVersion()
|
|
|
|
fData, err := os.ReadFile("../flake.nix")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Failed to open flake.nix: %q", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
got := bytes.Contains(fData, []byte(" version = \""+want+"\""))
|
|
|
|
|
|
|
|
if !got {
|
|
|
|
t.Errorf("Version string '%q' not found in ../flake.nix", want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestVersionStringFormat(t *testing.T) {
|
|
|
|
v := version
|
|
|
|
// this expression matches the format of "vX.Y.Z" where {X,Y,Z} are digits
|
|
|
|
// (such as 0 or 123)
|
|
|
|
re := regexp.MustCompile(`^(v\d+\.\d+\.\d+)$`)
|
|
|
|
match := re.MatchString(v)
|
|
|
|
|
|
|
|
if !match {
|
|
|
|
t.Errorf("Incorrect version string format, must match regex: '%q', provided version string: '%q'", re.String(), v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetVersion(t *testing.T) {
|
|
|
|
want := appName + " - " + version
|
|
|
|
got := getVersion()
|
|
|
|
|
|
|
|
if want != got {
|
|
|
|
t.Errorf("Incorrect version string, want: '%q', got: '%q'", want, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-27 22:14:29 +02:00
|
|
|
// set shortVersion variable manually.
|
2022-05-12 15:54:16 +02:00
|
|
|
func TestGetVersionWithShortVersionVar(t *testing.T) {
|
|
|
|
shortVersion = true
|
|
|
|
want := version
|
|
|
|
|
|
|
|
got := getVersion()
|
|
|
|
|
|
|
|
if want != got {
|
|
|
|
t.Errorf("Incorrect version string when 'shortVersion' is true, want: '%q', got: '%q'", want, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-27 22:14:29 +02:00
|
|
|
// explicitly get short version.
|
2022-05-12 15:54:16 +02:00
|
|
|
func TestGetShortVersion(t *testing.T) {
|
|
|
|
want := version
|
|
|
|
got := GetShortVersion()
|
|
|
|
|
|
|
|
if want != got {
|
|
|
|
t.Errorf("Incorrect 'short' version string, want: '%q', got: '%q'", want, got)
|
|
|
|
}
|
|
|
|
}
|