func FilterTestsBasedOnDiscoveryEndpoints(scripts Scripts, endpoints []discovery.ModelEndpoint, regPaths []PathRegex) (Scripts, error) {
	lookupMap := make(map[string]bool)
	var filteredScripts []Script

	for _, ep := range endpoints {
		for _, regPath := range regPaths {
			matched, err := regexp.MatchString(regPath.Regex, ep.Path)
			if err != nil {
				continue
			}
			if matched {
				lookupMap[regPath.Regex] = true
			}
		}
	}

	for k := range lookupMap {
		for _, scr := range scripts.Scripts {
			stripped := strings.Replace(scr.URI, "$", "", -1) // only works with a single character
			if strings.Contains(stripped, "foobar") {         //exceptions
				noFoobar := strings.Replace(stripped, "/foobar", "", -1) // only works with a single character
				matched, err := regexp.MatchString(k, noFoobar)
				if err != nil {
					continue
				}
				if matched {
					if !contains(filteredScripts, scr) {
						filteredScripts = append(filteredScripts, scr)
					}
				}

				if scr.URI == "/foobar" {
					if !contains(filteredScripts, scr) {
						filteredScripts = append(filteredScripts, scr)
					}
					continue
				}
			}

			matched, err := regexp.MatchString(k, stripped)
			if err != nil {
				continue
			}
			if matched {
				if !contains(filteredScripts, scr) {
					filteredScripts = append(filteredScripts, scr)
				}
			}
		}
	}
	result := Scripts{Scripts: filteredScripts}
	sort.Slice(result.Scripts, func(i, j int) bool { return result.Scripts[i].ID < result.Scripts[j].ID })

	return result, nil
}
// FilterTestsBasedOnDiscoveryEndpoints returns a subset of the first `scripts` parameter, thus filtering `scripts`.
// Filtering is performed by matching (via `regPaths` regex's) the provided `endpoints` against the provided `scripts`.
// The result is: For each path in the collection of scripts returned, there is at least one matching path in the `endpoint`
// list.
FilterTestsBasedOnDiscoveryEndpoints returns a subset of the first `scripts` parameter, thus filtering `scripts`.
Filtering is performed by matching (via `regPaths` regex's) the provided `endpoints` against the provided `scripts`.
The result is: For each path in the collection of scripts returned, there is at least one matching path in the `endpoint`
list.
// FilterTestsBasedOnDiscoveryEndpoints returns a subset of the first ` scripts ` parameter thus filtering ` scripts ` . // Filtering is performed by matching ( via ` regPaths ` regex ' s ) the provided ` endpoints ` against the provided ` scripts ` . // The result is : For each path in the collection of scripts returned there is at least one matching path in the ` endpoint ` // list .
func FilterTestsBasedOnDiscoveryEndpoints(scripts Scripts, endpoints []discovery.ModelEndpoint, regPaths []PathRegex) (Scripts, error) {
	lookupMap := make(map[string]bool)
	var filteredScripts []Script
	for _, ep := range endpoints {
		for _, regPath := range regPaths {
			matched, err := regexp.MatchString(regPath.Regex, ep.Path)
			if err != nil {
				continue
			}
			if matched {
				lookupMap[regPath.Regex] = true
			}
		}
	}
	for k := range lookupMap {
		for _, scr := range scripts.Scripts {
			stripped := strings.Replace(scr.URI, "$", "", -1) 
			if strings.Contains(stripped, "foobar") {         
				noFoobar := strings.Replace(stripped, "/foobar", "", -1) 
				matched, err := regexp.MatchString(k, noFoobar)
				if err != nil {
					continue
				}
				if matched {
					if !contains(filteredScripts, scr) {
						filteredScripts = append(filteredScripts, scr)
					}
				}
				if scr.URI == "/foobar" {
					if !contains(filteredScripts, scr) {
						filteredScripts = append(filteredScripts, scr)
					}
					continue
				}
			}
			matched, err := regexp.MatchString(k, stripped)
			if err != nil {
				continue
			}
			if matched {
				if !contains(filteredScripts, scr) {
					filteredScripts = append(filteredScripts, scr)
				}
			}
		}
	}
	result := Scripts{Scripts: filteredScripts}
	sort.Slice(result.Scripts, func(i, j int) bool { return result.Scripts[i].ID < result.Scripts[j].ID })
	return result, nil
}
func FilterTestsBasedOnDiscoveryEndpoints ( scripts Scripts , endpoints [ ] discovery . ModelEndpoint , regPaths [ ] PathRegex ) ( Scripts , error ) { lookupMap := make ( map [ string ] bool ) var filteredScripts [ ] Script for _ , ep := range endpoints { for _ , regPath := range regPaths { matched , err := regexp . MatchString ( regPath . Regex , ep . Path ) if err != nil { continue } if matched { lookupMap [ regPath . Regex ] = true } } } for k := range lookupMap { for _ , scr := range scripts . Scripts { stripped := strings . Replace ( scr . URI , " " , " " , - 1 ) if strings . Contains ( stripped , " " ) { noFoobar := strings . Replace ( stripped , " " , " " , - 1 ) matched , err := regexp . MatchString ( k , noFoobar ) if err != nil { continue } if matched { if ! contains ( filteredScripts , scr ) { filteredScripts = append ( filteredScripts , scr ) } } if scr . URI == " " { if ! contains ( filteredScripts , scr ) { filteredScripts = append ( filteredScripts , scr ) } continue } } matched , err := regexp . MatchString ( k , stripped ) if err != nil { continue } if matched { if ! contains ( filteredScripts , scr ) { filteredScripts = append ( filteredScripts , scr ) } } } } result := Scripts { Scripts : filteredScripts } sort . Slice ( result . Scripts , func ( i , j int ) bool { return result . Scripts [ i ] . ID < result . Scripts [ j ] . ID } ) return result , nil }
FilterTestsBasedOnDiscoveryEndpoints returns a subset of the first `scripts` parameter, thus filtering `scripts`.
FilterTestsBasedOnDiscoveryEndpoints returns a subset of the first ` scripts ` parameter thus filtering ` scripts ` .
// only works with a single character //exceptions // only works with a single character