package cql

import (
	"testing"

	"github.com/everything-on-mysql/cassandra-on-mysql/internal/config"
	"go.uber.org/zap"
)

func TestMessageHandlerExecutePinConfig(t *testing.T) {
	orig := config.GetConfig()
	cfg := config.DefaultConfig()
	cfg.Executor.ExecutePinMySQLConn = true
	config.SetConfig(cfg)
	t.Cleanup(func() {
		config.SetConfig(orig)
	})

	handler := NewMessageHandler(zap.NewNop(), NewPasswordAuthenticator())
	if !handler.executePinMySQLConn {
		t.Fatalf("expected execute pin flag enabled from config")
	}

	cfg.Executor.ExecutePinMySQLConn = false
	config.SetConfig(cfg)
	handler = NewMessageHandler(zap.NewNop(), NewPasswordAuthenticator())
	if handler.executePinMySQLConn {
		t.Fatalf("expected execute pin flag disabled from config")
	}
}
