/*
 * Copyright 2021 PingCAP, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package main

import (
	"context"
	"os"
	"testing"
)

func TestDefaultMapper_Start(t *testing.T) {
	dsn := os.Getenv("MYSQL_DSN")
	db, err := Dial(&MysqlConfig{
		DSN: dsn,
	})
	if err != nil {
		t.Fatal(err)
	}
	pipe := make(chan map[string]interface{}, 42)
	mp, err := NewDefaultMapper(db, pipe, "x")
	if err != nil {
		t.Fatal(err)
	}
	ctx := context.Background()
	var input = []map[string]interface{}{
		{
			"Code": 100,
			"Name": "John",
			"Age":  43,
		},
		{
			"Code": 101,
			"Name": "Jack",
			"Age":  42,
		},
	}
	for _, v := range input {
		if err := mp.Handle(ctx, v); err != nil {
			t.Fatal(err)
		}
	}
}
