diff --git a/internal/config/config.go b/internal/config/config.go index 7a6755d..0056956 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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. diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 85e35fe..f962042 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -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, }, diff --git a/internal/server/server_test.go b/internal/server/server_test.go index a901137..db4b5bf 100644 --- a/internal/server/server_test.go +++ b/internal/server/server_test.go @@ -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() diff --git a/internal/webfinger/webfinger.go b/internal/webfinger/webfinger.go index 784aa5b..22f10f6 100644 --- a/internal/webfinger/webfinger.go +++ b/internal/webfinger/webfinger.go @@ -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