github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/core/httpclient/getfile_test.go (about)

     1  package httpclient
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/lmorg/murex/test/count"
     7  )
     8  
     9  func TestExtractFileName(t *testing.T) {
    10  	tests := []struct {
    11  		url      string
    12  		expected string
    13  	}{
    14  		{
    15  			url:      `https://example.com`,
    16  			expected: `example.com`,
    17  		},
    18  		{
    19  			url:      `https://example.com/`,
    20  			expected: `example.com`,
    21  		},
    22  		{
    23  			url:      `https://example.com/example.txt`,
    24  			expected: `example.txt`,
    25  		},
    26  		{
    27  			url:      `https://example.com/example.txt/`,
    28  			expected: `example.txt`,
    29  		},
    30  		///// ?
    31  		{
    32  			url:      `https://example.com?`,
    33  			expected: `example.com`,
    34  		},
    35  		{
    36  			url:      `https://example.com/?`,
    37  			expected: `example.com`,
    38  		},
    39  		{
    40  			url:      `https://example.com/example.txt?`,
    41  			expected: `example.txt`,
    42  		},
    43  		{
    44  			url:      `https://example.com/example.txt/?`,
    45  			expected: `example.txt`,
    46  		},
    47  		{
    48  			url:      `https://example.com/example.txt?key=value`,
    49  			expected: `example.txt`,
    50  		},
    51  		{
    52  			url:      `https://example.com/example.txt/?key=value`,
    53  			expected: `example.txt`,
    54  		},
    55  	}
    56  
    57  	count.Tests(t, len(tests))
    58  
    59  	for i, test := range tests {
    60  		actual := extractFileName(test.url)
    61  		if test.expected != actual {
    62  			t.Errorf("mismatch in test %d", i)
    63  			t.Logf("  URL:      '%s'", test.url)
    64  			t.Logf("  Expected: '%s'", test.expected)
    65  			t.Logf("  Actual:   '%s'", actual)
    66  		}
    67  	}
    68  }