github.com/thanos-io/thanos@v0.32.5/cmd/thanos/rule_test.go (about)

     1  // Copyright (c) The Thanos Authors.
     2  // Licensed under the Apache License 2.0.
     3  
     4  package main
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/efficientgo/core/testutil"
    10  )
    11  
    12  func Test_parseFlagLabels(t *testing.T) {
    13  	var tData = []struct {
    14  		s         []string
    15  		expectErr bool
    16  	}{
    17  		{
    18  			s:         []string{`labelName="LabelVal"`, `_label_Name="LabelVal"`, `label_name="LabelVal"`, `LAb_el_Name="LabelValue"`, `lab3l_Nam3="LabelValue"`},
    19  			expectErr: false,
    20  		},
    21  		{
    22  			s:         []string{`label-Name="LabelVal"`}, // Unsupported labelname.
    23  			expectErr: true,
    24  		},
    25  		{
    26  			s:         []string{`label:Name="LabelVal"`}, // Unsupported labelname.
    27  			expectErr: true,
    28  		},
    29  		{
    30  			s:         []string{`1abelName="LabelVal"`}, // Unsupported labelname.
    31  			expectErr: true,
    32  		},
    33  		{
    34  			s:         []string{`label_Name"LabelVal"`}, // Missing "=" seprator.
    35  			expectErr: true,
    36  		},
    37  		{
    38  			s:         []string{`label_Name= "LabelVal"`}, // Whitespace invalid syntax.
    39  			expectErr: true,
    40  		},
    41  		{
    42  			s:         []string{`label_name=LabelVal`}, // Missing quotes invalid syntax.
    43  			expectErr: true,
    44  		},
    45  	}
    46  	for _, td := range tData {
    47  		_, err := parseFlagLabels(td.s)
    48  		testutil.Equals(t, err != nil, td.expectErr)
    49  	}
    50  }