allow missing urns and fingers files, if default
Some checks failed
Go / checks (push) Failing after 46s

This commit is contained in:
Gustavo Maronato 2023-09-20 01:40:57 -03:00
parent 8ad2fd2fd6
commit c16b039d3f
Signed by: maronato
SSH Key Fingerprint: SHA256:2Gw7kwMz/As+2UkR1qQ/qYYhn+WNh3FGv6ozhoRrLcs
4 changed files with 27 additions and 16 deletions

View File

@ -15,7 +15,7 @@ const (
// DefaultURNPath is the default file path to the URN alias file.
DefaultURNPath = "urns.yml"
// DefaultFingerPath is the default file path to the webfinger definition file.
DefaultFingerPath = "finger.yml"
DefaultFingerPath = "fingers.yml"
)
// ErrInvalidConfig is returned when the config is invalid.

View File

@ -59,14 +59,14 @@ func TestConfig_Validate(t *testing.T) {
name: "empty host",
cfg: &config.Config{
Host: "",
Port: "1234",
Port: config.DefaultPort,
},
wantErr: true,
},
{
name: "empty port",
cfg: &config.Config{
Host: "example.com",
Host: config.DefaultHost,
Port: "",
},
wantErr: true,
@ -74,7 +74,7 @@ func TestConfig_Validate(t *testing.T) {
{
name: "invalid addr",
cfg: &config.Config{
Host: "example.com",
Host: config.DefaultHost,
Port: "invalid",
},
wantErr: true,
@ -82,8 +82,8 @@ func TestConfig_Validate(t *testing.T) {
{
name: "empty urn path",
cfg: &config.Config{
Host: "example.com",
Port: "1234",
Host: config.DefaultHost,
Port: config.DefaultPort,
URNPath: "",
},
wantErr: true,
@ -91,9 +91,9 @@ func TestConfig_Validate(t *testing.T) {
{
name: "empty finger path",
cfg: &config.Config{
Host: "example.com",
Port: "1234",
URNPath: "urns.yml",
Host: config.DefaultHost,
Port: config.DefaultPort,
URNPath: config.DefaultURNPath,
FingerPath: "",
},
wantErr: true,
@ -101,10 +101,10 @@ func TestConfig_Validate(t *testing.T) {
{
name: "valid",
cfg: &config.Config{
Host: "example.com",
Port: "1234",
URNPath: "urns.yml",
FingerPath: "finger.yml",
Host: config.DefaultHost,
Port: config.DefaultPort,
URNPath: config.DefaultURNPath,
FingerPath: config.DefaultFingerPath,
},
wantErr: false,
},

View File

@ -60,7 +60,7 @@ func TestStartServer(t *testing.T) {
t.Run("fails to start", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*100)
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*200)
defer cancel()
cfg := config.NewConfig()

View File

@ -42,9 +42,15 @@ func NewFingerReader() *FingerReader {
func (f *FingerReader) ReadFiles(cfg *config.Config) error {
// Read URNs file
file, err := os.ReadFile(cfg.URNPath)
if err != nil {
return fmt.Errorf("error opening URNs file: %w", err)
// If the file does not exist and the path is the default, set the URNs to an empty map
if os.IsNotExist(err) && cfg.URNPath == config.DefaultURNPath {
f.URNSFile = []byte("")
} else {
return fmt.Errorf("error opening URNs file: %w", err)
}
}
f.URNSFile = file
@ -52,7 +58,12 @@ func (f *FingerReader) ReadFiles(cfg *config.Config) error {
// Read fingers file
file, err = os.ReadFile(cfg.FingerPath)
if err != nil {
return fmt.Errorf("error opening fingers file: %w", err)
// If the file does not exist and the path is the default, set the fingers to an empty map
if os.IsNotExist(err) && cfg.FingerPath == config.DefaultFingerPath {
f.FingersFile = []byte("")
} else {
return fmt.Errorf("error opening fingers file: %w", err)
}
}
f.FingersFile = file