Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
189 additions
and
44 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,20 @@ | ||
package cleanup | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_ExecuteCommand(t *testing.T) { | ||
cmd := NewCleanupSQLCmd() | ||
b := bytes.NewBufferString("") | ||
cmd.SetOut(b) | ||
cmd.SetArgs([]string{"dsadsadsadsa"}) | ||
cmd.Execute() | ||
out, err := ioutil.ReadAll(b) | ||
require.NoError(t, err) | ||
require.Contains(t, string(out), "Successfully") | ||
} |
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
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,138 @@ | ||
package sql_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/ory/kratos/internal" | ||
) | ||
|
||
func TestPersister_Cleanup(t *testing.T) { | ||
_, reg := internal.NewFastRegistryWithMocks(t) | ||
p := reg.Persister() | ||
ctx := context.Background() | ||
|
||
t.Run("case=should not throw error on cleanup", func(t *testing.T) { | ||
assert.Nil(t, p.CleanupDatabase(ctx, 0, 0, reg.Config(context.Background()).DatabaseCleanupBatchSize())) | ||
}) | ||
|
||
t.Run("case=should throw error on cleanup", func(t *testing.T) { | ||
p.GetConnection(ctx).Close() | ||
assert.Error(t, p.CleanupDatabase(ctx, 0, 0, reg.Config(context.Background()).DatabaseCleanupBatchSize())) | ||
}) | ||
} | ||
|
||
func TestPersister_Continuity_Cleanup(t *testing.T) { | ||
_, reg := internal.NewFastRegistryWithMocks(t) | ||
p := reg.Persister() | ||
currentTime := time.Now() | ||
ctx := context.Background() | ||
|
||
t.Run("case=should not throw error on cleanup continuity sessions", func(t *testing.T) { | ||
assert.Nil(t, p.DeleteExpiredContinuitySessions(ctx, currentTime, reg.Config(context.Background()).DatabaseCleanupBatchSize())) | ||
}) | ||
|
||
t.Run("case=should throw error on cleanup continuity sessions", func(t *testing.T) { | ||
p.GetConnection(ctx).Close() | ||
assert.Error(t, p.DeleteExpiredContinuitySessions(ctx, currentTime, reg.Config(context.Background()).DatabaseCleanupBatchSize())) | ||
}) | ||
} | ||
|
||
func TestPersister_Login_Cleanup(t *testing.T) { | ||
_, reg := internal.NewFastRegistryWithMocks(t) | ||
p := reg.Persister() | ||
currentTime := time.Now() | ||
ctx := context.Background() | ||
|
||
t.Run("case=should not throw error on cleanup login flows", func(t *testing.T) { | ||
assert.Nil(t, p.DeleteExpiredLoginFlows(ctx, currentTime, reg.Config(context.Background()).DatabaseCleanupBatchSize())) | ||
}) | ||
|
||
t.Run("case=should throw error on cleanup login flows", func(t *testing.T) { | ||
p.GetConnection(ctx).Close() | ||
assert.Error(t, p.DeleteExpiredLoginFlows(ctx, currentTime, reg.Config(context.Background()).DatabaseCleanupBatchSize())) | ||
}) | ||
} | ||
|
||
func TestPersister_Recovery_Cleanup(t *testing.T) { | ||
_, reg := internal.NewFastRegistryWithMocks(t) | ||
p := reg.Persister() | ||
currentTime := time.Now() | ||
ctx := context.Background() | ||
|
||
t.Run("case=should not throw error on cleanup recovery flows", func(t *testing.T) { | ||
assert.Nil(t, p.DeleteExpiredRecoveryFlows(ctx, currentTime, reg.Config(context.Background()).DatabaseCleanupBatchSize())) | ||
}) | ||
|
||
t.Run("case=should throw error on cleanup recovery flows", func(t *testing.T) { | ||
p.GetConnection(ctx).Close() | ||
assert.Error(t, p.DeleteExpiredRecoveryFlows(ctx, currentTime, reg.Config(context.Background()).DatabaseCleanupBatchSize())) | ||
}) | ||
} | ||
|
||
func TestPersister_Registration_Cleanup(t *testing.T) { | ||
_, reg := internal.NewFastRegistryWithMocks(t) | ||
p := reg.Persister() | ||
currentTime := time.Now() | ||
ctx := context.Background() | ||
|
||
t.Run("case=should not throw error on cleanup registration flows", func(t *testing.T) { | ||
assert.Nil(t, p.DeleteExpiredRecoveryFlows(ctx, currentTime, reg.Config(context.Background()).DatabaseCleanupBatchSize())) | ||
}) | ||
|
||
t.Run("case=should throw error on cleanup registration flows", func(t *testing.T) { | ||
p.GetConnection(ctx).Close() | ||
assert.Error(t, p.DeleteExpiredRecoveryFlows(ctx, currentTime, reg.Config(context.Background()).DatabaseCleanupBatchSize())) | ||
}) | ||
} | ||
|
||
func TestPersister_Session_Cleanup(t *testing.T) { | ||
_, reg := internal.NewFastRegistryWithMocks(t) | ||
p := reg.Persister() | ||
currentTime := time.Now() | ||
ctx := context.Background() | ||
|
||
t.Run("case=should not throw error on cleanup sessions", func(t *testing.T) { | ||
assert.Nil(t, p.DeleteExpiredSessions(ctx, currentTime, reg.Config(context.Background()).DatabaseCleanupBatchSize())) | ||
}) | ||
|
||
t.Run("case=should throw error on cleanup sessions", func(t *testing.T) { | ||
p.GetConnection(ctx).Close() | ||
assert.Error(t, p.DeleteExpiredSessions(ctx, currentTime, reg.Config(context.Background()).DatabaseCleanupBatchSize())) | ||
}) | ||
} | ||
|
||
func TestPersister_Settings_Cleanup(t *testing.T) { | ||
_, reg := internal.NewFastRegistryWithMocks(t) | ||
p := reg.Persister() | ||
currentTime := time.Now() | ||
ctx := context.Background() | ||
|
||
t.Run("case=should not throw error on cleanup setting flows", func(t *testing.T) { | ||
assert.Nil(t, p.DeleteExpiredSettingsFlows(ctx, currentTime, reg.Config(context.Background()).DatabaseCleanupBatchSize())) | ||
}) | ||
|
||
t.Run("case=should throw error on cleanup setting flows", func(t *testing.T) { | ||
p.GetConnection(ctx).Close() | ||
assert.Error(t, p.DeleteExpiredSettingsFlows(ctx, currentTime, reg.Config(context.Background()).DatabaseCleanupBatchSize())) | ||
}) | ||
} | ||
|
||
func TestPersister_Verification_Cleanup(t *testing.T) { | ||
_, reg := internal.NewFastRegistryWithMocks(t) | ||
p := reg.Persister() | ||
currentTime := time.Now() | ||
ctx := context.Background() | ||
|
||
t.Run("case=should not throw error on cleanup verification flows", func(t *testing.T) { | ||
assert.Nil(t, p.DeleteExpiredVerificationFlows(ctx, currentTime, reg.Config(context.Background()).DatabaseCleanupBatchSize())) | ||
}) | ||
|
||
t.Run("case=should throw error on cleanup verification flows", func(t *testing.T) { | ||
p.GetConnection(ctx).Close() | ||
assert.Error(t, p.DeleteExpiredVerificationFlows(ctx, currentTime, reg.Config(context.Background()).DatabaseCleanupBatchSize())) | ||
}) | ||
} |
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