当前位置: 首页>>代码示例>>Golang>>正文


Golang require.New函数代码示例

本文整理汇总了Golang中github.com/stretchr/testify/require.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestUserDocker

func TestUserDocker(t *testing.T) {
	assert := require.New(t)

	config := &CloudConfig{
		Rancher: RancherConfig{
			UserDocker: DockerConfig{
				TLS: true,
			},
		},
	}

	bytes, err := yaml.Marshal(config)
	assert.Nil(err)

	config = NewConfig()
	err = yaml.Unmarshal(bytes, config)
	assert.Nil(err)

	data := make(map[interface{}]map[interface{}]interface{})
	util.Convert(config, data)

	fmt.Println(data)

	val, ok := data["rancher"]["user_docker"]
	assert.True(ok)

	m, ok := val.(map[interface{}]interface{})
	assert.True(ok)
	v, ok := m["tls"]
	assert.True(ok)
	assert.True(v.(bool))

}
开发者ID:rowhit,项目名称:os,代码行数:33,代码来源:config_test.go

示例2: TestAddMetricToMapNewKey

// Tests the flow of AddMetricToMap where the metric name is not present in the map
func TestAddMetricToMapNewKey(t *testing.T) {
	var (
		cluster         = newRealModel(time.Minute)
		metrics         = make(map[string]*daystore.DayStore)
		new_metric_name = "name_not_in_map"
		stamp           = time.Now().Round(cluster.resolution)
		zeroTime        = time.Time{}
		value           = uint64(1234567890)
		assert          = assert.New(t)
		require         = require.New(t)
	)

	// First Call: Add a new metric to the map
	assert.NoError(cluster.addMetricToMap(new_metric_name, stamp, value, metrics))

	// Second Call: Add a second metric to the map on a later time. Flushes previous metric.
	assert.NoError(cluster.addMetricToMap(new_metric_name, stamp.Add(time.Minute), value, metrics))
	new_ts := *metrics[new_metric_name]
	results := new_ts.Hour.Get(zeroTime, zeroTime)
	require.Len(results, 2)
	assert.Equal(results[0].Timestamp, stamp.Add(time.Minute))
	assert.Equal(roundToEpsilon(results[0].Value, defaultEpsilon), roundToEpsilon(value, defaultEpsilon))
	assert.Equal(results[1].Timestamp, stamp)
	assert.Equal(roundToEpsilon(results[1].Value, defaultEpsilon), roundToEpsilon(value, defaultEpsilon))

	// Second Call: addMetricToMap for a new key, cause TimeStore failure
	assert.NoError(cluster.addMetricToMap("other_metric", stamp, value, metrics))
	assert.Error(cluster.addMetricToMap("other_metric", stamp.Add(-time.Minute), value, metrics))
}
开发者ID:MohamedFAhmed,项目名称:heapster,代码行数:30,代码来源:impl_test.go

示例3: Test_Column_MapsSlice

func Test_Column_MapsSlice(t *testing.T) {
	r := require.New(t)

	c1 := columns.ColumnsForStruct(&foo{}, "foo")
	c2 := columns.ColumnsForStruct(&foos{}, "foo")
	r.Equal(c1.String(), c2.String())
}
开发者ID:markbates,项目名称:pop,代码行数:7,代码来源:columns_test.go

示例4: TestGet

func TestGet(t *testing.T) {
	assert := require.New(t)

	data := map[interface{}]interface{}{
		"key": "value",
		"rancher": map[interface{}]interface{}{
			"key2": map[interface{}]interface{}{
				"subkey": "subvalue",
				"subnum": 42,
			},
		},
	}

	tests := map[string]interface{}{
		"key": "value",
		"rancher.key2.subkey":  "subvalue",
		"rancher.key2.subnum":  42,
		"rancher.key2.subkey2": "",
		"foo": "",
	}

	for k, v := range tests {
		assert.Equal(v, getOrSetVal(k, data, nil))
	}
}
开发者ID:rowhit,项目名称:os,代码行数:25,代码来源:config_test.go

示例5: Test_Request_URL_Params

func Test_Request_URL_Params(t *testing.T) {
	r := require.New(t)
	w := willy.New(App())

	req := w.Request("/foo?a=%s&b=%s", "A", "B")
	r.Equal("/foo?a=A&b=B", req.URL)
}
开发者ID:Isted,项目名称:going,代码行数:7,代码来源:willy_test.go

示例6: TestCli

// TestCli runs tests on the zest Cli and SetCli methods.
func TestCli(t *testing.T) {
	a := assert.New(t)
	r := require.New(t)
	zest := New()

	r.NotPanics(func() { _ = zest.Cli() })
	cli := zest.Cli()

	cli.Name = "foobar"
	zest.SetCli(cli)

	r.NotPanics(func() { _ = zest.Cli() })
	cli = zest.Cli()

	a.Equal("foobar", cli.Name)

	zest = Classic() // should also work with the Classic zest

	r.NotPanics(func() { _ = zest.Cli() })
	cli = zest.Cli()

	cli.Name = "foobar"
	zest.SetCli(cli)

	r.NotPanics(func() { _ = zest.Cli() })
	cli = zest.Cli()

	a.Equal("foobar", cli.Name)
}
开发者ID:solher,项目名称:zest,代码行数:30,代码来源:zest_test.go

示例7: TestRegister

// TestRegister runs tests on the syringe Register method.
func TestRegister(t *testing.T) {
	a := assert.New(t)
	r := require.New(t)
	syringe := New()

	deps := []interface{}{
		newDep1,
		newDep2,
	}

	syringe.Register(deps)
	r.NotPanics(func() { _ = syringe.deps[0]; _ = syringe.deps[1] })
	a.IsType(newDep1, syringe.deps[0])
	a.IsType(newDep2, syringe.deps[1])

	syringe.Register(newDep3, newDep4)
	r.NotPanics(func() { _ = syringe.deps[2]; _ = syringe.deps[3] })
	a.IsType(newDep3, syringe.deps[2])
	a.IsType(newDep4, syringe.deps[3])

	syringe.Register(newDep4)
	r.NotPanics(func() { _ = syringe.deps[4] })
	a.IsType(newDep4, syringe.deps[4])

	syringe.Register(newDep4())
	r.NotPanics(func() { _ = syringe.deps[5] })
	a.IsType(&dep4{}, syringe.deps[5])
}
开发者ID:solher,项目名称:syringe,代码行数:29,代码来源:syringe_test.go

示例8: TestIsPrefixHeader

//
//
// Unit TestCases
//
//
func TestIsPrefixHeader(t *testing.T) {
	assert := require.New(t)

	tests := map[string]bool{
		"$":               false,
		"#header 1":       true,
		"# header 1":      true,
		"#######header 7": true,
	}

	p := new(parser)
	for key, value := range tests {
		assert.Equal(p.isPrefixHeader([]byte(key)), value)
	}

	testsExtSpaceHeader := map[string]bool{
		"$":                false,
		"# ":               true,
		"#header 1":        false,
		"####### header 7": false,
		"# header 1":       true,
		"### header 3":     true,
		"# he":             true,
	}
	p1 := new(parser)
	p1.flags |= EXTENSION_SPACE_HEADERS
	for key, value := range testsExtSpaceHeader {
		assert.Equal(p1.isPrefixHeader([]byte(key)), value)
	}
}
开发者ID:datawolf,项目名称:markdown,代码行数:35,代码来源:block_test.go

示例9: TestParseCmdline

func TestParseCmdline(t *testing.T) {
	assert := require.New(t)

	expected := map[interface{}]interface{}{
		"rancher": map[interface{}]interface{}{
			"rescue":   true,
			"key1":     "value1",
			"key2":     "value2",
			"keyArray": []interface{}{int64(1), int64(2)},
			"obj1": map[interface{}]interface{}{
				"key3": "3value",
				"obj2": map[interface{}]interface{}{
					"key4": true,
				},
			},
			"key5": int64(5),
			"key6": "a,b",
			"key7": "a\nb",
		},
	}

	actual := parseCmdline("a b rancher.rescue rancher.keyArray=[1,2] rancher.key1=value1 c rancher.key2=value2 rancher.obj1.key3=3value rancher.obj1.obj2.key4 rancher.key5=5 rancher.key6=a,b rancher.key7=a\nb")

	assert.Equal(expected, actual)
}
开发者ID:carriercomm,项目名称:os,代码行数:25,代码来源:config_test.go

示例10: TestRepo

func TestRepo(t *testing.T) {
	scenarios.Load(tdb.StellarCoreURL(), "base-core.sql")
	assert := assert.New(t)
	require := require.New(t)
	repo := &Repo{DB: tdb.StellarCore()}

	var count int
	err := repo.GetRaw(&count, "SELECT COUNT(*) FROM txhistory")
	assert.NoError(err)
	assert.Equal(4, count)

	var ids []string
	err = repo.SelectRaw(&ids, "SELECT txid FROM txhistory")
	assert.NoError(err)
	assert.Len(ids, 4)

	ret, err := repo.ExecRaw("DELETE FROM txhistory")
	assert.NoError(err)
	deleted, err := ret.RowsAffected()
	assert.NoError(err)
	assert.Equal(int64(4), deleted)

	// Test args
	var hash string
	err = repo.GetRaw(&hash, "SELECT prevhash FROM ledgerheaders WHERE ledgerseq = ?", 1)
	assert.NoError(err)
	assert.Equal("0000000000000000000000000000000000000000000000000000000000000000", hash)

	// Test NoRows
	err = repo.GetRaw(&hash, "SELECT prevhash FROM ledgerheaders WHERE ledgerseq = ?", 100)
	assert.True(repo.NoRows(err))

	// Test transactions
	require.NoError(repo.Begin(), "begin failed")
	err = repo.GetRaw(&count, "SELECT COUNT(*) FROM ledgerheaders")
	assert.NoError(err)
	assert.Equal(3, count)
	_, err = repo.ExecRaw("DELETE FROM ledgerheaders")
	assert.NoError(err)
	err = repo.GetRaw(&count, "SELECT COUNT(*) FROM ledgerheaders")
	assert.NoError(err)
	assert.Equal(0, count, "Ledgers did not appear deleted inside transaction")
	assert.NoError(repo.Rollback(), "rollback failed")

	// Ensure commit works
	require.NoError(repo.Begin(), "begin failed")
	repo.ExecRaw("DELETE FROM ledgerheaders")
	assert.NoError(repo.Commit(), "commit failed")
	err = repo.GetRaw(&count, "SELECT COUNT(*) FROM ledgerheaders")
	assert.NoError(err)
	assert.Equal(0, count)

	// ensure that selecting into a populated slice clears the slice first
	scenarios.Load(tdb.StellarCoreURL(), "base-core.sql")
	require.Len(ids, 4, "ids slice was not preloaded with data")
	err = repo.SelectRaw(&ids, "SELECT txid FROM txhistory limit 2")
	assert.NoError(err)
	assert.Len(ids, 2)

}
开发者ID:irisli,项目名称:horizon,代码行数:60,代码来源:repo_test.go

示例11: Test_WillieSessions

func Test_WillieSessions(t *testing.T) {
	r := require.New(t)
	w := willie.New(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
		defer context.Clear(req)
		sess, _ := Store.Get(req, "my-session")
		t := sess.Values["foo"]
		fmt.Printf("t: %s\n", t)
		if t != nil {
			res.WriteHeader(200)
			fmt.Fprint(res, t)
		} else {
			sess.Values["foo"] = "bar"
			sess.Save(req, res)
			res.WriteHeader(201)
			fmt.Fprint(res, "setting session")
		}
	}))

	res := w.Get("/", nil)
	r.Equal(201, res.Code)
	r.Equal("setting session", res.Body.String())

	res = w.Get("/", nil)
	r.Equal(200, res.Code)
	r.Equal("bar", res.Body.String())
}
开发者ID:ryanzec,项目名称:going,代码行数:26,代码来源:willie_test.go

示例12: TestTests_Detail_OK

func TestTests_Detail_OK(t *testing.T) {
	assert := assert.New(t)
	require := require.New(t)

	c := &fakeAPIClient{
		fixture: "tests_detail_ok.json",
	}
	tt := newTests(c)

	test, err := tt.Detail(1234)
	require.Nil(err)

	assert.Equal("/Tests/Details", c.sentRequestPath)
	assert.Equal("GET", c.sentRequestMethod)
	assert.Equal(url.Values{"TestID": {"1234"}}, c.sentRequestValues)

	assert.Equal(test.TestID, 6735)
	assert.Equal(test.TestType, "HTTP")
	assert.Equal(test.Paused, false)
	assert.Equal(test.WebsiteName, "NL")
	assert.Equal(test.ContactID, 536)
	assert.Equal(test.Status, "Up")
	assert.Equal(test.Uptime, 0.0)
	assert.Equal(test.CheckRate, 60)
	assert.Equal(test.Timeout, 40)
	assert.Equal(test.LogoImage, "")
	assert.Equal(test.WebsiteHost, "Various")
	assert.Equal(test.FindString, "")
	assert.Equal(test.DoNotFind, false)
}
开发者ID:jen20,项目名称:statuscake,代码行数:30,代码来源:tests_test.go

示例13: Test_Client_Save_MultiHost

func Test_Client_Save_MultiHost(t *testing.T) {
	r := require.New(t)

	ms := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		s := SimpleSaveable{Message: "Primary"}
		json.NewEncoder(w).Encode(s)
		w.WriteHeader(200)
	}))
	defer ms.Close()
	ss := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		s := SimpleSaveable{Message: "Slave"}
		json.NewEncoder(w).Encode(s)
		w.WriteHeader(404)
	}))
	defer ms.Close()

	c, err := client.New([]*client.Host{
		{URL: ms.URL, Primary: true},
		{URL: ss.URL},
	})
	r.NoError(err)

	s := &SimpleSaveable{}
	res, err := c.Save(s)
	r.NoError(err)
	r.Equal(200, res.StatusCode)
	r.Equal("Primary", s.Message)
}
开发者ID:li-ang,项目名称:enterprise-client,代码行数:28,代码来源:client_test.go

示例14: Test_New_RespectsPrimary

func Test_New_RespectsPrimary(t *testing.T) {
	r := require.New(t)
	c, err := client.New([]*client.Host{{}, {Primary: true}})
	r.NoError(err)
	r.False(c.Hosts[0].Primary)
	r.True(c.Hosts[1].Primary)
}
开发者ID:li-ang,项目名称:enterprise-client,代码行数:7,代码来源:client_test.go

示例15: TestSoftRequirementsValidationSuccess

func TestSoftRequirementsValidationSuccess(t *testing.T) {
	req := require.New(t)
	tempDir, err := ioutil.TempDir("", "")
	req.NoError(err)
	req.NoError(ioutil.WriteFile(path.Join(tempDir, "cpu.cfs_period_us"), []byte("0"), os.ModePerm))
	req.NoError(ioutil.WriteFile(path.Join(tempDir, "cpu.cfs_quota_us"), []byte("0"), os.ModePerm))
	mountInt := &fakeMountInterface{
		[]mount.MountPoint{
			{
				Device: "cgroup",
				Type:   "cgroup",
				Opts:   []string{"rw", "relatime", "cpuset"},
			},
			{
				Device: "cgroup",
				Type:   "cgroup",
				Opts:   []string{"rw", "relatime", "cpu"},
				Path:   tempDir,
			},
			{
				Device: "cgroup",
				Type:   "cgroup",
				Opts:   []string{"rw", "relatime", "cpuacct", "memory"},
			},
		},
	}
	f, err := validateSystemRequirements(mountInt)
	assert.NoError(t, err)
	assert.True(t, f.cpuHardcapping, "cpu hardcapping is expected to be enabled")
}
开发者ID:XbinZh,项目名称:kubernetes,代码行数:30,代码来源:container_manager_linux_test.go


注:本文中的github.com/stretchr/testify/require.New函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。