@@ -17,17 +17,16 @@ package tuf
17
17
import (
18
18
"crypto"
19
19
"crypto/sha256"
20
+ "fmt"
20
21
"net/url"
22
+ "os"
23
+ "path/filepath"
21
24
"regexp"
22
25
"strconv"
23
26
"strings"
24
27
"testing"
25
28
"time"
26
29
27
- "fmt"
28
- "os"
29
- "path/filepath"
30
-
31
30
"github.com/sigstore/sigstore/pkg/signature"
32
31
"github.com/stretchr/testify/assert"
33
32
"github.com/theupdateframework/go-tuf/v2/metadata"
@@ -463,3 +462,49 @@ func (r *testRepo) SetTimestamp(date time.Time) {
463
462
r .t .Fatal (err )
464
463
}
465
464
}
465
+
466
+ func TestURLToPath (t * testing.T ) {
467
+ tests := []struct {
468
+ name string
469
+ url string
470
+ want string
471
+ }{
472
+ {
473
+ name : "no-change" ,
474
+ url : "example.com" ,
475
+ want : "example.com" ,
476
+ },
477
+ {
478
+ name : "simple" ,
479
+ url : "https://example.com" ,
480
+ want : "example.com" ,
481
+ },
482
+ {
483
+ name : "simple with path" ,
484
+ url : "https://example.com/foo/bar" ,
485
+ want : "example.com-foo-bar" ,
486
+ },
487
+ {
488
+ name : "http scheme" ,
489
+ url : "http://example.com/foo/bar" ,
490
+ want : "example.com-foo-bar" ,
491
+ },
492
+ {
493
+ name : "different port" ,
494
+ url : "http://example.com:8080/foo/bar" ,
495
+ want : "example.com-8080-foo-bar" ,
496
+ },
497
+ {
498
+ name : "lowercase" ,
499
+ url : "http://EXAMPLE.COM:8080/foo/bar" ,
500
+ want : "example.com-8080-foo-bar" ,
501
+ },
502
+ }
503
+ for _ , tt := range tests {
504
+ t .Run (tt .name , func (t * testing.T ) {
505
+ if got := URLToPath (tt .url ); got != tt .want {
506
+ t .Errorf ("URLToPath() = %v, want %v" , got , tt .want )
507
+ }
508
+ })
509
+ }
510
+ }
0 commit comments