@@ -10,6 +10,7 @@ import (
1010 "runtime"
1111 "strings"
1212 "testing"
13+ "time"
1314
1415 "github.com/opencontainers/go-digest"
1516 "gotest.tools/v3/assert"
@@ -25,6 +26,8 @@ func TestDownloadRemote(t *testing.T) {
2526 t .Cleanup (ts .Close )
2627 dummyRemoteFileURL := ts .URL + "/downloader.txt"
2728 const dummyRemoteFileDigest = "sha256:380481d26f897403368be7cb86ca03a4bc14b125bfaf2b93bff809a5a2ad717e"
29+ dummyRemoteFileStat , err := os .Stat (filepath .Join ("testdata" , "downloader.txt" ))
30+ assert .NilError (t , err )
2831
2932 t .Run ("without cache" , func (t * testing.T ) {
3033 t .Run ("without digest" , func (t * testing.T ) {
@@ -105,6 +108,17 @@ func TestDownloadRemote(t *testing.T) {
105108 _ , err = Cached (dummyRemoteFileURL , WithExpectedDigest (wrongDigest ), WithCacheDir (cacheDir ))
106109 assert .ErrorContains (t , err , "expected digest" )
107110 })
111+ t .Run ("metadata" , func (t * testing.T ) {
112+ _ , err := Cached (dummyRemoteFileURL , WithExpectedDigest (dummyRemoteFileDigest ))
113+ assert .ErrorContains (t , err , "cache directory to be specified" )
114+
115+ cacheDir := filepath .Join (t .TempDir (), "cache" )
116+ r , err := Download (context .Background (), "" , dummyRemoteFileURL , WithExpectedDigest (dummyRemoteFileDigest ), WithCacheDir (cacheDir ))
117+ assert .NilError (t , err )
118+ assert .Equal (t , StatusDownloaded , r .Status )
119+ assert .Equal (t , dummyRemoteFileStat .ModTime ().UTC ().Format (time .RFC1123 ), strings .Replace (r .LastModified , "GMT" , "UTC" , 1 ))
120+ assert .Equal (t , "text/plain; charset=utf-8" , r .ContentType )
121+ })
108122}
109123
110124func TestDownloadLocal (t * testing.T ) {
0 commit comments