diff --git a/settings/settings.go b/settings/settings.go index e7d9d5a..75d188e 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -116,16 +116,20 @@ func readConf(filename string) { } if gc.CacheLife != "" { - CacheLife, err = time.ParseDuration(gc.CacheLife) + cl, err := time.ParseDuration(gc.CacheLife) if err != nil { logger.Error(err) + } else { + CacheLife = cl } } if gc.LockFileMaxAge != "" { - LockFileMaxAge, err = time.ParseDuration(gc.LockFileMaxAge) + lfma, err := time.ParseDuration(gc.LockFileMaxAge) if err != nil { logger.Error(err) + } else { + LockFileMaxAge = lfma } } diff --git a/settings/settings_test.go b/settings/settings_test.go index fb41ddc..9942131 100644 --- a/settings/settings_test.go +++ b/settings/settings_test.go @@ -16,7 +16,7 @@ func TestInitialize(t *testing.T) { if err != nil { t.Fatalf("error creating conf file: %v", err) } - content := []byte("archs: [noarch, x86_64, arm64]\ncachelife: 10m\nlockfilemaxage: 1h\nallowunsafeurl: true") + content := []byte("archs: [noarch, x86_64, arm64]\ncachelife: 10m\nlockfilemaxage: 1x\nallowunsafeurl: true") if _, err := f.Write(content); err != nil { t.Fatalf("error writing conf file: %v", err) } @@ -30,20 +30,31 @@ func TestInitialize(t *testing.T) { t.Errorf("settings.Confirm got: %v, want: %v", got, want) } - wantArches := []string{"noarch", "x86_64", "arm64"} - if diff := cmp.Diff(wantArches, settings.Archs); diff != "" { - t.Errorf("settings.Archs unexpected diff (-want +got):\n%v", diff) - } - - if got, want := settings.CacheLife, 10*time.Minute; got != want { - t.Errorf("settings.CacheLife got: %v, want: %v", got, want) - } - - if got, want := settings.LockFileMaxAge, 1*time.Hour; got != want { - t.Errorf("settings.LockfileMaxAge got: %v, want: %v", got, want) - } - - if got, want := settings.AllowUnsafeURL, true; got != want { - t.Errorf("settings.AllowUnsafeURL got: %v, want: %v", got, want) - } + t.Run("Parsing Architectures", func(t *testing.T) { + wantArches := []string{"noarch", "x86_64", "arm64"} + if diff := cmp.Diff(wantArches, settings.Archs); diff != "" { + t.Errorf("settings.Archs unexpected diff (-want +got):\n%v", diff) + } + }) + + t.Run("Parsing CacheLife", func(t *testing.T) { + wantCacheLife := 10 * time.Minute + if got := settings.CacheLife; got != wantCacheLife { + t.Errorf("settings.CacheLife got: %v, want: %v", got, wantCacheLife) + } + }) + + t.Run("Parsing LockFileMaxAge", func(t *testing.T) { + wantLockFileMaxAge := 24 * time.Hour + if got := settings.LockFileMaxAge; got != wantLockFileMaxAge { + t.Errorf("settings.LockFileMaxAge got: %v, want: %v", got, wantLockFileMaxAge) + } + }) + + t.Run("Parsing AllowUnsafeURL", func(t *testing.T) { + wantAllowUnsafeURL := true + if got := settings.AllowUnsafeURL; got != wantAllowUnsafeURL { + t.Errorf("settings.AllowUnsafeURL got: %v, want: %v", got, wantAllowUnsafeURL) + } + }) }