...

Source file src/github.com/prometheus/alertmanager/notify/pushover/pushover_test.go

Documentation: github.com/prometheus/alertmanager/notify/pushover

     1  // Copyright 2019 Prometheus Team
     2  // Licensed under the Apache License, Version 2.0 (the "License");
     3  // you may not use this file except in compliance with the License.
     4  // You may obtain a copy of the License at
     5  //
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package pushover
    15  
    16  import (
    17  	"fmt"
    18  	"testing"
    19  
    20  	"github.com/go-kit/log"
    21  	commoncfg "github.com/prometheus/common/config"
    22  	"github.com/stretchr/testify/require"
    23  
    24  	"github.com/prometheus/alertmanager/config"
    25  	"github.com/prometheus/alertmanager/notify/test"
    26  )
    27  
    28  func TestPushoverRetry(t *testing.T) {
    29  	notifier, err := New(
    30  		&config.PushoverConfig{
    31  			HTTPConfig: &commoncfg.HTTPClientConfig{},
    32  		},
    33  		test.CreateTmpl(t),
    34  		log.NewNopLogger(),
    35  	)
    36  	require.NoError(t, err)
    37  	for statusCode, expected := range test.RetryTests(test.DefaultRetryCodes()) {
    38  		actual, _ := notifier.retrier.Check(statusCode, nil)
    39  		require.Equal(t, expected, actual, fmt.Sprintf("error on status %d", statusCode))
    40  	}
    41  }
    42  
    43  func TestPushoverRedactedURL(t *testing.T) {
    44  	ctx, u, fn := test.GetContextWithCancelingURL()
    45  	defer fn()
    46  
    47  	key, token := "user_key", "token"
    48  	notifier, err := New(
    49  		&config.PushoverConfig{
    50  			UserKey:    config.Secret(key),
    51  			Token:      config.Secret(token),
    52  			HTTPConfig: &commoncfg.HTTPClientConfig{},
    53  		},
    54  		test.CreateTmpl(t),
    55  		log.NewNopLogger(),
    56  	)
    57  	require.NoError(t, err)
    58  	notifier.apiURL = u.String()
    59  
    60  	test.AssertNotifyLeaksNoSecret(ctx, t, notifier, key, token)
    61  }
    62  

View as plain text