package audit

import (
	"context"
	"testing"

	auditent "github.com/tidbcloud/devops/entity/audit"
	testutil "github.com/tidbcloud/devops/pkg/infra/utils/test"

	. "github.com/onsi/ginkgo/v2"
	. "github.com/onsi/gomega"
)

func TestAuditService(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Audit Service Suite", testutil.ReporterConfig())
}

var _ = Describe("[AuditService]", func() {
	Describe("ListAuditLogTypes", func() {
		It("returns all audit log types and does not share backing array", func() {
			s := &svc{}

			types, err := s.ListAuditLogTypes(context.Background())
			Expect(err).To(BeNil())
			Expect(types).To(Equal(auditent.AuditLogTypeValues))
			Expect(types).To(HaveLen(len(auditent.AuditLogTypeValues)))

			if len(types) == 0 {
				return
			}

			original := auditent.AuditLogTypeValues[0]
			types[0] = auditent.AuditLogType("mutated_by_test")
			Expect(auditent.AuditLogTypeValues[0]).To(Equal(original))
		})
	})
})
