github.com/blend/go-sdk@v1.20220411.3/status/tracked_action_aggregator_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package status
     9  
    10  import (
    11  	"testing"
    12  
    13  	"github.com/blend/go-sdk/assert"
    14  )
    15  
    16  func Test_TrackedActionAggregator_getSummarySignal(t *testing.T) {
    17  	t.Parallel()
    18  	its := assert.New(t)
    19  
    20  	empty := map[string]Info{}
    21  	its.Equal(SignalGreen, new(TrackedActionAggregator).getSummarySignal(empty))
    22  
    23  	ok := map[string]Info{
    24  		"foo": {Status: SignalGreen},
    25  		"bar": {Status: SignalGreen},
    26  		"baz": {Status: SignalGreen},
    27  	}
    28  	its.Equal(SignalGreen, new(TrackedActionAggregator).getSummarySignal(ok))
    29  
    30  	mixed := map[string]Info{
    31  		"foo": {Status: SignalGreen},
    32  		"bar": {Status: SignalYellow},
    33  		"baz": {Status: SignalRed},
    34  	}
    35  	its.Equal(SignalRed, new(TrackedActionAggregator).getSummarySignal(mixed))
    36  
    37  	bad := map[string]Info{
    38  		"foo": {Status: SignalRed},
    39  		"bar": {Status: SignalRed},
    40  		"baz": {Status: SignalRed},
    41  	}
    42  	its.Equal(SignalRed, new(TrackedActionAggregator).getSummarySignal(bad))
    43  }
    44  
    45  func Test_TrackedActionAggregator_servicesOrDefault(t *testing.T) {
    46  	t.Parallel()
    47  	its := assert.New(t)
    48  
    49  	taa := TrackedActionAggregator{
    50  		TrackedActions: map[string]*TrackedAction{
    51  			"foo": nil,
    52  			"bar": nil,
    53  			"baz": nil,
    54  		},
    55  	}
    56  
    57  	defaults := []string{"bar", "baz", "foo"} // map keys get sorted
    58  	its.Equal(defaults, taa.servicesOrDefault())
    59  
    60  	servicesToCheck := []string{"alpha", "bravo", "charlie"}
    61  	its.Equal(servicesToCheck, taa.servicesOrDefault(servicesToCheck...))
    62  }