@@ -18,6 +18,7 @@ package resources
18
18
import (
19
19
"crypto"
20
20
"encoding/hex"
21
+ "fmt"
21
22
"net"
22
23
"net/http"
23
24
"net/url"
@@ -148,3 +149,25 @@ func TestIndexDownloadAndSignatureWithinArchive(t *testing.T) {
148
149
require.False(t, invDestDir.Join("package_index.json").Exist())
149
150
require.False(t, invDestDir.Join("package_index.json.sig").Exist())
150
151
}
152
+
153
+ func TestIndexFileName(t *testing.T) {
154
+ tests := []struct {
155
+ url string
156
+ expected string
157
+ }{
158
+ {url: "package_index.json", expected: "package_index.json"},
159
+ {url: "package_index.json.gz", expected: "package_index.json"},
160
+ {url: "package_index.tar.bz2", expected: "package_index.json"},
161
+ // https://github.com/arduino/arduino-cli/issues/2345
162
+ {url: "package_arduino.cc_index.json", expected: "package_arduino.cc_index.json"},
163
+ {url: "package_arduino.cc_index.json.gz", expected: "package_arduino.cc_index.json"},
164
+ {url: "package_arduino.cc_index.tar.bz2", expected: "package_arduino.cc_index.json"},
165
+ {url: "http://drazzy.com/package_drazzy.com_index.json", expected: "package_drazzy.com_index.json"},
166
+ }
167
+ for _, tc := range tests {
168
+ ir := IndexResource{URL: &url.URL{Path: tc.url}}
169
+ name, err := ir.IndexFileName()
170
+ require.NoError(t, err, fmt.Sprintf("error trying url: %v", tc))
171
+ require.Equal(t, tc.expected, name)
172
+ }
173
+ }
0 commit comments