github.com/VMitov/casper@v0.4.0/cmd/casper/flags_test.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"net/url"
     6  	"testing"
     7  )
     8  
     9  func TestFixPathsForFileSource(t *testing.T) {
    10  	dir := "/config"
    11  	cases := []struct {
    12  		u string
    13  		f string
    14  	}{
    15  		{
    16  			u: "file:///config/source.yaml?a=1",
    17  			f: "file:///config/source.yaml?a=1",
    18  		},
    19  		{
    20  			u: "file://source.yaml?a=1",
    21  			f: "file:///config/source.yaml?a=1",
    22  		},
    23  		{
    24  			u: "file://./source.yaml?a=1",
    25  			f: "file:///config/source.yaml?a=1",
    26  		},
    27  		{
    28  			u: "file://../source.yaml?a=1",
    29  			f: "file:///source.yaml?a=1",
    30  		},
    31  		{
    32  			u: "file://../config/source.yaml?a=1",
    33  			f: "file:///config/source.yaml?a=1",
    34  		},
    35  	}
    36  
    37  	for i, tc := range cases {
    38  		t.Run(fmt.Sprintf("Case%v", i), func(t *testing.T) {
    39  			u, err := url.Parse(tc.u)
    40  			if err != nil {
    41  				t.Fatal(err)
    42  			}
    43  
    44  			f, err := fixPathsForFileSource(dir, u)
    45  			if err != nil {
    46  				t.Fatal(err)
    47  			}
    48  
    49  			if f != tc.f {
    50  				t.Errorf("Got: %v; Expected: %v", f, tc.f)
    51  			}
    52  		})
    53  	}
    54  }