Files
commandkit/builtins_test.go

59 lines
1.7 KiB
Go
Raw Permalink Normal View History

package commandkit
import (
"runtime/debug"
"testing"
)
func TestCommandKitBuildIdentityProjectsEffectiveModuleVersion(t *testing.T) {
tests := []struct {
name string
info *debug.BuildInfo
want string
}{
{
name: "main module tag",
info: &debug.BuildInfo{Main: debug.Module{Path: commandKitModulePath, Version: "v1.2.3"}},
want: "v1.2.3",
},
{
name: "dependency tag",
info: &debug.BuildInfo{Main: debug.Module{Path: "example.com/application", Version: "v4.0.0"}, Deps: []*debug.Module{{Path: commandKitModulePath, Version: "v1.2.3"}}},
want: "v1.2.3",
},
{
name: "versioned replacement",
info: &debug.BuildInfo{Main: debug.Module{Path: "example.com/application"}, Deps: []*debug.Module{{Path: commandKitModulePath, Version: "v1.2.3", Replace: &debug.Module{Path: "example.com/fork", Version: "v2.0.0"}}}},
want: "v2.0.0",
},
{
name: "local replacement",
info: &debug.BuildInfo{Main: debug.Module{Path: commandKitModulePath, Version: "v1.2.3", Replace: &debug.Module{Path: "../CommandKit"}}},
want: "dev",
},
{
name: "development module",
info: &debug.BuildInfo{Main: debug.Module{Path: commandKitModulePath, Version: "(devel)"}},
want: "dev",
},
{
name: "missing module",
info: &debug.BuildInfo{Main: debug.Module{Path: "example.com/application"}},
want: "dev",
},
{
name: "missing build info",
info: nil,
want: "dev",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
identity := commandKitBuildIdentity(test.info)
if identity.Name != "CommandKit" || identity.Version != test.want || identity.Revision != "" {
t.Fatalf("identity = %#v, want CommandKit %q with no revision", identity, test.want)
}
})
}
}