github.com/mithrandie/csvq@v1.18.1/lib/action/fields_test.go (about)

     1  package action
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/mithrandie/csvq/lib/file"
     8  
     9  	"github.com/mithrandie/csvq/lib/query"
    10  )
    11  
    12  var showFieldsTests = []struct {
    13  	Name  string
    14  	Input string
    15  	Error string
    16  }{
    17  	{
    18  		Name:  "Empty File Name Error",
    19  		Input: "",
    20  		Error: "file name is empty",
    21  	},
    22  	{
    23  		Name:  "File Not Exist Error",
    24  		Input: "notexist",
    25  		Error: "file notexist does not exist",
    26  	},
    27  }
    28  
    29  func TestShowFields(t *testing.T) {
    30  	tx, _ := query.NewTransaction(context.Background(), file.DefaultWaitTimeout, file.DefaultRetryDelay, query.NewSession())
    31  	ctx := context.Background()
    32  
    33  	for _, v := range showFieldsTests {
    34  		proc := query.NewProcessor(tx)
    35  		err := ShowFields(ctx, proc, v.Input)
    36  		if err != nil {
    37  			if len(v.Error) < 1 {
    38  				t.Errorf("%s: unexpected error %q", v.Name, err)
    39  			} else if err.Error() != v.Error {
    40  				t.Errorf("%s: error %q, want error %q", v.Name, err.Error(), v.Error)
    41  			}
    42  			continue
    43  		}
    44  		if 0 < len(v.Error) {
    45  			t.Errorf("%s: no error, want error %q", v.Name, v.Error)
    46  			continue
    47  		}
    48  	}
    49  }