@@ -28,9 +28,9 @@ import (
2828)
2929
3030func TestGetRegistry (t * testing.T ) {
31- assert .Equal (t , "registry-1.docker.io" , getRegistry ("alpine" ))
32- assert .Equal (t , "registry-1.docker.io" , getRegistry ("library/alpine" ))
33- assert .Equal (t , "registry-1.docker.io" , getRegistry ("docker.io/library/alpine" ))
31+ assert .Equal (t , DockerHubRegistry , getRegistry ("alpine" ))
32+ assert .Equal (t , DockerHubRegistry , getRegistry ("library/alpine" ))
33+ assert .Equal (t , DockerHubRegistry , getRegistry ("docker.io/library/alpine" ))
3434 assert .Equal (t , "ghcr.io" , getRegistry ("ghcr.io/library/alpine" ))
3535}
3636
@@ -58,43 +58,51 @@ func TestDetectAuthURL(t *testing.T) {
5858}
5959
6060func TestDownload (t * testing.T ) {
61- d := NewStoreDownloader ()
6261 server := mock .NewInMemoryServer (0 )
63-
6462 err := server .Start (mock .NewLocalFileReader ("testdata/registry.yaml" ), "/v2" )
6563 assert .NoError (t , err )
6664 defer func () {
6765 server .Stop ()
6866 }()
6967
70- d .WithRegistry (fmt .Sprintf ("127.0.0.1:%s" , server .GetPort ()))
71- d .WithInsecure (true )
72- d .WithBasicAuth ("" , "" )
73- d .WithRoundTripper (nil )
74-
75- var reader io.Reader
76- reader , err = d .Download ("git" , "" , "" )
77- assert .NoError (t , err )
78- assert .NotNil (t , reader )
79-
80- // download and verify it
81- var tmpDownloadDir string
82- tmpDownloadDir , err = os .MkdirTemp (os .TempDir (), "download" )
83- defer os .RemoveAll (tmpDownloadDir )
84- assert .NoError (t , err )
85-
86- err = WriteTo (reader , tmpDownloadDir , "fake.txt" )
87- assert .NoError (t , err )
88-
89- var data []byte
90- data , err = os .ReadFile (filepath .Join (tmpDownloadDir , "fake.txt" ))
91- assert .NoError (t , err )
92- assert .Equal (t , "fake" , string (data ))
93-
94- assert .NotEmpty (t , d .GetTargetFile ())
95-
96- t .Run ("not found" , func (t * testing.T ) {
97- _ , err = d .Download ("orm" , "" , "" )
98- assert .Error (t , err )
99- })
68+ platforms := []string {
69+ "windows" , "linux" , "darwin" ,
70+ }
71+ for _ , platform := range platforms {
72+ t .Run (fmt .Sprintf ("on %s" , platform ), func (t * testing.T ) {
73+ d := NewStoreDownloader ()
74+ d .WithRegistry (fmt .Sprintf ("127.0.0.1:%s" , server .GetPort ()))
75+ d .WithInsecure (true )
76+ d .WithOS (platform )
77+ d .WithArch ("amd64" )
78+ d .WithBasicAuth ("" , "" )
79+ d .WithRoundTripper (nil )
80+
81+ var reader io.Reader
82+ reader , err = d .Download ("git" , "" , "" )
83+ assert .NoError (t , err )
84+ assert .NotNil (t , reader )
85+
86+ // download and verify it
87+ var tmpDownloadDir string
88+ tmpDownloadDir , err = os .MkdirTemp (os .TempDir (), "download" )
89+ defer os .RemoveAll (tmpDownloadDir )
90+ assert .NoError (t , err )
91+
92+ err = WriteTo (reader , tmpDownloadDir , "fake.txt" )
93+ assert .NoError (t , err )
94+
95+ var data []byte
96+ data , err = os .ReadFile (filepath .Join (tmpDownloadDir , "fake.txt" ))
97+ assert .NoError (t , err )
98+ assert .Equal (t , "fake" , string (data ))
99+
100+ assert .NotEmpty (t , d .GetTargetFile ())
101+
102+ t .Run ("not found" , func (t * testing.T ) {
103+ _ , err = d .Download ("orm" , "" , "" )
104+ assert .Error (t , err )
105+ })
106+ })
107+ }
100108}
0 commit comments