比基本测试多个循环。。。

package main

import (
	"testing"
	"net/http"
)

const checkMark = " OK! "
const ballotX = " ERROR! "

func TestDownload(t *testing.T) {
	var urls = []struct {
		url 	string
		statusCode 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 be able to make the Get call.", ballotX, err)
				}
				t.Log("\t\tShould be 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)
				}
			}
		}
	}
}

  

最新文章

  1. iOS 阶段学习第十天笔记(字符串操作)
  2. 如何录制手机屏幕并转成gif
  3. WKWebView使用及注意点
  4. [luogu P2647] 最大收益(贪心+dp)
  5. < %=...%>< %#... %>< % %>< %@ %>具体意义
  6. Java_eclipse软件与git配合使用创建git仓库
  7. WPF跨程序集共享样式(跨程序集隔离样式和代码)
  8. erlang mnesia 数据库实现SQL查询
  9. HDU_2057——64位无符号16进制数的运算
  10. 常用几个UITableView,UICollectionView  UIScrollView关键点
  11. 团队作业4——第一次项目冲刺(Alpha版本) 1
  12. git的CentOS服务端安装和windows客户端的使用
  13. Vue.js响应式原理
  14. ASP.NET Core2.2 IExceptionFilter
  15. 泊爷带你学go -- 反射的经典玩法
  16. Mac上通过iterm 上传文件到服务器
  17. 自学Zabbix11.3 Zabbix SNMP 常用OID列表
  18. 终端:Xcode模拟器上安装.app方法
  19. 《FPGA设计技巧与案例开发详解-第二版》全套资料包
  20. 学习笔记:Maven的ArcheType的学习笔记

热门文章

  1. 使用rsyslog编程,产生trace信息,记录到日志中
  2. 洛谷P3966 [TJOI2013]单词(fail树性质)
  3. Kubernetes - Getting Started With Kubeadm
  4. 第01篇 为什么推荐使用String直接赋值
  5. .NET类型转型的四种做法(转)
  6. hdu 4903 The only survival
  7. [Luogu 2590] ZJOI2008 树的统计
  8. 【NOIP】2016 换教室
  9. OPENId是什么, OAUTH 是什么
  10. nodejs入门教程之http的get和request简介及应用