github.com/webonyx/up@v0.7.4-0.20180808230834-91b94e551323/config/alerts_test.go (about)

     1  package config
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/tj/assert"
     7  )
     8  
     9  func TestAlert_Validate(t *testing.T) {
    10  	t.Run("invalid operator", func(t *testing.T) {
    11  		a := Alert{
    12  			Operator: "===",
    13  		}
    14  
    15  		assert.EqualError(t, a.Validate(), `.operator: "===" is invalid, must be one of:
    16  
    17    • <
    18    • <=
    19    • >
    20    • >=`)
    21  	})
    22  
    23  	t.Run("invalid statistic", func(t *testing.T) {
    24  		a := Alert{
    25  			Operator:  ">=",
    26  			Statistic: "minimumm",
    27  		}
    28  
    29  		assert.EqualError(t, a.Validate(), `.statistic: "minimumm" is invalid, must be one of:
    30  
    31    • average
    32    • avg
    33    • count
    34    • max
    35    • maximum
    36    • min
    37    • minimum
    38    • sum`)
    39  	})
    40  
    41  	t.Run("namespace explicit", func(t *testing.T) {
    42  		a := Alert{
    43  			Metric:    "5XXError",
    44  			Statistic: "minimum",
    45  			Namespace: "AWS/ApiGateway",
    46  		}
    47  
    48  		assert.NoError(t, a.Default(), "default")
    49  		assert.NoError(t, a.Validate(), "default")
    50  
    51  		assert.Equal(t, "AWS/ApiGateway", a.Namespace)
    52  		assert.Equal(t, "GreaterThanThreshold", a.Operator)
    53  		assert.Equal(t, "5XXError", a.Metric)
    54  	})
    55  
    56  	t.Run("namespace api", func(t *testing.T) {
    57  		a := &Alert{
    58  			Metric:    "http.5xx",
    59  			Statistic: "min",
    60  		}
    61  
    62  		assert.NoError(t, a.Default(), "default")
    63  		assert.NoError(t, a.Validate(), "default")
    64  
    65  		assert.Equal(t, "AWS/ApiGateway", a.Namespace)
    66  		assert.Equal(t, "GreaterThanThreshold", a.Operator)
    67  		assert.Equal(t, "5XXError", a.Metric)
    68  	})
    69  }