github.com/inspektor-gadget/inspektor-gadget@v0.28.1/pkg/columns/formatter/textcolumns/options_test.go (about)

     1  // Copyright 2022 The Inspektor Gadget authors
     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 textcolumns
    16  
    17  import "testing"
    18  
    19  func TestOptions(t *testing.T) {
    20  	opts := &Options{
    21  		AutoScale:      false,
    22  		ColumnDivider:  "",
    23  		DefaultColumns: nil,
    24  		HeaderStyle:    0,
    25  		RowDivider:     DividerNone,
    26  	}
    27  
    28  	WithAutoScale(true)(opts)
    29  	if !opts.AutoScale {
    30  		t.Errorf("Expected AutoScale to be true")
    31  	}
    32  
    33  	WithColumnDivider("X")(opts)
    34  	if opts.ColumnDivider != "X" {
    35  		t.Errorf("Expected ColumnDivider to be X")
    36  	}
    37  
    38  	WithDefaultColumns([]string{"abc"})(opts)
    39  	if len(opts.DefaultColumns) != 1 || opts.DefaultColumns[0] != "abc" {
    40  		t.Errorf("Expected DefaultColumns to have exactly 'abc' as value")
    41  	}
    42  
    43  	WithHeaderStyle(HeaderStyleLowercase)(opts)
    44  	if opts.HeaderStyle != HeaderStyleLowercase {
    45  		t.Errorf("Expected HeaderStyle to be HeaderStyleLowercase")
    46  	}
    47  
    48  	WithRowDivider("X")(opts)
    49  	if opts.RowDivider != "X" {
    50  		t.Errorf("Expected RowDivider to be X")
    51  	}
    52  }