github.com/google/cadvisor@v0.49.1/devicemapper/thin_ls_client_test.go (about)

     1  // Copyright 2016 Google Inc. All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package devicemapper
    16  
    17  import (
    18  	"reflect"
    19  	"testing"
    20  )
    21  
    22  func TestParseThinLsOutput(t *testing.T) {
    23  	cases := []struct {
    24  		name           string
    25  		input          string
    26  		expectedResult map[string]uint64
    27  	}{
    28  		{
    29  			name: "ok",
    30  			input: `
    31    1         2293760
    32    2         2097152
    33    3          131072
    34    4         2031616`,
    35  			expectedResult: map[string]uint64{
    36  				"1": 2293760,
    37  				"2": 2097152,
    38  				"3": 131072,
    39  				"4": 2031616,
    40  			},
    41  		},
    42  		{
    43  			name: "skip bad rows",
    44  			input: `
    45    1         2293760
    46    2         2097152
    47    3          131072ads
    48    4d dsrv         2031616`,
    49  			expectedResult: map[string]uint64{
    50  				"1": 2293760,
    51  				"2": 2097152,
    52  			},
    53  		},
    54  	}
    55  
    56  	for _, tc := range cases {
    57  		actualResult := parseThinLsOutput([]byte(tc.input))
    58  		if e, a := tc.expectedResult, actualResult; !reflect.DeepEqual(e, a) {
    59  			t.Errorf("%v: unexpected result: expected %+v got %+v", tc.name, e, a)
    60  		}
    61  	}
    62  }