44package downloadsources_test
55
66import (
7- "errors"
87 "testing"
98
109 "github.com/microsoft/azure-linux-dev-tools/internal/app/azldev"
@@ -22,6 +21,8 @@ import (
2221
2322const testLookasideURI = "https://example.com/lookaside/$pkg/$filename/$hashtype/$hash/$filename"
2423
24+ const testPkgDir = "/project/curl"
25+
2526func TestOnAppInit (t * testing.T ) {
2627 ctrl := gomock .NewController (t )
2728 app := azldev .NewApp (opctx_test .NewMockFileSystemFactory (ctrl ), opctx_test .NewMockOSEnvFactory (ctrl ))
@@ -63,64 +64,56 @@ func TestDownloadSources_StandaloneMode(t *testing.T) {
6364 testEnv := testutils .NewTestEnv (t )
6465 ctrl := gomock .NewController (t )
6566
66- pkgDir := "/project/curl"
67- require .NoError (t , fileutils .MkdirAll (testEnv .TestFS , pkgDir ))
68- require .NoError (t , fileutils .WriteFile (testEnv .TestFS , pkgDir + "/sources" , []byte ("" ), fileperms .PrivateFile ))
67+ require . NoError ( t , fileutils . MkdirAll ( testEnv . TestFS , testPkgDir ))
68+ require .NoError (t , fileutils .WriteFile (testEnv .TestFS , testPkgDir + "/curl.spec" , [] byte ( "" ), fileperms . PrivateFile ))
69+ require .NoError (t , fileutils .WriteFile (testEnv .TestFS , testPkgDir + "/sources" , []byte ("" ), fileperms .PrivateFile ))
6970
7071 mockDownloader := fedorasource_test .NewMockFedoraSourceDownloader (ctrl )
7172 mockDownloader .EXPECT ().
72- ExtractSourcesFromRepo (gomock .Any (), pkgDir , "curl" , testLookasideURI , gomock .Any (), gomock .Any ()).
73+ ExtractSourcesFromRepo (gomock .Any (), testPkgDir , "curl" , testLookasideURI , gomock .Any (), gomock .Any ()).
7374 Return (nil )
7475
7576 options := & downloadsources.DownloadSourcesOptions {
76- Directory : pkgDir ,
77+ Directory : testPkgDir ,
7778 LookasideBaseURIs : []string {testLookasideURI },
7879 LookasideDownloader : mockDownloader ,
7980 }
8081
81- // Package name "curl" derived from directory basename .
82+ // Package name "curl" derived from curl.spec filename .
8283 err := downloadsources .DownloadSources (testEnv .Env , options )
8384 require .NoError (t , err )
8485}
8586
86- func TestDownloadSources_StandaloneMode_NonexistentDir (t * testing.T ) {
87+ func TestDownloadSources_StandaloneMode_NoSpecFile (t * testing.T ) {
8788 testEnv := testutils .NewTestEnv (t )
88- ctrl := gomock .NewController (t )
8989
90- mockDownloader := fedorasource_test .NewMockFedoraSourceDownloader (ctrl )
91- mockDownloader .EXPECT ().
92- ExtractSourcesFromRepo (
93- gomock .Any (), "/project/nonexistent" , "nonexistent" ,
94- testLookasideURI , gomock .Any (), gomock .Any (),
95- ).
96- Return (errors .New ("repository directory does not exist" ))
90+ require .NoError (t , fileutils .MkdirAll (testEnv .TestFS , testPkgDir ))
9791
9892 options := & downloadsources.DownloadSourcesOptions {
99- Directory : "/project/nonexistent" ,
100- LookasideBaseURIs : []string {testLookasideURI },
101- LookasideDownloader : mockDownloader ,
93+ Directory : testPkgDir ,
94+ LookasideBaseURIs : []string {testLookasideURI },
10295 }
10396
10497 err := downloadsources .DownloadSources (testEnv .Env , options )
10598 require .Error (t , err )
106- assert .Contains (t , err .Error (), "does not exist " )
99+ assert .Contains (t , err .Error (), "no .spec file found " )
107100}
108101
109102func TestDownloadSources_StandaloneMode_NoSourcesFile (t * testing.T ) {
110103 testEnv := testutils .NewTestEnv (t )
111104 ctrl := gomock .NewController (t )
112105
113- pkgDir := "/project/curl"
114- require .NoError (t , fileutils .MkdirAll (testEnv .TestFS , pkgDir ))
106+ require . NoError ( t , fileutils . MkdirAll ( testEnv . TestFS , testPkgDir ))
107+ require .NoError (t , fileutils .WriteFile (testEnv .TestFS , testPkgDir + "/curl.spec" , [] byte ( "" ), fileperms . PrivateFile ))
115108
116109 // ExtractSourcesFromRepo returns nil when no sources file exists.
117110 mockDownloader := fedorasource_test .NewMockFedoraSourceDownloader (ctrl )
118111 mockDownloader .EXPECT ().
119- ExtractSourcesFromRepo (gomock .Any (), pkgDir , "curl" , testLookasideURI , gomock .Any (), gomock .Any ()).
112+ ExtractSourcesFromRepo (gomock .Any (), testPkgDir , "curl" , testLookasideURI , gomock .Any (), gomock .Any ()).
120113 Return (nil )
121114
122115 options := & downloadsources.DownloadSourcesOptions {
123- Directory : pkgDir ,
116+ Directory : testPkgDir ,
124117 LookasideBaseURIs : []string {testLookasideURI },
125118 LookasideDownloader : mockDownloader ,
126119 }
0 commit comments