Skip to content

Instantly share code, notes, and snippets.

@lockwooddev
Created February 17, 2021 10:01
Show Gist options
  • Save lockwooddev/4a457ed823c30fb511ca025a3e3f2dab to your computer and use it in GitHub Desktop.
Save lockwooddev/4a457ed823c30fb511ca025a3e3f2dab to your computer and use it in GitHub Desktop.
var robots = `
# Group 1
User-agent: Googlebot
Disallow: /nogooglebot/
# Group 2
User-agent: *
Allow: /
Sitemap: http://www.example.com/sitemap.xml
Sitemap: http://www.example.com/sitemap2.xml
`
func TestRobotsClient_Httptest(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, robots)
}))
defer ts.Close()
client := NewRobotsClient()
robotRules, err := client.FetchRobots(ts.URL)
assert.NoError(t, err)
fmt.Println(robotRules)
expectedRobotRules := RobotRules{
rules: []Rule{
{
UserAgents: []string{"Googlebot"},
Disallow: []string{"/nogooglebot/"},
},
{
UserAgents: []string{"*"},
Allow: []string{"/"},
},
},
Sitemaps: []string{
"http://www.example.com/sitemap.xml",
"http://www.example.com/sitemap2.xml",
},
}
assert.Equal(t, expectedRobotRules, robotRules)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment