github.com/influxdata/influxdb/v2@v2.7.6/label_test.go (about)

     1  package influxdb_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/influxdata/influxdb/v2"
     7  	"github.com/influxdata/influxdb/v2/kit/platform"
     8  	influxtest "github.com/influxdata/influxdb/v2/testing"
     9  )
    10  
    11  const (
    12  	orgOneID = "020f755c3c083000"
    13  )
    14  
    15  func TestLabelValidate(t *testing.T) {
    16  	type fields struct {
    17  		Name  string
    18  		OrgID platform.ID
    19  	}
    20  	tests := []struct {
    21  		name    string
    22  		fields  fields
    23  		wantErr bool
    24  	}{
    25  		{
    26  			name: "valid label",
    27  			fields: fields{
    28  				Name:  "iot",
    29  				OrgID: influxtest.MustIDBase16(orgOneID),
    30  			},
    31  		},
    32  		{
    33  			name: "label requires a name",
    34  			fields: fields{
    35  				OrgID: influxtest.MustIDBase16(orgOneID),
    36  			},
    37  			wantErr: true,
    38  		},
    39  		{
    40  			name: "label requires an organization ID",
    41  			fields: fields{
    42  				Name: "iot",
    43  			},
    44  			wantErr: true,
    45  		},
    46  	}
    47  	for _, tt := range tests {
    48  		t.Run(tt.name, func(t *testing.T) {
    49  			m := influxdb.Label{
    50  				Name:  tt.fields.Name,
    51  				OrgID: tt.fields.OrgID,
    52  			}
    53  			if err := m.Validate(); (err != nil) != tt.wantErr {
    54  				t.Errorf("Label.Validate() error = %v, wantErr %v", err, tt.wantErr)
    55  			}
    56  		})
    57  	}
    58  }