github.com/ethersphere/bee/v2@v2.2.0/pkg/api/metrics_test.go (about)

     1  // Copyright 2021 The Swarm Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package api_test
     6  
     7  import (
     8  	"testing"
     9  
    10  	"github.com/ethersphere/bee/v2/pkg/api"
    11  )
    12  
    13  func TestToFileSizeBucket(t *testing.T) {
    14  	t.Parallel()
    15  
    16  	var want int64 = 300000
    17  	bucket := api.ToFileSizeBucket(want)
    18  	if bucket < want {
    19  		t.Fatalf("bucket should be greater than filesize")
    20  	}
    21  
    22  	want = 5000000
    23  	bucket = api.ToFileSizeBucket(want)
    24  	if bucket != want {
    25  		t.Fatalf("bucket should be exactly 5000000")
    26  	}
    27  
    28  	overBound := api.FileSizeBucketsKBytes[len(api.FileSizeBucketsKBytes)-1]*1000 + 1
    29  	bucket = api.ToFileSizeBucket(overBound)
    30  	if bucket != api.FileSizeBucketsKBytes[len(api.FileSizeBucketsKBytes)-1]*1000 {
    31  		t.Fatalf("bucket should be the last bucket")
    32  	}
    33  }