-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from sudo-bmitch/pr-conf-defaults
Consolidate setting config default values
- Loading branch information
Showing
8 changed files
with
141 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package config | ||
|
||
import "testing" | ||
|
||
func TestSetDefaults(t *testing.T) { | ||
c := Config{Storage: ConfigStorage{StoreType: StoreDir}} | ||
c.SetDefaults() | ||
if c.API.DeleteEnabled == nil || c.API.PushEnabled == nil || c.API.Blob.DeleteEnabled == nil || | ||
c.API.Referrer.Enabled == nil { | ||
t.Errorf("bool default values should not be nil") | ||
} | ||
if c.API.Manifest.Limit == 0 { | ||
t.Errorf("manifest limit should not be zero") | ||
} | ||
if c.Storage.RootDir == "" { | ||
t.Errorf("rootDir should not be empty for StoreDir") | ||
} | ||
} | ||
|
||
func TestStoreMarshal(t *testing.T) { | ||
tt := []struct { | ||
val Store | ||
str string | ||
expErr bool | ||
}{ | ||
{ | ||
val: StoreDir, | ||
str: "dir", | ||
}, | ||
{ | ||
val: StoreMem, | ||
str: "mem", | ||
}, | ||
{ | ||
val: StoreUndef, | ||
str: "unknown", | ||
expErr: true, | ||
}, | ||
} | ||
for _, tc := range tt { | ||
t.Run(tc.str, func(t *testing.T) { | ||
t.Run("marshal", func(t *testing.T) { | ||
result, err := tc.val.MarshalText() | ||
if tc.expErr { | ||
if err == nil { | ||
t.Errorf("marshal did not fail") | ||
} | ||
return | ||
} | ||
if err != nil { | ||
t.Errorf("failed to marshal: %v", err) | ||
return | ||
} | ||
if string(result) != tc.str { | ||
t.Errorf("expected %s, received %s", tc.str, string(result)) | ||
} | ||
}) | ||
t.Run("unmarshal", func(t *testing.T) { | ||
var s Store | ||
err := s.UnmarshalText([]byte(tc.str)) | ||
if tc.expErr { | ||
if err == nil { | ||
t.Errorf("unmarshal did not fail") | ||
} | ||
return | ||
} | ||
if err != nil { | ||
t.Errorf("failed to unmarshal: %v", err) | ||
} | ||
if tc.val != s { | ||
t.Errorf("expected %d, received %d", tc.val, s) | ||
} | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters