<commit_before>package storage

import (
	"os"
	"path"
	"reflect"
	"testing"
	"time"

	"github.com/taku-k/polymerase/pkg/base"
)

func NewLocalBackupStorageForTest() *LocalBackupStorage {
	dir, _ := os.Getwd()
	cfg := &base.Config{}
	cfg.InitDefaults()
	return &LocalBackupStorage{
		RootDir:    path.Join(dir, "testdata"),
		TimeFormat: cfg.TimeFormat,
	}
}

func TestLocalBackupStorage_GetLastLSN(t *testing.T) {
	s := NewLocalBackupStorageForTest()
	a, err := s.GetLastLSN("test-db1")
	e := "110"
	if err != nil {
		t.Errorf(`GetLastLSN("test-db1") is failed: %v`, err)
	}
	if a != e {
		t.Errorf(`GetLastLSN("test-db1") returns wrong lsn: expected = (%v), actual (%v)`, e, a)
	}
}

func TestLocalBackupStorage_SearchStaringPointByLSN(t *testing.T) {
	s := NewLocalBackupStorageForTest()
	a, err := s.SearchStaringPointByLSN("test-db1", "110")
	e := "2017-05-24"
	if err != nil {
		t.Errorf(`SearchStartingPointByLSN("test-db1", "110") is failed: %v`, err)
	}
	if a != e {
		t.Errorf(`SearchStartingPointByLSN("test-db1", "110") returns wrong starting point: expected = (%v), actual (%v)`, e, a)
	}
}

func TestLocalBackupStorage_SearchConsecutiveIncBackups(t *testing.T) {
	s := NewLocalBackupStorageForTest()
	db := "test-db1"
	st := s.GetStorageType()

	var tests = []struct {
		in  string
		out []*BackupFile
	}{
		{
			"2017-05-26",
			[]*BackupFile{
				{
					StorageType: st,
					BackupType:  "incremental",
					Key:         "test-db1/2017-05-24/2017-05-25-15-04-05",
				},
				{
					StorageType: st,
					BackupType:  "full-backuped",
					Key:         "test-db1/2017-05-24/2017-05-24-15-04-05",
				},
			},
		},
		{
			"2017-05-25",
			[]*BackupFile{
				{
					StorageType: st,
					BackupType:  "full-backuped",
					Key:         "test-db1/2017-05-24/2017-05-24-15-04-05",
				},
			},
		},
		{
			"2017-05-19",
			[]*BackupFile{
				{
					StorageType: st,
					BackupType:  "incremental",
					Key:         "test-db1/2017-05-17/2017-05-18-15-04-05",
				},
				{
					StorageType: st,
					BackupType:  "full-backuped",
					Key:         "test-db1/2017-05-17/2017-05-17-15-04-05",
				},
			},
		},
	}
	for _, tt := range tests {
		f, _ := time.Parse("2006-01-02", tt.in)
		a, err := s.SearchConsecutiveIncBackups(db, f)
		if err != nil {
			t.Errorf(`SearchConsecutiveIncBackups(%v, %v) is failed: %v`, db, f, err)
		}
		if !reflect.DeepEqual(a, tt.out) {
			t.Errorf(`SearchConsecutiveIncBackups(%v, %v) returns wrong keys: expected = (%v), actual = (%v)`, db, f, tt.out, a)

		}
	}
}
<commit_msg>Pass test<commit_after>package storage

import (
	"os"
	"path"
	"reflect"
	"testing"
	"time"

	"github.com/taku-k/polymerase/pkg/base"
)

func NewLocalBackupStorageForTest() *LocalBackupStorage {
	dir, _ := os.Getwd()
	cfg := &base.Config{}
	cfg.InitDefaults()
	return &LocalBackupStorage{
		RootDir:    path.Join(dir, "testdata"),
		TimeFormat: cfg.TimeFormat,
	}
}

func TestLocalBackupStorage_GetLastLSN(t *testing.T) {
	s := NewLocalBackupStorageForTest()
	a, err := s.GetLastLSN("test-db1")
	e := "110"
	if err != nil {
		t.Errorf(`GetLastLSN("test-db1") is failed: %v`, err)
	}
	if a != e {
		t.Errorf(`GetLastLSN("test-db1") returns wrong lsn: expected = (%v), actual (%v)`, e, a)
	}
}

func TestLocalBackupStorage_SearchStaringPointByLSN(t *testing.T) {
	s := NewLocalBackupStorageForTest()
	a, err := s.SearchStaringPointByLSN("test-db1", "110")
	e := "2017-05-24-15-04-05"
	if err != nil {
		t.Errorf(`SearchStartingPointByLSN("test-db1", "110") is failed: %v`, err)
	}
	if a != e {
		t.Errorf(`SearchStartingPointByLSN("test-db1", "110") returns wrong starting point: expected = (%v), actual (%v)`, e, a)
	}
}

func TestLocalBackupStorage_SearchConsecutiveIncBackups(t *testing.T) {
	s := NewLocalBackupStorageForTest()
	db := "test-db1"
	st := s.GetStorageType()

	var tests = []struct {
		in  string
		out []*BackupFile
	}{
		{
			"2017-05-26",
			[]*BackupFile{
				{
					StorageType: st,
					BackupType:  "incremental",
					Key:         "test-db1/2017-05-24-15-04-05/2017-05-25-15-04-05",
				},
				{
					StorageType: st,
					BackupType:  "full-backuped",
					Key:         "test-db1/2017-05-24-15-04-05/2017-05-24-15-04-05",
				},
			},
		},
		{
			"2017-05-25",
			[]*BackupFile{
				{
					StorageType: st,
					BackupType:  "full-backuped",
					Key:         "test-db1/2017-05-24-15-04-05/2017-05-24-15-04-05",
				},
			},
		},
		{
			"2017-05-19",
			[]*BackupFile{
				{
					StorageType: st,
					BackupType:  "incremental",
					Key:         "test-db1/2017-05-17-15-04-05/2017-05-18-15-04-05",
				},
				{
					StorageType: st,
					BackupType:  "full-backuped",
					Key:         "test-db1/2017-05-17-15-04-05/2017-05-17-15-04-05",
				},
			},
		},
	}
	for _, tt := range tests {
		f, _ := time.Parse("2006-01-02", tt.in)
		a, err := s.SearchConsecutiveIncBackups(db, f)
		if err != nil {
			t.Errorf(`SearchConsecutiveIncBackups(%v, %v) is failed: %v`, db, f, err)
		}
		if !reflect.DeepEqual(a, tt.out) {
			t.Errorf(`SearchConsecutiveIncBackups(%v, %v) returns wrong keys: expected = (%v), actual = (%v)`, db, f, tt.out, a)

		}
	}
}

{'fraction_non_alphanumeric': 0.18578161822466616, 'fraction_numerical': 0.07541241162608013, 'mean_word_length': 2.9726989079563184, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2611976', 'n_tokens_mistral': 2578, 'n_tokens_neox': 2109, 'n_words': 361}