github.com/cockroachdb/pebble@v1.1.2/internal/manifest/level_test.go (about)

     1  // Copyright 2020 The LevelDB-Go and Pebble Authors. All rights reserved. Use
     2  // of this source code is governed by a BSD-style license that can be found in
     3  // the LICENSE file.
     4  
     5  package manifest
     6  
     7  import (
     8  	"fmt"
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func TestLevel(t *testing.T) {
    15  	testCases := []struct {
    16  		level    int
    17  		expected string
    18  	}{
    19  		{0, "L0"},
    20  		{1, "L1"},
    21  		{2, "L2"},
    22  		{3, "L3"},
    23  		{4, "L4"},
    24  		{5, "L5"},
    25  		{6, "L6"},
    26  		{7, "L7"},
    27  	}
    28  
    29  	for _, c := range testCases {
    30  		t.Run("", func(t *testing.T) {
    31  			s := Level(c.level).String()
    32  			require.EqualValues(t, c.expected, s)
    33  		})
    34  	}
    35  }
    36  
    37  func TestL0Sublevel(t *testing.T) {
    38  	testCases := []struct {
    39  		level    int
    40  		sublevel int
    41  		expected string
    42  	}{
    43  		{0, 0, "L0.0"},
    44  		{0, 1, "L0.1"},
    45  		{0, 2, "L0.2"},
    46  		{0, 1000, "L0.1000"},
    47  		{0, -1, "invalid L0 sublevel: -1"},
    48  		{0, -2, "invalid L0 sublevel: -2"},
    49  	}
    50  
    51  	for _, c := range testCases {
    52  		t.Run("", func(t *testing.T) {
    53  			s := func() (result string) {
    54  				defer func() {
    55  					if r := recover(); r != nil {
    56  						result = fmt.Sprint(r)
    57  					}
    58  				}()
    59  				return L0Sublevel(c.sublevel).String()
    60  			}()
    61  			require.EqualValues(t, c.expected, s)
    62  		})
    63  	}
    64  }