github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/cmd/server/cacheconfig_test.go (about) 1 package server 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 ) 8 9 func TestParsePercent(t *testing.T) { 10 table := []struct { 11 percent string 12 freeMem uint64 13 expected uint64 14 expectedErr error 15 }{ 16 {"100%", 1000, 1000, nil}, 17 {"0%", 1000, 0, nil}, 18 {"50%", 1000, 500, nil}, 19 {"100%", 0, 0, nil}, 20 {"1000%", 1000, 0, errOverHundredPercent}, 21 } 22 23 for _, tt := range table { 24 v, err := parsePercent(tt.percent, tt.freeMem) 25 if tt.expectedErr == nil { 26 require.Nil(t, err) 27 } else { 28 require.Equal(t, tt.expectedErr, err) 29 } 30 require.Equal(t, tt.expected, v) 31 } 32 }