@@ -24,7 +24,7 @@ func TestApplyResourcesWithCustomGeoipDir(t *testing.T) {
2424 elasticPackagePath := t .TempDir ()
2525 profilesPath := filepath .Join (elasticPackagePath , "profiles" )
2626
27- os .Setenv ("ELASTIC_PACKAGE_DATA_HOME" , elasticPackagePath )
27+ t .Setenv ("ELASTIC_PACKAGE_DATA_HOME" , elasticPackagePath )
2828
2929 // Create profile.
3030 err := profile .CreateProfile (profile.Options {
@@ -70,6 +70,82 @@ func TestApplyResourcesWithCustomGeoipDir(t *testing.T) {
7070 assert .Contains (t , volumes , expectedVolume )
7171}
7272
73+ func TestApplyResourcesWithDefaultPackageRegistryURL (t * testing.T ) {
74+ const profileName = "custom_package_registry"
75+ const expectedEPR = "https://epr.elastic.co"
76+
77+ elasticPackagePath := t .TempDir ()
78+ profilesPath := filepath .Join (elasticPackagePath , "profiles" )
79+
80+ t .Setenv ("ELASTIC_PACKAGE_DATA_HOME" , elasticPackagePath )
81+
82+ // Create profile.
83+ err := profile .CreateProfile (profile.Options {
84+ ProfilesDirPath : profilesPath ,
85+ Name : profileName ,
86+ })
87+ require .NoError (t , err )
88+
89+ p , err := profile .LoadProfile (profileName )
90+ require .NoError (t , err )
91+ t .Logf ("Profile name: %s, path: %s" , p .ProfileName , p .ProfilePath )
92+
93+ // Ensure that the profile has no specific configuration for EPR proxy.
94+ v := p .Config (configElasticEPRProxyTo , "" )
95+ require .Equal (t , "" , v )
96+
97+ // Now, apply resources and check that the variable has been used.
98+ stackVersion := "8.6.1"
99+ err = applyResources (p , stackVersion , stackVersion )
100+ require .NoError (t , err )
101+
102+ d , err := os .ReadFile (p .Path (ProfileStackPath , DockerfilePackageRegistryFile ))
103+ require .NoError (t , err )
104+
105+ assert .Contains (t , string (d ), fmt .Sprintf ("ENV EPR_PROXY_TO=%s" , expectedEPR ))
106+ }
107+
108+ func TestApplyResourcesWithCustomPackageRegistryURL (t * testing.T ) {
109+ const profileName = "custom_package_registry"
110+ const expectedEPR = "http://localhost"
111+
112+ elasticPackagePath := t .TempDir ()
113+ profilesPath := filepath .Join (elasticPackagePath , "profiles" )
114+
115+ t .Setenv ("ELASTIC_PACKAGE_DATA_HOME" , elasticPackagePath )
116+
117+ // Create profile.
118+ err := profile .CreateProfile (profile.Options {
119+ ProfilesDirPath : profilesPath ,
120+ Name : profileName ,
121+ })
122+ require .NoError (t , err )
123+
124+ // Write configuration to the profile.
125+ configPath := filepath .Join (profilesPath , profileName , profile .PackageProfileConfigFile )
126+ config := fmt .Sprintf ("%s: %q" , configElasticEPRProxyTo , expectedEPR )
127+ err = os .WriteFile (configPath , []byte (config ), 0644 )
128+ require .NoError (t , err )
129+
130+ p , err := profile .LoadProfile (profileName )
131+ require .NoError (t , err )
132+ t .Logf ("Profile name: %s, path: %s" , p .ProfileName , p .ProfilePath )
133+
134+ // Smoke test to check that we are actually loading the profile we want and it has the setting.
135+ v := p .Config (configElasticEPRProxyTo , "" )
136+ require .Equal (t , expectedEPR , v )
137+
138+ // Now, apply resources and check that the variable has been used.
139+ stackVersion := "8.6.1"
140+ err = applyResources (p , stackVersion , stackVersion )
141+ require .NoError (t , err )
142+
143+ d , err := os .ReadFile (p .Path (ProfileStackPath , DockerfilePackageRegistryFile ))
144+ require .NoError (t , err )
145+
146+ assert .Contains (t , string (d ), fmt .Sprintf ("ENV EPR_PROXY_TO=%s" , expectedEPR ))
147+ }
148+
73149func TestSemverLessThan (t * testing.T ) {
74150 b , err := semverLessThan ("8.9.0" , "8.10.0-SNAPSHOT" )
75151 require .NoError (t , err )
0 commit comments