Skip to content

Commit

Permalink
feat: update migration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Aug 27, 2020
1 parent f87fb54 commit fb28173
Show file tree
Hide file tree
Showing 26 changed files with 112 additions and 16 deletions.
@@ -1,5 +1,6 @@
{
"id": "202c1981-1e25-47f0-8764-75ad506c2bec",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/login",
Expand Down
@@ -1,5 +1,6 @@
{
"id": "3a9ea34f-0f12-469b-9417-3ae5795a7baa",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/login",
Expand Down
@@ -1,5 +1,6 @@
{
"id": "43c99182-bb67-47e1-b564-bb23bd8d4393",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/login?prompt=login\u0026return_to=http%3A%2F%2F127.0.0.1%3A4455%2F.ory%2Fkratos%2Fpublic%2Fself-service%2Fbrowser%2Fflows%2Fsettings%2Fstrategies%2Fprofile%3Frequest%3D74fd6c53-7651-453e-90b8-2c5adbf911bb",
Expand Down
@@ -0,0 +1,10 @@
{
"id": "47edd3a8-0998-4779-9469-f4b8ee4430df",
"type": "api",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/login",
"messages": [],
"methods": {},
"forced": false
}
@@ -1,5 +1,6 @@
{
"id": "56d94e8b-8a5d-4b7f-8a6e-3259d2b2903e",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/login",
Expand Down
@@ -1,5 +1,6 @@
{
"id": "6d387820-f2f4-4f9f-9980-a90d89e7811f",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/login",
Expand Down
@@ -1,5 +1,6 @@
{
"id": "916ded11-aa64-4a27-b06e-96e221a509d7",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/login",
Expand Down
@@ -1,5 +1,6 @@
{
"id": "99974ce6-388c-4669-a95a-7757ee724020",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/login",
Expand Down
@@ -1,5 +1,6 @@
{
"id": "13178936-095a-466b-abe0-36d977d3dc18",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/registration",
Expand Down
@@ -0,0 +1,11 @@
{
"id": "87e871e1-a45f-4ed0-ba4e-a03063c774dc",
"type": "api",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/registration",
"active": "link",
"messages": [],
"methods": {},
"state": "choose_method"
}
@@ -1,5 +1,6 @@
{
"id": "05a7f09d-4ef3-41fb-958a-6ad74584b36a",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/registration",
Expand Down
@@ -1,5 +1,6 @@
{
"id": "22d58184-b97d-44a5-bbaf-0aa8b4000d81",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/registration",
Expand Down
@@ -1,5 +1,6 @@
{
"id": "2bf132e0-5d40-4df9-9a11-9106e5333735",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/registration",
Expand Down
@@ -0,0 +1,10 @@
{
"id": "696e7022-c466-44f6-89c6-8cf93c06a62a",
"type": "api",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/registration",
"active": "password",
"messages": [],
"methods": {}
}
@@ -1,5 +1,6 @@
{
"id": "87fa3f43-5155-42b4-a1ad-174c2595fdaf",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/registration",
Expand Down
@@ -1,5 +1,6 @@
{
"id": "9edcf051-1cd0-44cc-bd2f-6ac21f0c24dd",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/registration",
Expand Down
@@ -1,5 +1,6 @@
{
"id": "194c5b05-0487-4a11-bcbc-f301c9ff9678",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/settings",
Expand Down
@@ -1,5 +1,6 @@
{
"id": "21c5f714-3089-49d2-b387-f244d4dd9e00",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/settings",
Expand Down
@@ -1,5 +1,6 @@
{
"id": "74fd6c53-7651-453e-90b8-2c5adbf911bb",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/settings",
Expand Down
@@ -1,5 +1,6 @@
{
"id": "77fe4fb3-2d4e-4532-b568-c44b0aece0aa",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/settings",
Expand Down
@@ -1,5 +1,6 @@
{
"id": "a79bfcf1-68ae-49de-8b23-4f96921b8341",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/settings",
Expand Down
@@ -0,0 +1,19 @@
{
"id": "cdfd1eed-34a4-491d-ad0a-7579d3a0a7ba",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/settings",
"active": "profile",
"messages": [],
"methods": {},
"identity": {
"id": "a251ebc2-880c-4f76-a8f3-38e6940eab0e",
"schema_id": "default",
"schema_url": "",
"traits": {
"email": "foobar@ory.sh"
}
},
"state": "show_form"
}
18 changes: 18 additions & 0 deletions persistence/sql/migratest/migration_refresh_test.go
@@ -0,0 +1,18 @@
// +build refresh

package migratest

import (
"testing"
"encoding/json"
"io/ioutil"

"github.com/stretchr/testify/require"
)

func writeFixtureOnError(t *testing.T, err error, actual interface{}, location string) {
content, err := json.MarshalIndent(actual, "", " ")
require.NoError(t, err)
require.NoError(t, ioutil.WriteFile(location, content, 0666))

}
13 changes: 13 additions & 0 deletions persistence/sql/migratest/migration_strict_test.go
@@ -0,0 +1,13 @@
// +build !refresh

package migratest

import (
"testing"

"github.com/stretchr/testify/require"
)

func writeFixtureOnError(t *testing.T, err error, actual interface{}, location string) {
require.NoError(t, err)
}
22 changes: 6 additions & 16 deletions persistence/sql/migratest/migration_test.go
Expand Up @@ -9,7 +9,6 @@ import (
"os"
"path/filepath"
"runtime/debug"
"strconv"
"testing"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -127,7 +126,7 @@ func TestMigrations(t *testing.T) {
for _, id := range ids {
actual, err := d.Registry().LoginFlowPersister().GetLoginFlow(context.Background(), id.ID)
require.NoError(t, err)
compareWithFixture(t, actual, "login_request", id.ID.String())
compareWithFixture(t, actual, "login_flow", id.ID.String())
}
})
t.Run("case=registration", func(t *testing.T) {
Expand All @@ -137,28 +136,28 @@ func TestMigrations(t *testing.T) {
for _, id := range ids {
actual, err := d.Registry().RegistrationFlowPersister().GetRegistrationFlow(context.Background(), id.ID)
require.NoError(t, err)
compareWithFixture(t, actual, "registration_request", id.ID.String())
compareWithFixture(t, actual, "registration_flow", id.ID.String())
}
})
t.Run("case=settings_request", func(t *testing.T) {
t.Run("case=settings_flow", func(t *testing.T) {
var ids []settings.Flow
require.NoError(t, c.Select("id").All(&ids))

for _, id := range ids {
actual, err := d.Registry().SettingsFlowPersister().GetSettingsFlow(context.Background(), id.ID)
require.NoError(t, err)
compareWithFixture(t, actual, "settings_request", id.ID.String())
compareWithFixture(t, actual, "settings_flow", id.ID.String())
}
})

t.Run("case=recovery_request", func(t *testing.T) {
t.Run("case=recovery_flow", func(t *testing.T) {
var ids []recovery.Flow
require.NoError(t, c.Select("id").All(&ids))

for _, id := range ids {
actual, err := d.Registry().RecoveryFlowPersister().GetRecoveryFlow(context.Background(), id.ID)
require.NoError(t, err)
compareWithFixture(t, actual, "recovery_request", id.ID.String())
compareWithFixture(t, actual, "recovery_flow", id.ID.String())
}
})
})
Expand Down Expand Up @@ -195,12 +194,3 @@ func compareWithFixture(t *testing.T, actual interface{}, prefix string, id stri
writeFixtureOnError(t, nil, actual, location)
}
}

func writeFixtureOnError(t *testing.T, err error, actual interface{}, location string) {
if ok, _ := strconv.ParseBool(os.Getenv("REFRESH_FIXTURES")); ok {
content, err := json.MarshalIndent(actual, "", " ")
require.NoError(t, err)
require.NoError(t, ioutil.WriteFile(location, content, 0666))
}
require.NoError(t, err)
}
@@ -0,0 +1,7 @@
INSERT INTO selfservice_login_requests (id, request_url, issued_at, expires_at, active_method, csrf_token, created_at, updated_at, forced, messages, type) VALUES ('47edd3a8-0998-4779-9469-f4b8ee4430df', 'http://kratos:4433/self-service/browser/flows/login', '2013-10-07 08:23:19', '2013-10-07 08:23:19', '', 'fpeVSZ9ZH7YvUkhXsOVEIssxbfauh5lcoQSYxTcN0XkMneg1L42h+HtvisjlNjBF4ElcD2jApCHoJYq2u9sVWg==', '2013-10-07 08:23:19', '2013-10-07 08:23:19', false, '[]', 'api');
INSERT INTO selfservice_registration_requests (id, request_url, issued_at, expires_at, active_method, csrf_token, created_at, updated_at, messages, type) VALUES ('696e7022-c466-44f6-89c6-8cf93c06a62a', 'http://kratos:4433/self-service/browser/flows/registration', '2013-10-07 08:23:19', '2013-10-07 08:23:19', 'password', 'vYYuhWXBfXKzBC+BlnbDmXfBKsUWY6SU/v04gHF9GYzPjFP51RXDPOc57R7Dpbf+XLkbPNAkmem33Crz/avdrw==', '2013-10-07 08:23:19', '2013-10-07 08:23:19', '[]', 'api');
INSERT INTO selfservice_verification_requests (id, request_url, issued_at, expires_at, form, via, csrf_token, success, created_at, updated_at, messages, type) VALUES ('3631e880-ce59-4cbd-a705-0d825eea590d', 'http://kratos:4433/self-service/browser/flows/verification/email', '2013-10-07 08:23:19', '2013-10-07 08:23:19', 'null', 'email', '8xoIMa1+UkDqTt+tIHmIEHztQkk0AWk2PJhWWYDmB6dSE+RtJinnxtwH5lNNCnYyQuCF2ugy7rWjCgiwYPJNOw==', true, '2013-10-07 08:23:19', '2013-10-07 08:23:19', '[]', 'api');
INSERT INTO selfservice_settings_requests (id, request_url, issued_at, expires_at, state, identity_id, created_at, updated_at, active_method, messages) VALUES
('cdfd1eed-34a4-491d-ad0a-7579d3a0a7ba', 'http://kratos:4433/self-service/browser/flows/settings', '2013-10-07 08:23:19', '2013-10-07 08:23:19', 'show_form', 'a251ebc2-880c-4f76-a8f3-38e6940eab0e', '2013-10-07 08:23:19', '2013-10-07 08:23:19', 'profile', '[]');
INSERT INTO selfservice_recovery_requests (id, request_url, issued_at, expires_at, messages, active_method, csrf_token, state, recovered_identity_id, created_at, updated_at, type)
VALUES ('87e871e1-a45f-4ed0-ba4e-a03063c774dc', 'http://kratos:4433/self-service/browser/flows/registration', '2013-10-07 08:23:19', '2013-10-07 08:23:19', '[]', 'link', 'vYYuhWXBfXKzBC+BlnbDmXfBKsUWY6SU/v04gHF9GYzPjFP51RXDPOc57R7Dpbf+XLkbPNAkmem33Crz/avdrw==', 'choose_method', 'a251ebc2-880c-4f76-a8f3-38e6940eab0e', '2013-10-07 08:23:19', '2013-10-07 08:23:19', 'api');

0 comments on commit fb28173

Please sign in to comment.