-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add network specific error message to avoid confusion (#2367)
Closes #2338
- Loading branch information
1 parent
f006556
commit 56d71e6
Showing
2 changed files
with
50 additions
and
0 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,42 @@ | ||
package driver | ||
|
||
import ( | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/ory/hydra/driver/config" | ||
"github.com/ory/x/configx" | ||
"github.com/ory/x/logrusx" | ||
"github.com/sirupsen/logrus" | ||
"github.com/sirupsen/logrus/hooks/test" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRegistryBase_newKeyStrategy_handlesNetworkError(t *testing.T) { | ||
// Test ensures any network specific error is logged with a | ||
// specific message when attempting to create a new key strategy: issue #2338 | ||
|
||
hook := test.Hook{} // Test hook for asserting log messages | ||
|
||
l := logrusx.New("", "", logrusx.WithHook(&hook)) | ||
l.Logrus().SetOutput(ioutil.Discard) | ||
l.Logrus().ExitFunc = func(int) {} // Override the exit func to avoid call to os.Exit | ||
|
||
// Create a config and set a valid but unresolvable DSN | ||
c := config.MustNew(l, configx.WithConfigFiles("../internal/.hydra.yaml")) | ||
c.MustSet(config.KeyDSN, "postgres://user:password@127.0.0.1:9999/postgres") | ||
|
||
registry, err := NewRegistryFromDSN(c, l) | ||
if err != nil { | ||
t.Error("failed to create registry: ", err) | ||
return | ||
} | ||
|
||
registryBase := RegistryBase{r: registry, l: l} | ||
|
||
strategy := registryBase.newKeyStrategy("key") | ||
|
||
assert.Equal(t, nil, strategy) | ||
assert.Equal(t, logrus.FatalLevel, hook.LastEntry().Level) | ||
assert.Contains(t, hook.LastEntry().Message, "A network error occurred, see error for specific details.") | ||
} |