github.com/blend/go-sdk@v1.20220411.3/status/main_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  	"context"
    12  	"math"
    13  	"time"
    14  )
    15  
    16  func trackedActionConfigDefaults() TrackedActionConfig {
    17  	tac := new(TrackedActionConfig)
    18  	_ = tac.Resolve(context.Background())
    19  	return *tac
    20  }
    21  
    22  func trackedActionDefaults() *TrackedAction {
    23  	return &TrackedAction{
    24  		TrackedActionConfig: trackedActionConfigDefaults(),
    25  	}
    26  }
    27  
    28  func trackedActionDefaultsWithCounts(requestCount, errorCount int) *TrackedAction {
    29  	ta := &TrackedAction{
    30  		TrackedActionConfig: trackedActionConfigDefaults(),
    31  	}
    32  	for x := 0; x < requestCount; x++ {
    33  		ta.requests = append(ta.requests, RequestInfo{RequestTime: time.Now().UTC()})
    34  	}
    35  	for x := 0; x < errorCount; x++ {
    36  		ta.errors = append(ta.errors, ErrorInfo{Args: "test-endpoint", RequestInfo: RequestInfo{RequestTime: time.Now().UTC()}})
    37  	}
    38  	return ta
    39  }
    40  
    41  func lessThanPercentage(target int, percentage float64) (requestCount int, expected float64) {
    42  	requestCount = int(math.Floor(float64(target)/percentage)) - target>>1
    43  	expected = percentage * float64(requestCount)
    44  	return
    45  }
    46  
    47  func moreThanPercentage(target int, percentage float64) (requestCount int, expected float64) {
    48  	requestCount = int(math.Ceil(float64(target)/percentage)) + target>>1
    49  	expected = percentage * float64(requestCount)
    50  	return
    51  }