feat: use GetVersion()
This commit is contained in:
@@ -55,7 +55,7 @@ func run(args []string) error {
|
|||||||
|
|
||||||
docs.SwaggerInfo.Title = fmt.Sprintf("%s API", cfg.App.Title)
|
docs.SwaggerInfo.Title = fmt.Sprintf("%s API", cfg.App.Title)
|
||||||
docs.SwaggerInfo.Description = "Y Combinator-style news board API."
|
docs.SwaggerInfo.Description = "Y Combinator-style news board API."
|
||||||
docs.SwaggerInfo.Version = version.Version
|
docs.SwaggerInfo.Version = version.GetVersion()
|
||||||
docs.SwaggerInfo.BasePath = "/api"
|
docs.SwaggerInfo.BasePath = "/api"
|
||||||
docs.SwaggerInfo.Host = fmt.Sprintf("%s:%s", cfg.Server.Host, cfg.Server.Port)
|
docs.SwaggerInfo.Host = fmt.Sprintf("%s:%s", cfg.Server.Host, cfg.Server.Port)
|
||||||
docs.SwaggerInfo.Schemes = []string{"http"}
|
docs.SwaggerInfo.Schemes = []string{"http"}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ func (h *APIHandler) GetAPIInfo(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
apiInfo := map[string]any{
|
apiInfo := map[string]any{
|
||||||
"name": fmt.Sprintf("%s API", h.config.App.Title),
|
"name": fmt.Sprintf("%s API", h.config.App.Title),
|
||||||
"version": version.Version,
|
"version": version.GetVersion(),
|
||||||
"description": "Y Combinator-style news board API",
|
"description": "Y Combinator-style news board API",
|
||||||
"endpoints": map[string]any{
|
"endpoints": map[string]any{
|
||||||
"authentication": map[string]any{
|
"authentication": map[string]any{
|
||||||
@@ -145,7 +145,7 @@ func (h *APIHandler) GetHealth(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
if h.healthChecker != nil {
|
if h.healthChecker != nil {
|
||||||
health := h.healthChecker.CheckHealth()
|
health := h.healthChecker.CheckHealth()
|
||||||
health["version"] = version.Version
|
health["version"] = version.GetVersion()
|
||||||
SendSuccessResponse(w, "Health check successful", health)
|
SendSuccessResponse(w, "Health check successful", health)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ func (h *APIHandler) GetHealth(w http.ResponseWriter, r *http.Request) {
|
|||||||
health := map[string]any{
|
health := map[string]any{
|
||||||
"status": "healthy",
|
"status": "healthy",
|
||||||
"timestamp": currentTimestamp,
|
"timestamp": currentTimestamp,
|
||||||
"version": version.Version,
|
"version": version.GetVersion(),
|
||||||
"services": map[string]any{
|
"services": map[string]any{
|
||||||
"database": "connected",
|
"database": "connected",
|
||||||
"api": "running",
|
"api": "running",
|
||||||
@@ -230,7 +230,7 @@ func (h *APIHandler) GetMetrics(w http.ResponseWriter, r *http.Request) {
|
|||||||
},
|
},
|
||||||
"system": map[string]any{
|
"system": map[string]any{
|
||||||
"timestamp": time.Now().UTC().Format(time.RFC3339),
|
"timestamp": time.Now().UTC().Format(time.RFC3339),
|
||||||
"version": version.Version,
|
"version": version.GetVersion(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,39 +8,39 @@ import (
|
|||||||
func TestVersionSemver(t *testing.T) {
|
func TestVersionSemver(t *testing.T) {
|
||||||
semverRegex := regexp.MustCompile(`^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`)
|
semverRegex := regexp.MustCompile(`^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`)
|
||||||
|
|
||||||
if !semverRegex.MatchString(Version) {
|
if !semverRegex.MatchString(GetVersion()) {
|
||||||
t.Errorf("Version %q does not follow semantic versioning format (MAJOR.MINOR.PATCH[-PRERELEASE][+BUILD])", Version)
|
t.Errorf("Version %q does not follow semantic versioning format (MAJOR.MINOR.PATCH[-PRERELEASE][+BUILD])", GetVersion())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVersionSemverFlexible(t *testing.T) {
|
func TestVersionSemverFlexible(t *testing.T) {
|
||||||
flexibleSemverRegex := regexp.MustCompile(`^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`)
|
flexibleSemverRegex := regexp.MustCompile(`^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`)
|
||||||
|
|
||||||
if !flexibleSemverRegex.MatchString(Version) {
|
if !flexibleSemverRegex.MatchString(GetVersion()) {
|
||||||
t.Errorf("Version %q does not follow semantic versioning format (MAJOR.MINOR[.PATCH][-PRERELEASE][+BUILD])", Version)
|
t.Errorf("Version %q does not follow semantic versioning format (MAJOR.MINOR[.PATCH][-PRERELEASE][+BUILD])", GetVersion())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVersionNotEmpty(t *testing.T) {
|
func TestVersionNotEmpty(t *testing.T) {
|
||||||
if Version == "" {
|
if GetVersion() == "" {
|
||||||
t.Error("Version should not be empty")
|
t.Error("Version should not be empty")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVersionFormat(t *testing.T) {
|
func TestVersionFormat(t *testing.T) {
|
||||||
if !regexp.MustCompile(`\d+\.\d+`).MatchString(Version) {
|
if !regexp.MustCompile(`\d+\.\d+`).MatchString(GetVersion()) {
|
||||||
t.Errorf("Version %q should contain at least MAJOR.MINOR format", Version)
|
t.Errorf("Version %q should contain at least MAJOR.MINOR format", GetVersion())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVersionStartsWithNumber(t *testing.T) {
|
func TestVersionStartsWithNumber(t *testing.T) {
|
||||||
if !regexp.MustCompile(`^\d+`).MatchString(Version) {
|
if !regexp.MustCompile(`^\d+`).MatchString(GetVersion()) {
|
||||||
t.Errorf("Version %q should start with a number", Version)
|
t.Errorf("Version %q should start with a number", GetVersion())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVersionNoLeadingZeros(t *testing.T) {
|
func TestVersionNoLeadingZeros(t *testing.T) {
|
||||||
parts := regexp.MustCompile(`^(\d+)\.(\d+)`).FindStringSubmatch(Version)
|
parts := regexp.MustCompile(`^(\d+)\.(\d+)`).FindStringSubmatch(GetVersion())
|
||||||
if len(parts) >= 3 {
|
if len(parts) >= 3 {
|
||||||
major := parts[1]
|
major := parts[1]
|
||||||
minor := parts[2]
|
minor := parts[2]
|
||||||
|
|||||||
Reference in New Issue
Block a user