go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/supervisor/service_history_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2024 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package supervisor
     9  
    10  import (
    11  	"fmt"
    12  	"testing"
    13  
    14  	"go.charczuk.com/sdk/assert"
    15  )
    16  
    17  func Test_ServiceHistory_RecentFailures(t *testing.T) {
    18  	testErr := fmt.Errorf("this is just a test")
    19  	sh := ServiceHistory{
    20  		Exits: []Exit{
    21  			{Error: nil},
    22  			{Error: testErr},
    23  			{Error: nil},
    24  			{Error: testErr},
    25  			{Error: testErr},
    26  			{Error: testErr},
    27  			{Error: testErr},
    28  			{Error: testErr},
    29  		},
    30  	}
    31  	assert.ItsEqual(t, 5, len(sh.RecentFailures()))
    32  }
    33  
    34  func Test_ServiceHistory_RecentFailures_empty(t *testing.T) {
    35  	sh := ServiceHistory{
    36  		Exits: []Exit{
    37  			{Error: nil},
    38  			{Error: nil},
    39  			{Error: nil},
    40  			{Error: nil},
    41  			{Error: nil},
    42  		},
    43  	}
    44  	assert.ItsEqual(t, 0, len(sh.RecentFailures()))
    45  }
    46  
    47  func Test_ServiceHistory_RecentFailures_empty2(t *testing.T) {
    48  	testErr := fmt.Errorf("this is just a test")
    49  	sh := ServiceHistory{
    50  		Exits: []Exit{
    51  			{Error: nil},
    52  			{Error: testErr},
    53  			{Error: testErr},
    54  			{Error: testErr},
    55  			{Error: testErr},
    56  			{Error: testErr},
    57  			{Error: testErr},
    58  			{Error: nil},
    59  		},
    60  	}
    61  	assert.ItsEqual(t, 0, len(sh.RecentFailures()))
    62  }