github.com/qri-io/qri@v0.10.1-0.20220104210721-c771715036cb/lib/params_test.go (about)

     1  package lib
     2  
     3  import (
     4  	"path/filepath"
     5  	"testing"
     6  )
     7  
     8  type testStruct struct {
     9  	Name  string
    10  	Path  string `qri:"fspath"`
    11  	Ref   string
    12  	Left  string `qri:"dsrefOrFspath"`
    13  	Right string `qri:"dsrefOrFspath"`
    14  }
    15  
    16  func TestNormalizeInputParams(t *testing.T) {
    17  	st := testStruct{
    18  		Name:  "test_data",
    19  		Path:  "testdata/dataset.yml",
    20  		Ref:   "my_peer/my_dataset",
    21  		Left:  "testdata/cities_2/body.csv",
    22  		Right: "my_peer/another_ds",
    23  	}
    24  	normalizeInputParams(&st)
    25  
    26  	if st.Name != "test_data" {
    27  		t.Errorf("Name mismatch, expected: test_data, got: %s", st.Name)
    28  	}
    29  	if !filepath.IsAbs(st.Path) {
    30  		t.Errorf("Path mismatch, expected abs path, got: %s", st.Path)
    31  	}
    32  	if st.Ref != "my_peer/my_dataset" {
    33  		t.Errorf("Ref mismatch, expected: my_peer/my_dataset, got: %s", st.Ref)
    34  	}
    35  	if !filepath.IsAbs(st.Left) {
    36  		t.Errorf("Left mismatch, expected abs path, got: %s", st.Left)
    37  	}
    38  	if st.Right != "my_peer/another_ds" {
    39  		t.Errorf("Right mismatch, expected: my_peer/another_ds, got: %s", st.Right)
    40  	}
    41  }