package mysql

import "testing"

// TestConnect ...
func TestConnect(t *testing.T) {
	db := New("sylvrec.com:3306", "test", "test", "test")
	db.Close()
}

func TestCRUD(t *testing.T) {
	db := New("sylvrec.com:3306", "test", "test", "test")
	var values [][]string
	values = append(values, []string{"", "WuYu", "Kawai"})
	errInsert := db.Insert("test", []string{"id", "nom", "prenom"}, values)
	if errInsert != nil {
		t.Errorf("Expected err=nil, %#v", errInsert)
		return
	}
	var colvalues [][]string
	colvalues = append(colvalues, []string{"nom", "WuYu"})
	rslt, errSelect := db.SelectAND("test", colvalues)
	if rslt == nil || rslt[1][1] != "WuYu" {
		t.Errorf("Expected err=nil, %#v", errSelect)
		return
	}
	var vals [][]string
	var sets [][]string
	sets = append(sets, []string{"nom", "YoYo"})
	vals = append(vals, []string{"nom", "WuYu"})
	vals = append(vals, []string{"prenom", "Kawai"})
	errUpdate := db.UpdateAND("test", sets, vals)
	if errUpdate != nil {
		t.Errorf("Expected err=nil, %#v", errUpdate)
		return
	}
	sets = append(sets, []string{"prenom", "Kawai"})
	errDelete := db.DeleteAND("test", sets)
	if errDelete != nil {
		t.Errorf("Expected err=nil, %#v", errDelete)
		return
	}
	db.Close()
}
