srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/internal/version/version_test.go
blob: d2d501b06378b47486a83ae82d25b94e8169994b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package version

import "testing"

func TestStringDefault(t *testing.T) {
	orig := Version
	Version, Commit, Date = "dev", "", ""
	defer func() { Version = orig }()
	if got := String("mitmux"); got != "mitmux dev" {
		t.Errorf("String(%q) = %q, want %q", "mitmux", got, "mitmux dev")
	}
}

func TestStringWithCommitAndDate(t *testing.T) {
	origV, origC, origD := Version, Commit, Date
	Version, Commit, Date = "1.2.3", "abc1234", "2026-01-02"
	defer func() { Version, Commit, Date = origV, origC, origD }()
	want := "mitmuxd 1.2.3 (abc1234, 2026-01-02)"
	if got := String("mitmuxd"); got != want {
		t.Errorf("String(%q) = %q, want %q", "mitmuxd", got, want)
	}
}

func TestStringCommitOnly(t *testing.T) {
	origV, origC, origD := Version, Commit, Date
	Version, Commit, Date = "1.2.3", "abc1234", ""
	defer func() { Version, Commit, Date = origV, origC, origD }()
	want := "mitmux 1.2.3 (abc1234)"
	if got := String("mitmux"); got != want {
		t.Errorf("String(%q) = %q, want %q", "mitmux", got, want)
	}
}