package premium_dm

import (
	"testing"

	v1beta2 "github.com/tidbcloud/dataflow-service-ng/idl/pbgen/proto/premium_dm/v1beta2"
	"github.com/stretchr/testify/require"
)

func TestHasPremiumDMSourceSecurityTLS(t *testing.T) {
	t.Parallel()

	tests := map[string]struct {
		security *v1beta2.Security
		want     bool
	}{
		"nil security": {
			security: nil,
			want:     false,
		},
		"empty security": {
			security: &v1beta2.Security{},
			want:     false,
		},
		"cert allowed cn only": {
			security: &v1beta2.Security{CertAllowedCn: []string{"cn-a"}},
			want:     false,
		},
		"ca only": {
			security: &v1beta2.Security{SslCaContent: []byte("ca")},
			want:     true,
		},
		"cert and key only": {
			security: &v1beta2.Security{
				SslCertContent: []byte("cert"),
				SslKeyContent:  []byte("key"),
			},
			want: true,
		},
	}
	for name, tc := range tests {
		t.Run(name, func(t *testing.T) {
			t.Parallel()
			require.Equal(t, tc.want, hasPremiumDMSourceSecurityTLS(tc.security))
		})
	}
}
