Ejemplo n.º 1
0
func getQuery() *views.Query {
	var err error
	var command views.Query
	flag.Parse()
	command.Count = *count
	command.Template = *template
	command.Start, err = days.Parse(*start)
	command.Out = os.Stdout
	if err != nil {
		fmt.Printf("error: failed to parse: %v\n", *start)
		os.Exit(1)
	}
	command.View = views.Resolve(*format)
	if command.View == nil {
		fmt.Printf("error: unsupported format: %v\n", *format)
		os.Exit(1)
	}
	return &command
}
Ejemplo n.º 2
0
func TestRange(t *testing.T) {
	q := new(Query)
	q.Start, _ = days.Parse("2006-01-02")
	q.Count = 3
	r := q.Range()
	if len(r) != 4 {
		t.Fatalf("expected 4 results, got %v", len(r))
	}
	if r[0] != q.Start {
		t.Fatal("expected %v got %v", q.Start, r[0])
	}
	if r[1] != q.Start.Add(1) {
		t.Fatal("expected %v got %v", q.Start.Add(1), r[1])
	}
	if r[2] != q.Start.Add(2) {
		t.Fatal("expected %v got %v", q.Start.Add(2), r[2])
	}
	if r[3] != q.Start.Add(3) {
		t.Fatal("expected %v got %v", q.Start.Add(3), r[3])
	}
}