...

Source file src/edge-infra.dev/pkg/edge/monitoring/billman/costs/costs_test.go

Documentation: edge-infra.dev/pkg/edge/monitoring/billman/costs

     1  package costs
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestLogCosts(t *testing.T) {
    10  	testCases := []struct {
    11  		bytes        int64
    12  		rate         float64
    13  		expectedCost float64
    14  	}{
    15  		{
    16  			0,
    17  			.50,
    18  			0,
    19  		}, {
    20  			1073741824, // 1GiB
    21  			.50,
    22  			0.50,
    23  		}, {
    24  			107374182400, // 100GiB
    25  			.50,
    26  			50,
    27  		},
    28  	}
    29  
    30  	for _, tc := range testCases {
    31  		cost := LogCosts(tc.bytes, tc.rate)
    32  		assert.Equal(t, cost, tc.expectedCost)
    33  	}
    34  }
    35  
    36  func TestMetricCosts(t *testing.T) {
    37  	testCases := []struct {
    38  		samples      int64
    39  		rate         float64
    40  		expectedCost float64
    41  	}{
    42  		{
    43  			0,
    44  			.15,
    45  			0,
    46  		}, {
    47  			1000000,
    48  			.15,
    49  			0.15,
    50  		}, {
    51  			17520000000, // 17,520 million
    52  			.15,
    53  			2628,
    54  		}, {
    55  			175200000000, // 175,200 million
    56  			.15,
    57  			26280,
    58  		},
    59  	}
    60  
    61  	for _, tc := range testCases {
    62  		cost := MetricCosts(tc.samples, tc.rate)
    63  		assert.Equal(t, cost, tc.expectedCost)
    64  	}
    65  }
    66  

View as plain text