mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
Merge pull request #1230 from prymitive/am-0.20
fix(backend): correct pre-release version parsing for alertmanager up…
This commit is contained in:
40
internal/alertmanager/mapper_test.go
Normal file
40
internal/alertmanager/mapper_test.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package alertmanager
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prymitive/karma/internal/mapper"
|
||||
)
|
||||
|
||||
func TestGetAlertMapper(t *testing.T) {
|
||||
versions := []string{
|
||||
"0.4.0",
|
||||
"0.4.1",
|
||||
"0.4.99",
|
||||
"0.5.0-alpha.0",
|
||||
"0.5.0-beta.0",
|
||||
"0.10",
|
||||
"0.10.11",
|
||||
"0.15.0-rc.3",
|
||||
"0.17.0",
|
||||
"0.20.0-rc.0",
|
||||
"0.20.0-rc.0-2",
|
||||
}
|
||||
|
||||
for _, version := range versions {
|
||||
_, err := mapper.GetAlertMapper(version)
|
||||
if err != nil {
|
||||
t.Errorf("mapper.GetAlertMapper(%s) returned error: %s", version, err)
|
||||
}
|
||||
|
||||
_, err = mapper.GetSilenceMapper(version)
|
||||
if err != nil {
|
||||
t.Errorf("mapper.GetSilenceMapper(%s) returned error: %s", version, err)
|
||||
}
|
||||
|
||||
_, err = mapper.GetStatusMapper(version)
|
||||
if err != nil {
|
||||
t.Errorf("mapper.GetStatusMapper(%s) returned error: %s", version, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/prymitive/karma/internal/models"
|
||||
@@ -50,10 +51,15 @@ func RegisterAlertMapper(m AlertMapper) {
|
||||
alertMappers = append(alertMappers, m)
|
||||
}
|
||||
|
||||
func fixSemVersion(version string) string {
|
||||
// https://github.com/Masterminds/semver/issues/135
|
||||
return strings.SplitN(version, "-", 2)[0]
|
||||
}
|
||||
|
||||
// GetAlertMapper returns mapper for given version
|
||||
func GetAlertMapper(version string) (AlertMapper, error) {
|
||||
for _, m := range alertMappers {
|
||||
if m.IsSupported(version) {
|
||||
if m.IsSupported(fixSemVersion(version)) {
|
||||
return m, nil
|
||||
}
|
||||
}
|
||||
@@ -69,7 +75,7 @@ func RegisterSilenceMapper(m SilenceMapper) {
|
||||
// GetSilenceMapper returns mapper for given version
|
||||
func GetSilenceMapper(version string) (SilenceMapper, error) {
|
||||
for _, m := range silenceMappers {
|
||||
if m.IsSupported(version) {
|
||||
if m.IsSupported(fixSemVersion(version)) {
|
||||
return m, nil
|
||||
}
|
||||
}
|
||||
@@ -85,7 +91,7 @@ func RegisterStatusMapper(m StatusMapper) {
|
||||
// GetStatusMapper returns mapper for given version
|
||||
func GetStatusMapper(version string) (StatusMapper, error) {
|
||||
for _, m := range statusMappers {
|
||||
if m.IsSupported(version) {
|
||||
if m.IsSupported(fixSemVersion(version)) {
|
||||
return m, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user