Skip to content

Commit

Permalink
improve: fix test failure
Browse files Browse the repository at this point in the history
Move SaveSettings out of the common helper, and instead move it to the two tests that need
it.
  • Loading branch information
dnephin committed Aug 10, 2022
1 parent c582447 commit a8e7ea6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
7 changes: 1 addition & 6 deletions internal/access/access_test.go
Expand Up @@ -41,13 +41,8 @@ func setupAccessTestContext(t *testing.T) (*gin.Context, *gorm.DB, *models.Provi
c, _ := gin.CreateTestContext(httptest.NewRecorder())
c.Set("db", db)

err := data.SaveSettings(db, &models.Settings{
LengthMin: 8,
})
assert.NilError(t, err)

admin := &models.Identity{Name: "admin@example.com"}
err = data.CreateIdentity(db, admin)
err := data.CreateIdentity(db, admin)
assert.NilError(t, err)

c.Set("identity", admin)
Expand Down
5 changes: 5 additions & 0 deletions internal/access/credential_test.go
Expand Up @@ -86,6 +86,11 @@ func TestUpdateCredentials(t *testing.T) {
_, err = CreateCredential(c, *user)
assert.NilError(t, err)

err = data.SaveSettings(db, &models.Settings{
LengthMin: 8,
})
assert.NilError(t, err)

t.Run("Update user credentials IS single use password", func(t *testing.T) {
err := UpdateCredential(c, user, "newPassword")
assert.NilError(t, err)
Expand Down
7 changes: 6 additions & 1 deletion internal/access/passwordreset_test.go
Expand Up @@ -13,12 +13,17 @@ import (
func TestPasswordResetFlow(t *testing.T) {
c, db, _ := setupAccessTestContext(t)

err := data.SaveSettings(db, &models.Settings{
LengthMin: 8,
})
assert.NilError(t, err)

user := &models.Identity{
Name: "joe@example.com",
}

// setup user
err := CreateIdentity(c, user)
err = CreateIdentity(c, user)
assert.NilError(t, err)

err = data.CreateCredential(db, &models.Credential{
Expand Down
2 changes: 1 addition & 1 deletion internal/server/data/passwordresettoken.go
Expand Up @@ -3,12 +3,12 @@ package data
import (
"time"

"github.com/infrahq/infra/uid"
"gorm.io/gorm"

"github.com/infrahq/infra/internal"
"github.com/infrahq/infra/internal/generate"
"github.com/infrahq/infra/internal/server/models"
"github.com/infrahq/infra/uid"
)

func CreatePasswordResetToken(db *gorm.DB, user *models.Identity) (*models.PasswordResetToken, error) {
Expand Down

0 comments on commit a8e7ea6

Please sign in to comment.