Skip to content

Commit

Permalink
Update version
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesStewy committed May 4, 2017
1 parent 1f0225e commit 5a2120b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ Create MYSQL dumps in Go without the `mysqldump` CLI as a dependancy.

[![GoDoc](https://godoc.org/github.com/JamesStewy/go-mysqldump?status.svg)](https://godoc.org/github.com/JamesStewy/go-mysqldump)
[![Build Status](https://travis-ci.org/JamesStewy/go-mysqldump.svg?branch=master)](https://travis-ci.org/JamesStewy/go-mysqldump)

2 changes: 1 addition & 1 deletion dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type dump struct {
CompleteTime string
}

const version = "0.1.1"
const version = "0.2.0"

const tmpl = `-- Go SQL Dump {{ .DumpVersion }}
--
Expand Down
47 changes: 21 additions & 26 deletions dump_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package mysqldump

import (
"testing"
"github.com/DATA-DOG/go-sqlmock"
"reflect"
"io/ioutil"
"os"
"reflect"
"strings"
"testing"
)

func TestGetTablesOk(t *testing.T) {
Expand All @@ -18,12 +18,12 @@ func TestGetTablesOk(t *testing.T) {
defer db.Close()

rows := sqlmock.NewRows([]string{"Tables_in_Testdb"}).
AddRow("Test_Table_1",).
AddRow("Test_Table_1").
AddRow("Test_Table_2")

mock.ExpectQuery("^SHOW TABLES$").WillReturnRows(rows)

result, err := getTables(db);
result, err := getTables(db)
if err != nil {
t.Errorf("error was not expected while updating stats: %s", err)
}
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestGetTablesNil(t *testing.T) {

mock.ExpectQuery("^SHOW TABLES$").WillReturnRows(rows)

result, err := getTables(db);
result, err := getTables(db)
if err != nil {
t.Errorf("error was not expected while updating stats: %s", err)
}
Expand All @@ -81,11 +81,11 @@ func TestGetServerVersionOk(t *testing.T) {
defer db.Close()

rows := sqlmock.NewRows([]string{"Version()"}).
AddRow("test_version",)
AddRow("test_version")

mock.ExpectQuery("^SELECT version()").WillReturnRows(rows)

result, err := getServerVersion(db);
result, err := getServerVersion(db)
if err != nil {
t.Errorf("error was not expected while updating stats: %s", err)
}
Expand All @@ -111,11 +111,11 @@ func TestCreateTableSQLOk(t *testing.T) {
defer db.Close()

rows := sqlmock.NewRows([]string{"Table", "Create Table"}).
AddRow("Test_Table", "CREATE TABLE 'Test_Table' (`id` int(11) NOT NULL AUTO_INCREMENT,`s` char(60) DEFAULT NULL, PRIMARY KEY (`id`))ENGINE=InnoDB DEFAULT CHARSET=latin1",)
AddRow("Test_Table", "CREATE TABLE 'Test_Table' (`id` int(11) NOT NULL AUTO_INCREMENT,`s` char(60) DEFAULT NULL, PRIMARY KEY (`id`))ENGINE=InnoDB DEFAULT CHARSET=latin1")

mock.ExpectQuery("^SHOW CREATE TABLE Test_Table$").WillReturnRows(rows)

result, err := createTableSQL(db, "Test_Table");
result, err := createTableSQL(db, "Test_Table")

if err != nil {
t.Errorf("error was not expected while updating stats: %s", err)
Expand All @@ -133,7 +133,6 @@ func TestCreateTableSQLOk(t *testing.T) {
}
}


func TestCreateTableValuesOk(t *testing.T) {
db, mock, err := sqlmock.New()
if err != nil {
Expand All @@ -148,7 +147,7 @@ func TestCreateTableValuesOk(t *testing.T) {

mock.ExpectQuery("^SELECT (.+) FROM test$").WillReturnRows(rows)

result, err := createTableValues(db, "test");
result, err := createTableValues(db, "test")
if err != nil {
t.Errorf("error was not expected while updating stats: %s", err)
}
Expand Down Expand Up @@ -179,7 +178,7 @@ func TestCreateTableValuesNil(t *testing.T) {

mock.ExpectQuery("^SELECT (.+) FROM test$").WillReturnRows(rows)

result, err := createTableValues(db, "test");
result, err := createTableValues(db, "test")
if err != nil {
t.Errorf("error was not expected while updating stats: %s", err)
}
Expand All @@ -205,17 +204,16 @@ func TestCreateTableOk(t *testing.T) {
defer db.Close()

createTableRows := sqlmock.NewRows([]string{"Table", "Create Table"}).
AddRow("Test_Table", "CREATE TABLE 'Test_Table' (`id` int(11) NOT NULL AUTO_INCREMENT,`s` char(60) DEFAULT NULL, PRIMARY KEY (`id`))ENGINE=InnoDB DEFAULT CHARSET=latin1",)
AddRow("Test_Table", "CREATE TABLE 'Test_Table' (`id` int(11) NOT NULL AUTO_INCREMENT,`s` char(60) DEFAULT NULL, PRIMARY KEY (`id`))ENGINE=InnoDB DEFAULT CHARSET=latin1")

createTableValueRows := sqlmock.NewRows([]string{"id", "email", "name"}).
AddRow(1, nil, "Test Name 1").
AddRow(2, "test2@test.de", "Test Name 2")


mock.ExpectQuery("^SHOW CREATE TABLE Test_Table$").WillReturnRows(createTableRows)
mock.ExpectQuery("^SELECT (.+) FROM Test_Table$").WillReturnRows(createTableValueRows)

result, err := createTable(db, "Test_Table");
result, err := createTable(db, "Test_Table")
if err != nil {
t.Errorf("error was not expected while updating stats: %s", err)
}
Expand All @@ -226,8 +224,8 @@ func TestCreateTableOk(t *testing.T) {
}

expectedResult := &table{
Name:"Test_Table",
SQL: "CREATE TABLE 'Test_Table' (`id` int(11) NOT NULL AUTO_INCREMENT,`s` char(60) DEFAULT NULL, PRIMARY KEY (`id`))ENGINE=InnoDB DEFAULT CHARSET=latin1",
Name: "Test_Table",
SQL: "CREATE TABLE 'Test_Table' (`id` int(11) NOT NULL AUTO_INCREMENT,`s` char(60) DEFAULT NULL, PRIMARY KEY (`id`))ENGINE=InnoDB DEFAULT CHARSET=latin1",
Values: "('1','','Test Name 1'),('2','test2@test.de','Test Name 2')",
}

Expand All @@ -249,13 +247,13 @@ func TestDumpOk(t *testing.T) {
defer db.Close()

showTablesRows := sqlmock.NewRows([]string{"Tables_in_Testdb"}).
AddRow("Test_Table",)
AddRow("Test_Table")

serverVersionRows := sqlmock.NewRows([]string{"Version()"}).
AddRow("test_version",)
AddRow("test_version")

createTableRows := sqlmock.NewRows([]string{"Table", "Create Table"}).
AddRow("Test_Table", "CREATE TABLE 'Test_Table' (`id` int(11) NOT NULL AUTO_INCREMENT,`email` char(60) DEFAULT NULL, `name` char(60), PRIMARY KEY (`id`))ENGINE=InnoDB DEFAULT CHARSET=latin1",)
AddRow("Test_Table", "CREATE TABLE 'Test_Table' (`id` int(11) NOT NULL AUTO_INCREMENT,`email` char(60) DEFAULT NULL, `name` char(60), PRIMARY KEY (`id`))ENGINE=InnoDB DEFAULT CHARSET=latin1")

createTableValueRows := sqlmock.NewRows([]string{"id", "email", "name"}).
AddRow(1, nil, "Test Name 1").
Expand All @@ -266,11 +264,10 @@ func TestDumpOk(t *testing.T) {
mock.ExpectQuery("^SHOW CREATE TABLE Test_Table$").WillReturnRows(createTableRows)
mock.ExpectQuery("^SELECT (.+) FROM Test_Table$").WillReturnRows(createTableValueRows)


dumper := &Dumper{
db:db,
db: db,
format: "test_format",
dir: "/tmp/",
dir: "/tmp/",
}

path, err := dumper.Dump()
Expand All @@ -291,8 +288,7 @@ func TestDumpOk(t *testing.T) {

result := strings.Replace(strings.Split(string(f), "-- Dump completed")[0], "`", "\\", -1)


expected := `-- Go SQL Dump 0.1.1
expected := `-- Go SQL Dump ` + version + `
--
-- ------------------------------------------------------
-- Server version test_version
Expand Down Expand Up @@ -320,4 +316,3 @@ UNLOCK TABLES;
t.Fatalf("expected %#v, got %#v", expected, result)
}
}

0 comments on commit 5a2120b

Please sign in to comment.