@@ -51,6 +51,9 @@ func Test_S3Path_Parse(t *testing.T) {
5151 if err != nil {
5252 t .Fatalf ("unexpected error parsing s3 path: %v" , err )
5353 }
54+ if s3path .scheme != "s3" {
55+ t .Fatalf ("unexpected scheme for s3 path, got %q expected \" s3\" : %v" , s3path .scheme , s3path )
56+ }
5457 if s3path .bucket != g .ExpectedBucket {
5558 t .Fatalf ("unexpected s3 path: %v" , s3path )
5659 }
@@ -65,6 +68,81 @@ func Test_S3Path_Parse(t *testing.T) {
6568 }
6669}
6770
71+ func Test_LinodePath_Parse (t * testing.T ) {
72+ grid := []struct {
73+ Input string
74+ ExpectError bool
75+ ExpectedBucket string
76+ ExpectedPath string
77+ }{
78+ {
79+ Input : "linode://bucket" ,
80+ ExpectedBucket : "bucket" ,
81+ ExpectedPath : "" ,
82+ },
83+ {
84+ Input : "linode://bucket/path" ,
85+ ExpectedBucket : "bucket" ,
86+ ExpectedPath : "path" ,
87+ },
88+ {
89+ Input : "linode://bucket2/path/subpath" ,
90+ ExpectedBucket : "bucket2" ,
91+ ExpectedPath : "path/subpath" ,
92+ },
93+ {
94+ Input : "linode:///bucket/path/subpath" ,
95+ ExpectError : true ,
96+ },
97+ }
98+ for _ , g := range grid {
99+ s3path , err := Context .buildLinodePath (g .Input )
100+ if ! g .ExpectError {
101+ if err != nil {
102+ t .Fatalf ("unexpected error parsing linode path: %v" , err )
103+ }
104+ if s3path .scheme != "linode" {
105+ t .Fatalf ("expected scheme=\" linode\" for linode path, got %q: %v" , s3path .scheme , s3path )
106+ }
107+ if s3path .bucket != g .ExpectedBucket {
108+ t .Fatalf ("unexpected linode path: %v" , s3path )
109+ }
110+ if s3path .key != g .ExpectedPath {
111+ t .Fatalf ("unexpected linode path: %v" , s3path )
112+ }
113+ } else {
114+ if err == nil {
115+ t .Fatalf ("unexpected error parsing %q" , g .Input )
116+ }
117+ }
118+ }
119+ }
120+
121+ func Test_NonLinodeObjectStoragePaths_HaveCorrectScheme (t * testing.T ) {
122+ grid := []struct {
123+ name string
124+ input string
125+ scheme string
126+ build func (string ) (* S3Path , error )
127+ }{
128+ {name : "do" , input : "do://bucket/path" , scheme : "do" , build : Context .buildDOPath },
129+ {name : "hos" , input : "hos://bucket/path" , scheme : "hos" , build : Context .buildHetznerPath },
130+ {name : "scw" , input : "scw://bucket/path" , scheme : "scw" , build : Context .buildSCWPath },
131+ }
132+
133+ for _ , tc := range grid {
134+ t .Run (tc .name , func (t * testing.T ) {
135+ s3path , err := tc .build (tc .input )
136+ if err != nil {
137+ t .Fatalf ("unexpected error parsing %s path: %v" , tc .name , err )
138+ }
139+ if s3path .scheme != tc .scheme {
140+ t .Fatalf ("unexpected scheme for %s path, got %q expected %q" , tc .name , s3path .scheme , tc .scheme )
141+ }
142+ })
143+ }
144+ }
145+
68146func TestGetHTTPsUrl (t * testing.T ) {
69147 grid := []struct {
70148 Path string
0 commit comments