package metadata

import (
	"testing"

	"github.com/smartystreets/goconvey/convey"
)

func TestActualRequestEqual(t *testing.T) {
	convey.Convey("test equal", t, func() {
		actual := &ExpectRequest[uint64]{
			TenantId:   1,
			ProjectId:  2,
			ClusterId:  3,
			ResourceId: "5",
		}
		convey.Convey("test org id", func() {
			convey.Convey("not equal", func() {
				err := Validate[uint64](t.Context(), actual)
				convey.So(err, convey.ShouldBeError)

				ctx := AppendToOutgoingMeta(t.Context(), &RequestMeta{})
				err = Validate[uint64](ctx, actual)
				convey.So(err, convey.ShouldBeError)

				ctx = AppendToOutgoingMeta(t.Context(), &RequestMeta{OrgID: 2})
				err = Validate[uint64](ctx, actual)
				convey.So(err, convey.ShouldBeError)
			})
			convey.Convey("equal", func() {
				ctx := AppendToOutgoingMeta(t.Context(), &RequestMeta{OrgID: 1})
				err := Validate[uint64](ctx, actual)
				convey.So(err, convey.ShouldBeNil)
			})
		})
		convey.Convey("test project id", func() {
			convey.Convey("not equal", func() {
				ctx := AppendToIncomingMeta(t.Context(), &RequestMeta{DefaultProjectID: 1})
				err := Validate[uint64](ctx, actual)
				convey.So(err, convey.ShouldBeError)
			})
			convey.Convey("equal", func() {
				ctx := AppendToIncomingMeta(t.Context(), &RequestMeta{DefaultProjectID: 2})
				err := Validate[uint64](ctx, actual)
				convey.So(err, convey.ShouldBeNil)
			})
		})
		convey.Convey("test cluster id", func() {
			convey.Convey("not equal", func() {
				ctx := AppendToIncomingMeta(t.Context(), &RequestMeta{ClusterID: 1})
				err := Validate[uint64](ctx, actual)
				convey.So(err, convey.ShouldBeError)
			})
			convey.Convey("equal", func() {
				ctx := AppendToIncomingMeta(t.Context(), &RequestMeta{ClusterID: 3})
				err := Validate[uint64](ctx, actual)
				convey.So(err, convey.ShouldBeNil)
			})
		})
		convey.Convey("test resource id", func() {
			convey.Convey("not equal", func() {
				ctx := AppendToOutgoingMeta(t.Context(), &RequestMeta{ResourceID: "1"})
				err := Validate[uint64](ctx, actual)
				convey.So(err, convey.ShouldBeError)
			})
			convey.Convey("equal", func() {
				ctx := AppendToIncomingMeta(t.Context(), &RequestMeta{ResourceID: "5"})
				err := Validate[uint64](ctx, actual)
				convey.So(err, convey.ShouldBeNil)
			})
		})
	})
}
