agent_test.go 1.37 KB
Newer Older
ale's avatar
ale committed
1 2 3 4 5 6
package tabacco

import (
	"context"
	"testing"

ale's avatar
ale committed
7
	"git.autistici.org/ai3/tools/tabacco/jobs"
ale's avatar
ale committed
8 9 10 11
)

type fakeManager struct{}

ale's avatar
ale committed
12 13
func (m *fakeManager) BackupJob(context.Context, *SourceSpec) (*Backup, jobs.Job, error) {
	return &Backup{}, nil, nil
ale's avatar
ale committed
14 15
}

ale's avatar
ale committed
16 17
func (m *fakeManager) Backup(context.Context, *SourceSpec) (*Backup, error) {
	return &Backup{}, nil
ale's avatar
ale committed
18 19
}

ale's avatar
ale committed
20
func (m *fakeManager) RestoreJob(context.Context, *FindRequest, string) (jobs.Job, error) {
ale's avatar
ale committed
21 22 23
	return nil, nil
}

ale's avatar
ale committed
24
func (m *fakeManager) Restore(context.Context, *FindRequest, string) error {
ale's avatar
ale committed
25 26 27 28 29 30 31 32 33 34 35 36
	return nil
}

func (m *fakeManager) Close() error {
	return nil
}

func (m *fakeManager) GetStatus() ([]jobs.Status, []jobs.Status, []jobs.Status) {
	return nil, nil, nil
}

func TestMakeSchedule(t *testing.T) {
ale's avatar
ale committed
37 38
	sourceSpecs := []*SourceSpec{
		&SourceSpec{
39
			Name:     "source1/users",
ale's avatar
ale committed
40 41
			Handler:  "file1",
			Schedule: "@random_every 1d",
ale's avatar
ale committed
42 43 44 45 46 47 48 49 50 51 52 53
			Datasets: []*DatasetSpec{
				&DatasetSpec{
					Atoms: []Atom{
						{
							Name: "user1",
							Path: "user1",
						},
						{
							Name: "user2",
							Path: "user2",
						},
					},
ale's avatar
ale committed
54 55 56
				},
			},
		},
ale's avatar
ale committed
57 58 59 60 61
		&SourceSpec{
			Name:            "source2",
			Handler:         "dbpipe",
			Schedule:        "35 3 * * *",
			DatasetsCommand: "echo user1 user1 ; echo user2 user2",
ale's avatar
ale committed
62 63 64 65 66 67 68 69 70
		},
	}

	mgr := &fakeManager{}
	_, err := makeSchedule(context.Background(), mgr, sourceSpecs, 1234)
	if err != nil {
		t.Fatal(err)
	}
}