예제 #1
0
파일: main.go 프로젝트: apoydence/ledger
func buildFilterFlags() []cli.Flag {
	var results []cli.Flag
	for name := range filters.Store() {
		results = append(results, cli.StringSliceFlag{
			Name:  fmt.Sprintf("filter-%s", name),
			Value: new(cli.StringSlice),
		})
	}
	return results
}
예제 #2
0
파일: main.go 프로젝트: apoydence/ledger
func buildFilter(c *cli.Context) database.Filter {
	var results []database.Filter
	for name, factory := range filters.Store() {
		filterArgs := c.StringSlice(fmt.Sprintf("filter-%s", name))
		if len(filterArgs) <= 0 {
			continue
		}

		for _, arg := range filterArgs {
			builtFilter, err := factory.Generate(arg)
			fatalErr(err)
			results = append(results, builtFilter)
		}
	}

	if len(results) == 0 {
		return nil
	}

	return database.CombineFilters(results...)
}
예제 #3
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Store", func() {
	var mockFilterFactory filters.FilterFactoryFunc

	BeforeEach(func() {
		mockFilterFactory = filters.FilterFactoryFunc(func(string) (database.Filter, error) {
			return nil, nil
		})
	})

	It("has a map of filters", func() {
		filters.AddToStore("some-filter-name", mockFilterFactory)
		Expect(filters.Store()).To(HaveKey("some-filter-name"))
	})

	It("panics if the same name is added twice", func() {
		filters.AddToStore("some-other-name", nil)
		Expect(func() { filters.AddToStore("some-other-name", nil) }).To(Panic())
	})

	Describe("Fetch()", func() {
		It("returns all the matching filters", func() {
			filters.AddToStore("filter-1", mockFilterFactory)
			filters.AddToStore("filter-2", mockFilterFactory)
			filters, err := filters.Fetch("filter-1", "filter-2")

			Expect(err).ToNot(HaveOccurred())
			Expect(filters).To(HaveLen(2))