11package config
22
33import (
4+ "os"
5+ "path/filepath"
46 "strings"
57 "testing"
68 "time"
@@ -30,7 +32,7 @@ func TestConfig_SidecarPath(t *testing.T) {
3032 c .options .SidecarPath = ".photoprism"
3133 assert .Equal (t , ".photoprism" , c .SidecarPath ())
3234 c .options .SidecarPath = ""
33- assert .Equal (t , "/go/src/github.com/photoprism/photoprism /storage/testdata/sidecar" , c .SidecarPath ())
35+ assert .Equal (t , ProjectRoot + " /storage/testdata/sidecar" , c .SidecarPath ())
3436}
3537
3638func TestConfig_SidecarYaml (t * testing.T ) {
@@ -135,7 +137,7 @@ func TestConfig_TempPath(t *testing.T) {
135137 t .Logf ("c.options.TempPath: '%s'" , c .options .TempPath )
136138 t .Logf ("c.tempPath(): '%s'" , d0 )
137139
138- assert .Equal (t , "/go/src/github.com/photoprism/photoprism /storage/testdata/temp" , c .tempPath ())
140+ assert .Equal (t , ProjectRoot + " /storage/testdata/temp" , c .tempPath ())
139141
140142 c .options .TempPath = ""
141143
@@ -192,22 +194,60 @@ func TestConfig_CmdLibPath(t *testing.T) {
192194
193195func TestConfig_CachePath2 (t * testing.T ) {
194196 c := NewConfig (CliTestContext ())
195- assert .Equal (t , "/go/src/github.com/photoprism/photoprism /storage/testdata/cache" , c .CachePath ())
197+ assert .Equal (t , ProjectRoot + " /storage/testdata/cache" , c .CachePath ())
196198 c .options .CachePath = ""
197- assert .Equal (t , "/go/src/github.com/photoprism/photoprism/storage/testdata/cache" , c .CachePath ())
199+ assert .Equal (t , ProjectRoot + "/storage/testdata/cache" , c .CachePath ())
200+ }
201+
202+ func TestConfig_SettingsYaml (t * testing.T ) {
203+ t .Run ("Default" , func (t * testing.T ) {
204+ c := NewConfig (CliTestContext ())
205+ assert .Contains (t , c .SettingsYaml (), "settings.yml" )
206+ })
207+ t .Run ("PreferYamlExtension" , func (t * testing.T ) {
208+ c := NewConfig (CliTestContext ())
209+ tempDir := t .TempDir ()
210+ c .options .ConfigPath = tempDir
211+
212+ yamlPath := filepath .Join (tempDir , "settings" + fs .ExtYaml )
213+ if err := os .WriteFile (yamlPath , []byte ("ui:\n " ), fs .ModeFile ); err != nil {
214+ t .Fatalf ("write %s: %v" , yamlPath , err )
215+ }
216+
217+ assert .Equal (t , yamlPath , c .SettingsYaml ())
218+ })
219+ }
220+
221+ func TestConfig_HubConfigFile (t * testing.T ) {
222+ t .Run ("Default" , func (t * testing.T ) {
223+ c := NewConfig (CliTestContext ())
224+ assert .Contains (t , c .HubConfigFile (), "hub.yml" )
225+ })
226+ t .Run ("PreferYamlExtension" , func (t * testing.T ) {
227+ c := NewConfig (CliTestContext ())
228+ tempDir := t .TempDir ()
229+ c .options .ConfigPath = tempDir
230+
231+ yamlPath := filepath .Join (tempDir , "hub" + fs .ExtYaml )
232+ if err := os .WriteFile (yamlPath , []byte ("host: example\n " ), fs .ModeFile ); err != nil {
233+ t .Fatalf ("write %s: %v" , yamlPath , err )
234+ }
235+
236+ assert .Equal (t , yamlPath , c .HubConfigFile ())
237+ })
198238}
199239
200240func TestConfig_StoragePath (t * testing.T ) {
201241 c := NewConfig (CliTestContext ())
202- assert .Equal (t , "/go/src/github.com/photoprism/photoprism /storage/testdata" , c .StoragePath ())
242+ assert .Equal (t , ProjectRoot + " /storage/testdata" , c .StoragePath ())
203243 c .options .StoragePath = ""
204- assert .Equal (t , "/go/src/github.com/photoprism/photoprism /storage/testdata/originals/.photoprism/storage" , c .StoragePath ())
244+ assert .Equal (t , ProjectRoot + " /storage/testdata/originals/.photoprism/storage" , c .StoragePath ())
205245}
206246
207247func TestConfig_TestdataPath (t * testing.T ) {
208248 c := NewConfig (CliTestContext ())
209249
210- assert .Equal (t , "/go/src/github.com/photoprism/photoprism /storage/testdata/testdata" , c .TestdataPath ())
250+ assert .Equal (t , ProjectRoot + " /storage/testdata/testdata" , c .TestdataPath ())
211251}
212252
213253func TestConfig_AlbumsPath (t * testing.T ) {
@@ -218,13 +258,13 @@ func TestConfig_AlbumsPath(t *testing.T) {
218258 // If this test fails, please manually move “albums” to the “backup” folder
219259 // in the “storage/testdata” directory within your development environment:
220260 // https://github.com/photoprism/photoprism/discussions/4520
221- assert .Equal (t , "/go/src/github.com/photoprism/photoprism /storage/testdata/backup/albums" , c .BackupAlbumsPath ())
261+ assert .Equal (t , ProjectRoot + " /storage/testdata/backup/albums" , c .BackupAlbumsPath ())
222262}
223263
224264func TestConfig_OriginalsAlbumsPath (t * testing.T ) {
225265 c := NewConfig (CliTestContext ())
226266
227- assert .Equal (t , "/go/src/github.com/photoprism/photoprism /storage/testdata/originals/albums" , c .OriginalsAlbumsPath ())
267+ assert .Equal (t , ProjectRoot + " /storage/testdata/originals/albums" , c .OriginalsAlbumsPath ())
228268}
229269
230270func TestConfig_CreateDirectories (t * testing.T ) {
@@ -419,21 +459,21 @@ func TestConfig_CreateDirectories2(t *testing.T) {
419459
420460func TestConfig_PIDFilename2 (t * testing.T ) {
421461 c := NewConfig (CliTestContext ())
422- assert .Equal (t , "/go/src/github.com/photoprism/photoprism /storage/testdata/photoprism.pid" , c .PIDFilename ())
423- c .options .PIDFilename = "/go/src/github.com/photoprism/photoprism /internal/config/testdata/test.pid"
424- assert .Equal (t , "/go/src/github.com/photoprism/photoprism /internal/config/testdata/test.pid" , c .PIDFilename ())
462+ assert .Equal (t , ProjectRoot + " /storage/testdata/photoprism.pid" , c .PIDFilename ())
463+ c .options .PIDFilename = ProjectRoot + " /internal/config/testdata/test.pid"
464+ assert .Equal (t , ProjectRoot + " /internal/config/testdata/test.pid" , c .PIDFilename ())
425465}
426466
427467func TestConfig_LogFilename2 (t * testing.T ) {
428468 c := NewConfig (CliTestContext ())
429- assert .Equal (t , "/go/src/github.com/photoprism/photoprism /storage/testdata/photoprism.log" , c .LogFilename ())
430- c .options .LogFilename = "/go/src/github.com/photoprism/photoprism /internal/config/testdata/test.log"
431- assert .Equal (t , "/go/src/github.com/photoprism/photoprism /internal/config/testdata/test.log" , c .LogFilename ())
469+ assert .Equal (t , ProjectRoot + " /storage/testdata/photoprism.log" , c .LogFilename ())
470+ c .options .LogFilename = ProjectRoot + " /internal/config/testdata/test.log"
471+ assert .Equal (t , ProjectRoot + " /internal/config/testdata/test.log" , c .LogFilename ())
432472}
433473
434474func TestConfig_OriginalsPath2 (t * testing.T ) {
435475 c := NewConfig (CliTestContext ())
436- assert .Equal (t , "/go/src/github.com/photoprism/photoprism /storage/testdata/originals" , c .OriginalsPath ())
476+ assert .Equal (t , ProjectRoot + " /storage/testdata/originals" , c .OriginalsPath ())
437477 c .options .OriginalsPath = ""
438478 if s := c .OriginalsPath (); s != "" && s != "/photoprism/originals" {
439479 t .Errorf ("unexpected originals path: %s" , s )
@@ -467,7 +507,7 @@ func TestConfig_AssetsPath(t *testing.T) {
467507 c := NewConfig (CliTestContext ())
468508
469509 assert .True (t , strings .HasSuffix (c .AssetsPath (), "/assets" ))
470- assert .Equal (t , "/go/src/github.com/photoprism/photoprism /assets" , c .AssetsPath ())
510+ assert .Equal (t , ProjectRoot + " /assets" , c .AssetsPath ())
471511 c .options .AssetsPath = ""
472512 if s := c .AssetsPath (); s != "" && s != "/opt/photoprism/assets" {
473513 t .Errorf ("unexpected assets path: %s" , s )
0 commit comments