Skip to content

Commit

Permalink
initial test structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Itaykal committed May 18, 2024
1 parent 7dff093 commit 60643e2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 24 deletions.
43 changes: 43 additions & 0 deletions integration/mimir/alertmanager_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package mimir

import (
"os"
"testing"

"github.com/grafana/grizzly/pkg/grizzly"
"github.com/grafana/grizzly/pkg/mimir"
"github.com/grafana/grizzly/pkg/mimir/client"
"github.com/grafana/grizzly/pkg/testutil"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)

func TestAlertmanager(t *testing.T) {
alertmanagerTestFilePath := "testdata/alertmanager/test-alertmanager.yml"
provider := mimir.NewProvider(&testutil.TestContext().Mimir)
client := client.NewHTTPClient(&testutil.TestContext().Mimir)
handler := mimir.NewAlertmanagerHandler(provider, client)

t.Run("create prometheus alertmanager config", func(t *testing.T) {

Check failure on line 21 in integration/mimir/alertmanager_test.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary leading newline (whitespace)

file, err := os.ReadFile(alertmanagerTestFilePath)
require.NoError(t, err)

var resource grizzly.Resource
require.NoError(t, yaml.Unmarshal(file, &resource.Body))
require.NoError(t, handler.Add(resource))

t.Run("get remote alertmanager config", func(t *testing.T) {
file, err := os.ReadFile(alertmanagerTestFilePath)
require.NoError(t, err)

var resource grizzly.Resource
require.NoError(t, yaml.Unmarshal(file, &resource.Body))

remoteResource, err := handler.GetRemote(grizzly.Resource{})
require.NoError(t, err)

require.Equal(t, resource, *remoteResource)
})
})
}
17 changes: 0 additions & 17 deletions integration/mimir/testdata/alertmanager/no-template-files.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: grizzly.grafana.com/v1alpha1
kind: PrometheusAlertmanagerConfig
metadata:
name: test-alertmanager
name: global
spec:
template_files:
default_template: |
Expand Down
6 changes: 0 additions & 6 deletions pkg/mimir/client/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ var loadRulesEndpoint = "%s/prometheus/config/v1/rules/%s"
var listRulesEndpoint = "%s/prometheus/api/v1/rules"
var alertmanagerAPIPath = "%s/api/v1/alerts"

type GetAlertmanagerConfigResponse struct {
TemplateFiles map[string]string `yaml:"template_files"`
AlertmanagerConfig string `yaml:"alertmanager_config"`
}

type ListGroupResponse struct {
Status string `yaml:"status"`
Data struct {
Expand All @@ -50,7 +45,6 @@ func NewHTTPClient(config *config.MimirConfig) Mimir {
func (c *Client) CreateAlertmangerConfig(resource models.PrometheusAlertmanagerConfig) error {
url := fmt.Sprintf(alertmanagerAPIPath, c.config.Address)
cfg, err := yaml.Marshal(&resource)
fmt.Println(string(cfg))
if err != nil {
return err
}
Expand Down

0 comments on commit 60643e2

Please sign in to comment.