@@ -14,11 +14,14 @@ type ConfigSuite struct {
1414var _ = Suite (& ConfigSuite {})
1515
1616func (s * ConfigSuite ) TestLoadConfig (c * C ) {
17- configname := filepath .Join (c .MkDir (), "aptly.json " )
17+ configname := filepath .Join (c .MkDir (), "aptly.json1 " )
1818 f , _ := os .Create (configname )
1919 f .WriteString (configFile )
2020 f .Close ()
2121
22+ // start with empty config
23+ s .config = ConfigStructure {}
24+
2225 err := LoadConfig (configname , & s .config )
2326 c .Assert (err , IsNil )
2427 c .Check (s .config .GetRootDir (), Equals , "/opt/aptly/" )
@@ -27,7 +30,10 @@ func (s *ConfigSuite) TestLoadConfig(c *C) {
2730}
2831
2932func (s * ConfigSuite ) TestSaveConfig (c * C ) {
30- configname := filepath .Join (c .MkDir (), "aptly.json" )
33+ configname := filepath .Join (c .MkDir (), "aptly.json2" )
34+
35+ // start with empty config
36+ s .config = ConfigStructure {}
3137
3238 s .config .RootDir = "/tmp/aptly"
3339 s .config .DownloadConcurrency = 5
@@ -153,4 +159,128 @@ func (s *ConfigSuite) TestSaveConfig(c *C) {
153159 "}" )
154160}
155161
162+ func (s * ConfigSuite ) TestLoadYAMLConfig (c * C ) {
163+ configname := filepath .Join (c .MkDir (), "aptly.yaml1" )
164+ f , _ := os .Create (configname )
165+ f .WriteString (configFileYAML )
166+ f .Close ()
167+
168+ // start with empty config
169+ s .config = ConfigStructure {}
170+
171+ err := LoadConfig (configname , & s .config )
172+ c .Assert (err , IsNil )
173+ c .Check (s .config .GetRootDir (), Equals , "/opt/aptly/" )
174+ c .Check (s .config .DownloadConcurrency , Equals , 40 )
175+ c .Check (s .config .DatabaseOpenAttempts , Equals , 10 )
176+ }
177+
178+ func (s * ConfigSuite ) TestSaveYAMLConfig (c * C ) {
179+ configname := filepath .Join (c .MkDir (), "aptly.yaml2" )
180+ f , _ := os .Create (configname )
181+ f .WriteString (configFileYAML )
182+ f .Close ()
183+
184+ // start with empty config
185+ s .config = ConfigStructure {}
186+
187+ err := LoadConfig (configname , & s .config )
188+ c .Assert (err , IsNil )
189+
190+ err = SaveConfigYAML (configname , & s .config )
191+ c .Assert (err , IsNil )
192+
193+ f , _ = os .Open (configname )
194+ defer f .Close ()
195+
196+ st , _ := f .Stat ()
197+ buf := make ([]byte , st .Size ())
198+ f .Read (buf )
199+
200+ c .Check (string (buf ), Equals , configFileYAML )
201+ }
202+
156203const configFile = `{"rootDir": "/opt/aptly/", "downloadConcurrency": 33, "databaseOpenAttempts": 33}`
204+ const configFileYAML = `root_dir: /opt/aptly/
205+ log_level: error
206+ log_format: json
207+ database_open_attempts: 10
208+ architectures:
209+ - amd64
210+ - arm64
211+ skip_legacy_pool: true
212+ dep_follow_suggests: false
213+ dep_follow_recommends: true
214+ dep_follow_all_variants: false
215+ dep_follow_source: true
216+ dep_verboseresolve: false
217+ ppa_distributor_id: Ubuntu
218+ ppa_codename: short
219+ serve_in_api_mode: true
220+ enable_metrics_endpoint: false
221+ enable_swagger_endpoint: true
222+ async_api: false
223+ database_backend:
224+ type: etcd
225+ db_path: ""
226+ url: 127.0.0.1:2379
227+ downloader: grab
228+ download_concurrency: 40
229+ download_limit: 100
230+ download_retries: 10
231+ download_sourcepackages: true
232+ gpg_provider: gpg
233+ gpg_disable_sign: true
234+ gpg_disable_verify: false
235+ skip_contents_publishing: true
236+ skip_bz2_publishing: false
237+ filesystem_publish_endpoints:
238+ test1:
239+ root_dir: /opt/srv/aptly_public
240+ link_method: hardlink
241+ verify_method: md5
242+ s3_publish_endpoints:
243+ test:
244+ region: us-east-1
245+ bucket: test-bucket
246+ prefix: ""
247+ acl: public-read
248+ access_key_id: "2"
249+ secret_access_key: secret
250+ session_token: none
251+ endpoint: endpoint
252+ storage_class: STANDARD
253+ encryption_method: AES256
254+ plus_workaround: true
255+ disable_multidel: false
256+ force_sigv2: true
257+ force_virtualhosted_style: false
258+ debug: true
259+ swift_publish_endpoints:
260+ test:
261+ container: c1
262+ prefix: pre
263+ username: user
264+ password: pass
265+ tenant: t
266+ tenant_id: "2"
267+ domain: pop
268+ domain_id: "1"
269+ tenant_domain: td
270+ tenant_domain_id: "3"
271+ auth_url: http://auth.url
272+ azure_publish_endpoints:
273+ test:
274+ container: container1
275+ prefix: pre2
276+ account_name: aname
277+ account_key: akey
278+ endpoint: https://end.point
279+ packagepool_storage:
280+ type: azure
281+ container: test-pool1
282+ prefix: pre3
283+ account_name: a name
284+ account_key: a key
285+ endpoint: ""
286+ `
0 commit comments