1
0
mirror of https://github.com/zitadel/zitadel.git synced 2025-08-20 12:47:45 +00:00
Files
.artifacts
.codecov
.github
build
cmd
console
deploy
docs
e2e
internal
actions
admin
api
auth
auth_request
authz
cache
command
config
crypto
database
domain
errors
eventstore
form
i18n
iam
id
idp
integration
config
assert.go
assert_test.go
integration.go
integration_test.go
usertype_string.go
logstore
migration
notification
org
project
proto
protoc
qrcode
query
renderer
repository
static
statik
telemetry
test
user
view
webauthn
openapi
pkg
proto
statik
tools
.dockerignore
.gitignore
.golangci.yaml
.goreleaser.yaml
.releaserc.js
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
README.md
SECURITY.md
buf.work.yaml
changelog.config.js
go.mod
go.sum
main.go
release-channels.yaml
yarn.lock
zitadel/internal/integration/assert.go
2023-05-02 19:24:24 +03:00

42 lines
1.2 KiB
Go

package integration
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
object "github.com/zitadel/zitadel/pkg/grpc/object/v2alpha"
)
type DetailsMsg interface {
GetDetails() *object.Details
}
// AssertDetails asserts values in a message's object Details,
// if the object Details in expected is a non-nil value.
// It targets API v2 messages that have the `GetDetails()` method.
//
// Dynamically generated values are not compared with expected.
// Instead a sanity check is performed.
// For the sequence a non-zero value is expected.
// The change date has to be now, with a tollerance of 1 second.
//
// The resource owner is compared with expected and is
// therefore the only value that has to be set.
func AssertDetails[D DetailsMsg](t testing.TB, exptected, actual D) {
wantDetails, gotDetails := exptected.GetDetails(), actual.GetDetails()
if wantDetails == nil {
assert.Nil(t, gotDetails)
return
}
assert.NotZero(t, gotDetails.GetSequence())
gotCD := gotDetails.GetChangeDate().AsTime()
now := time.Now()
assert.WithinRange(t, gotCD, now.Add(-time.Second), now.Add(time.Second))
assert.Equal(t, wantDetails.GetResourceOwner(), gotDetails.GetResourceOwner())
}