Example #1
0
func TestLOC(t *testing.T) {
	var dump, dumpmagic bool // set to true to print out LOC sigs

	config.SetHome(filepath.Join("..", "..", "cmd", "roy", "data"))
	config.SetLOC("")()
	l, err := newLOC(config.LOC())
	if l != nil {
		if dump {
			fdd := l.(fdds)
			for _, v := range fdd.f {
				fmt.Println(v)
				fmt.Println("****************")
			}
		} else if dumpmagic {
			fdd := l.(fdds)
			for _, v := range fdd.f {
				if len(v.Magics) > 0 {
					fmt.Println("{")
					for _, m := range v.Magics {
						fmt.Println("`" + m + "`,")
					}
					fmt.Println("},")
				}
			}
		}
		if _, _, err = l.Signatures(); err != nil {
			t.Fatal(err)
		}
	} else {
		t.Fatalf("Expecting a LOC, got nothing! Error: %v", err)
	}
}
Example #2
0
func New(opts ...config.Option) (core.Identifier, error) {
	for _, v := range opts {
		v()
	}
	loc, err := newLOC(config.LOC())
	if err != nil {
		return nil, err
	}
	// set updated
	updated := loc.(fdds).Updated().Format(dateFmt)
	// add extensions
	for _, v := range config.Extend() {
		e, err := newLOC(v)
		if err != nil {
			return nil, fmt.Errorf("LOC: error loading extension file %s; got %s", v, err)
		}
		loc = identifier.Join(loc, e)
	}
	// apply config
	loc = identifier.ApplyConfig(loc)
	// return identifier
	return &Identifier{
		infos: infos(loc.Infos()),
		Base:  identifier.New(loc, config.ZipLOC(), updated),
	}, nil
}
Example #3
0
func TestUpdated(t *testing.T) {
	config.SetHome(filepath.Join("..", "..", "cmd", "roy", "data"))
	l, err := newLOC(config.LOC())
	if err != nil || l == nil {
		t.Fatalf("couldn't parse LOC file: %v", err)
	}
	expect, _ := time.Parse(dateFmt, "2016-01-01")
	f := l.(fdds)
	if !f.Updated().After(expect) {
		t.Fatalf("expected %v, got %v", expect, f.Updated())
	}
}