2023-04-28 14:39:53 +03:00
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2023-09-13 14:43:01 +02:00
|
|
|
object "github.com/zitadel/zitadel/pkg/grpc/object/v2beta"
|
2023-04-28 14:39:53 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type DetailsMsg interface {
|
|
|
|
GetDetails() *object.Details
|
|
|
|
}
|
|
|
|
|
2023-05-02 19:24:24 +03:00
|
|
|
// 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.
|
2023-09-15 16:58:45 +02:00
|
|
|
func AssertDetails[D DetailsMsg](t testing.TB, expected, actual D) {
|
|
|
|
wantDetails, gotDetails := expected.GetDetails(), actual.GetDetails()
|
2023-05-02 19:24:24 +03:00
|
|
|
if wantDetails == nil {
|
|
|
|
assert.Nil(t, gotDetails)
|
|
|
|
return
|
2023-04-28 14:39:53 +03:00
|
|
|
}
|
2023-05-02 19:24:24 +03:00
|
|
|
|
|
|
|
assert.NotZero(t, gotDetails.GetSequence())
|
|
|
|
|
|
|
|
gotCD := gotDetails.GetChangeDate().AsTime()
|
|
|
|
now := time.Now()
|
2023-06-07 17:28:42 +02:00
|
|
|
assert.WithinRange(t, gotCD, now.Add(-time.Minute), now.Add(time.Minute))
|
2023-05-02 19:24:24 +03:00
|
|
|
|
2023-04-28 14:39:53 +03:00
|
|
|
assert.Equal(t, wantDetails.GetResourceOwner(), gotDetails.GetResourceOwner())
|
|
|
|
}
|