gogio: improve -version parse error message

Add a test while here.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2025-05-22 17:07:15 +02:00
parent ae8dd5433d
commit 1b42337ac0
3 changed files with 37 additions and 12 deletions
+32 -5
View File
@@ -2,14 +2,12 @@ package main
import "testing"
type expval struct {
in, out string
}
func TestAppID(t *testing.T) {
t.Parallel()
tests := []expval{
tests := []struct {
in, out string
}{
{"example", "localhost.example"},
{"example.com", "com.example"},
{"www.example.com", "com.example.www"},
@@ -30,3 +28,32 @@ func TestAppID(t *testing.T) {
}
}
}
func TestVersion(t *testing.T) {
t.Parallel()
tests := []struct {
version string
valid bool
}{
{"v1", false},
{"v10.21.333.12", false},
{"1.2.3", false},
{"1.2.3.4", true},
}
for i, test := range tests {
ver, err := parseSemver(test.version)
if err != nil {
if test.valid {
t.Errorf("(%d): %q failed to parse: %v", i, test.version, err)
}
continue
} else if !test.valid {
t.Errorf("(%d): %q was unexpectedly accepted", i, test.version)
}
if got := ver.String(); got != test.version {
t.Errorf("(%d): %q parsed to %q", i, test.version, got)
}
}
}