package contracts import "testing" func laravelContractIDs(cs []Contract) map[string]Contract { out := map[string]Contract{} for _, c := range cs { if fw, _ := c.Meta["framework"].(string); fw == "laravel" { out[c.ID] = c } } return out } func TestLaravelResource_FullExpansion(t *testing.T) { src := []byte(`only(['index', 'show']); `) ext := &HTTPExtractor{} byID := laravelContractIDs(ext.Extract("routes/web.php", src, nil, nil)) if len(byID) != 2 { t.Fatalf("->only(['index','show']) should yield 2 routes, got %d: %v", len(byID), keysOf(byID)) } if _, ok := byID["http::GET::/tags"]; !ok { t.Errorf("missing index route") } if _, ok := byID["http::GET::/tags/{p1}"]; !ok { t.Errorf("missing show route") } } func TestLaravelResource_ExceptFilter(t *testing.T) { src := []byte(`except(['destroy', 'edit', 'create']); `) ext := &HTTPExtractor{} byID := laravelContractIDs(ext.Extract("routes/web.php", src, nil, nil)) if _, ok := byID["http::DELETE::/items/{p1}"]; ok { t.Errorf("->except must drop the destroy route") } if len(byID) != 4 { t.Errorf("except(destroy,edit,create) should leave 4 routes, got %d: %v", len(byID), keysOf(byID)) } }