test(tools): add unit tests for error handling functions
* Implement tests for error functions like errRequiredField, errInvalidField, and errEntityNotFound. * Ensure proper metadata is returned for various error scenarios. * Validate error handling in CRM, Files, and other tools. * Introduce tests for parsing stored file IDs and UUIDs. * Enhance coverage for helper functions related to project resolution and session management.
This commit is contained in:
41
internal/buildinfo/buildinfo.go
Normal file
41
internal/buildinfo/buildinfo.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package buildinfo
|
||||
|
||||
import "strings"
|
||||
|
||||
var (
|
||||
Version = "dev"
|
||||
TagName = "dev"
|
||||
Commit = "unknown"
|
||||
BuildDate = "unknown"
|
||||
)
|
||||
|
||||
type Info struct {
|
||||
Version string `json:"version"`
|
||||
TagName string `json:"tag_name"`
|
||||
Commit string `json:"commit"`
|
||||
BuildDate string `json:"build_date"`
|
||||
}
|
||||
|
||||
func Current() Info {
|
||||
info := Info{
|
||||
Version: strings.TrimSpace(Version),
|
||||
TagName: strings.TrimSpace(TagName),
|
||||
Commit: strings.TrimSpace(Commit),
|
||||
BuildDate: strings.TrimSpace(BuildDate),
|
||||
}
|
||||
|
||||
if info.Version == "" {
|
||||
info.Version = "dev"
|
||||
}
|
||||
if info.TagName == "" {
|
||||
info.TagName = info.Version
|
||||
}
|
||||
if info.Commit == "" {
|
||||
info.Commit = "unknown"
|
||||
}
|
||||
if info.BuildDate == "" {
|
||||
info.BuildDate = "unknown"
|
||||
}
|
||||
|
||||
return info
|
||||
}
|
||||
32
internal/buildinfo/buildinfo_test.go
Normal file
32
internal/buildinfo/buildinfo_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package buildinfo
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCurrentAppliesFallbacks(t *testing.T) {
|
||||
originalVersion, originalTagName, originalCommit, originalBuildDate := Version, TagName, Commit, BuildDate
|
||||
t.Cleanup(func() {
|
||||
Version = originalVersion
|
||||
TagName = originalTagName
|
||||
Commit = originalCommit
|
||||
BuildDate = originalBuildDate
|
||||
})
|
||||
|
||||
Version = ""
|
||||
TagName = ""
|
||||
Commit = ""
|
||||
BuildDate = ""
|
||||
|
||||
info := Current()
|
||||
if info.Version != "dev" {
|
||||
t.Fatalf("version = %q, want %q", info.Version, "dev")
|
||||
}
|
||||
if info.TagName != "dev" {
|
||||
t.Fatalf("tag_name = %q, want %q", info.TagName, "dev")
|
||||
}
|
||||
if info.Commit != "unknown" {
|
||||
t.Fatalf("commit = %q, want %q", info.Commit, "unknown")
|
||||
}
|
||||
if info.BuildDate != "unknown" {
|
||||
t.Fatalf("build_date = %q, want %q", info.BuildDate, "unknown")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user