Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
45 changes: 28 additions & 17 deletions settings/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
})
}
Loading