More loops than basic testing ...
Package Mainimport ("Testing" "Net/http") const Checkmark = "ok!" Const BALLOTX = "error!" Func testdownload (t *testing. T) {var urls = []struct {URL stringstatuscode int}{{"http://localhost:8000/test.html", http. statusok,},{"HTTP://LOCALHOST:8000/TEST.HTML2", http. Statusnotfound,},}t.log ("Given the need to test downloading content.") {for _, U: = Range URLs {t.logf ("\twhen checking \"%s\ "for status code \"%d\ "", U.url, U.statuscode) {resp, err: = http. Get (U.url) if err! = Nil {t.fatal ("\tshould is able to make the get call.", Ballotx, Err)}t.log ("\t\tshould is able to make The Get call. ", checkmark) Defer resp. Body.close () If Resp. StatusCode = = U.statuscode {T.LOGF ("\t\tshould receive a \"%d\ "status,%v", U.statuscode, Checkmark)} else {T.errorf ("\t\ Tshould receive a \ "%d\" status. %v%v ", U.statuscode, Ballotx, resp. StatusCode)}}}}
Go Language Table Group Test example