47 lines
666 B
Go
47 lines
666 B
Go
|
package server_test
|
||
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"os"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
// Route represents a single line in the test data.
|
||
|
type Route struct {
|
||
|
Method string
|
||
|
Path string
|
||
|
}
|
||
|
|
||
|
// loadRoutes loads all routes from a text file.
|
||
|
func loadRoutes(filePath string) []Route {
|
||
|
var routes []Route
|
||
|
f, err := os.Open(filePath)
|
||
|
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
|
||
|
defer f.Close()
|
||
|
reader := bufio.NewReader(f)
|
||
|
|
||
|
for {
|
||
|
line, err := reader.ReadString('\n')
|
||
|
|
||
|
if line != "" {
|
||
|
line = strings.TrimSpace(line)
|
||
|
parts := strings.Split(line, " ")
|
||
|
|
||
|
routes = append(routes, Route{
|
||
|
Method: parts[0],
|
||
|
Path: parts[1],
|
||
|
})
|
||
|
}
|
||
|
|
||
|
if err != nil {
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return routes
|
||
|
}
|