You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DateKeys/version_test.go

61 lines
2.1 KiB

package datekeys
import (
"os"
"runtime/debug"
"strings"
"testing"
)
// SpecVersion names the specification of this repository: its file, its
// title and its record in spec/README.md.
func TestSpecVersionNamesTheSpecification(t *testing.T) {
spec, err := os.ReadFile("spec/DateKeys_Protocol_Specification_v" + SpecVersion + ".md")
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(spec), "### Borrador normativo v"+SpecVersion+"\n") {
t.Error("the specification is not titled v" + SpecVersion)
}
readme, err := os.ReadFile("spec/README.md")
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(readme), "draft v"+SpecVersion+" (") {
t.Error("spec/README.md does not record v" + SpecVersion)
}
}
func TestModulePath(t *testing.T) {
if modulePath != "g.activething.com/go/DateKeys" {
t.Fatalf("module path %q", modulePath)
}
}
func TestVersion(t *testing.T) {
if Version() == "" {
t.Fatal("empty version")
}
other := debug.Module{Path: "example.com/app", Version: "v1.2.3"}
for _, tc := range []struct {
name string
info debug.BuildInfo
want string
}{
{"the main module, tagged", debug.BuildInfo{Main: debug.Module{Path: modulePath, Version: "v0.1.0"}}, "v0.1.0"},
{"the main module, from a checkout", debug.BuildInfo{Main: debug.Module{Path: modulePath, Version: "v0.0.0-20260928125528-9ac9cd952f04"}},
"v0.0.0-20260928125528-9ac9cd952f04"},
{"the main module in a test", debug.BuildInfo{Main: debug.Module{Path: modulePath}}, "(devel)"},
{"a dependency", debug.BuildInfo{Main: other, Deps: []*debug.Module{{Path: modulePath, Version: "v0.2.0"}}}, "v0.2.0"},
{"replaced by another version", debug.BuildInfo{Main: other, Deps: []*debug.Module{
{Path: modulePath, Version: "v0.2.0", Replace: &debug.Module{Path: modulePath, Version: "v0.2.1"}}}}, "v0.2.1"},
{"replaced by a directory", debug.BuildInfo{Main: other, Deps: []*debug.Module{
{Path: modulePath, Version: "v0.2.0", Replace: &debug.Module{Path: "../datekeys-go"}}}}, "(devel)"},
{"not in the program", debug.BuildInfo{Main: other}, "(devel)"},
} {
if got := versionIn(&tc.info); got != tc.want {
t.Errorf("%s: %q, want %q", tc.name, got, tc.want)
}
}
}

Powered by TurnKey Linux.