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


Golang assert.NotContains函数代码示例

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


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

示例1: TestLoggingStatements

func TestLoggingStatements(t *testing.T) {
	output := new(bytes.Buffer)
	l := New()
	l.Logger.Formatter.(*logrus.TextFormatter).DisableColors = true
	l.Logger.Out = output

	// level defaults to warn
	l.Debug("debug")
	l.Info("info")
	l.Warn("warn")

	assert.NotContains(t, output.String(), "level=info")
	assert.NotContains(t, output.String(), "level=debug")
	assert.Contains(t, output.String(), "level=warn")

	// when on debug level, all statements are logged
	output.Reset()
	assert.Empty(t, output.String())
	l.Logger.Level = logrus.DebugLevel
	l.Debug("1")
	l.Info("1")
	l.Warn("1")
	l.Error("1")
	assert.Contains(t, output.String(), "level=debug")
	assert.Contains(t, output.String(), "level=info")
	assert.Contains(t, output.String(), "level=warn")
	assert.Contains(t, output.String(), "level=error")
	assert.Panics(t, func() {
		l.Panic("boom")
	}, "Calling Panic() should panic")
	assert.Contains(t, output.String(), "level=panic")
}
开发者ID:stellar,项目名称:bridge-server,代码行数:32,代码来源:main_test.go

示例2: test

func test(l *Logger, t *testing.T) {
	b := new(bytes.Buffer)
	l.SetOutput(b)
	l.DisableColor()
	l.SetLevel(WARN)

	l.Print("print")
	l.Printf("print%s", "f")
	l.Debug("debug")
	l.Debugf("debug%s", "f")
	l.Info("info")
	l.Infof("info%s", "f")
	l.Warn("warn")
	l.Warnf("warn%s", "f")
	l.Error("error")
	l.Errorf("error%s", "f")

	assert.Contains(t, b.String(), "print\n")
	assert.Contains(t, b.String(), "\nprintf\n")
	assert.NotContains(t, b.String(), "debug")
	assert.NotContains(t, b.String(), "debugf")
	assert.NotContains(t, b.String(), "info")
	assert.NotContains(t, b.String(), "infof")
	assert.Contains(t, b.String(), "level=WARN, prefix="+l.prefix)
	assert.Contains(t, b.String(), "level=WARN, prefix="+l.prefix)
	assert.Contains(t, b.String(), "level=ERROR, prefix="+l.prefix)
	assert.Contains(t, b.String(), "level=ERROR, prefix="+l.prefix)
}
开发者ID:nlamirault,项目名称:abraracourcix,代码行数:28,代码来源:log_test.go

示例3: TestDefaultLogging

func TestDefaultLogging(t *testing.T) {
	outputBuf := new(bytes.Buffer)
	logBuf := new(bytes.Buffer)
	LogHandle = logBuf
	OutHandle = outputBuf

	SetLogThreshold(LevelWarn)
	SetStdoutThreshold(LevelError)

	FATAL.Println("fatal err")
	CRITICAL.Println("critical err")
	ERROR.Println("an error")
	WARN.Println("a warning")
	INFO.Println("information")
	DEBUG.Println("debugging info")

	assert.Contains(t, logBuf.String(), "fatal err")
	assert.Contains(t, logBuf.String(), "critical err")
	assert.Contains(t, logBuf.String(), "an error")
	assert.Contains(t, logBuf.String(), "a warning")
	assert.NotContains(t, logBuf.String(), "information")
	assert.NotContains(t, logBuf.String(), "debugging info")

	assert.Contains(t, outputBuf.String(), "fatal err")
	assert.Contains(t, outputBuf.String(), "critical err")
	assert.Contains(t, outputBuf.String(), "an error")
	assert.NotContains(t, outputBuf.String(), "a warning")
	assert.NotContains(t, outputBuf.String(), "information")
	assert.NotContains(t, outputBuf.String(), "debugging info")
}
开发者ID:aktuba,项目名称:centrifugo,代码行数:30,代码来源:logger_test.go

示例4: TestListClustersWithSecrets

func TestListClustersWithSecrets(t *testing.T) {
	ts := newTestServer(t)
	defer ts.Stop()
	r, err := ts.Client.ListClusters(context.Background(), &api.ListClustersRequest{})
	assert.NoError(t, err)
	assert.Empty(t, r.Clusters)

	policy := api.AcceptancePolicy{Policies: []*api.AcceptancePolicy_RoleAdmissionPolicy{{Secret: &api.AcceptancePolicy_RoleAdmissionPolicy_Secret{Alg: "bcrypt", Data: []byte("secret")}}}}

	createCluster(t, ts, "id1", "name1", policy, ts.Server.rootCA)
	r, err = ts.Client.ListClusters(context.Background(), &api.ListClustersRequest{})
	assert.NoError(t, err)
	assert.Equal(t, 1, len(r.Clusters))

	createCluster(t, ts, "id2", "name2", policy, ts.Server.rootCA)
	createCluster(t, ts, "id3", "name3", policy, ts.Server.rootCA)
	r, err = ts.Client.ListClusters(context.Background(), &api.ListClustersRequest{})
	assert.NoError(t, err)
	assert.Equal(t, 3, len(r.Clusters))
	for _, cluster := range r.Clusters {
		assert.NotContains(t, cluster.String(), policy.Policies[0].Secret)
		assert.NotContains(t, cluster.String(), "PRIVATE")
		assert.NotNil(t, cluster.Spec.AcceptancePolicy.Policies[0].Secret.Data)
	}
}
开发者ID:yongtang,项目名称:swarmkit,代码行数:25,代码来源:cluster_test.go

示例5: test

func test(l *Logger, t *testing.T) {
	b := new(bytes.Buffer)
	l.SetOutput(b)
	l.DisableColor()
	l.SetLevel(WARN)

	l.Print("print")
	l.Printf("print%s", "f")
	l.Debug("debug")
	l.Debugf("debug%s", "f")
	l.Info("info")
	l.Infof("info%s", "f")
	l.Warn("warn")
	l.Warnf("warn%s", "f")
	l.Error("error")
	l.Errorf("error%s", "f")

	assert.Contains(t, b.String(), "print\n")
	assert.Contains(t, b.String(), "\nprintf\n")
	assert.NotContains(t, b.String(), "debug")
	assert.NotContains(t, b.String(), "debugf")
	assert.NotContains(t, b.String(), "info")
	assert.NotContains(t, b.String(), "infof")
	assert.Contains(t, b.String(), `"level":"WARN","prefix":"`+l.prefix+`"`)
	assert.Contains(t, b.String(), `"message":"warn"`)
	assert.Contains(t, b.String(), `"level":"ERROR","prefix":"`+l.prefix+`"`)
	assert.Contains(t, b.String(), `"message":"errorf"`)
}
开发者ID:eurie-inc,项目名称:echo-sample,代码行数:28,代码来源:log_test.go

示例6: TestPublicVariables

func TestPublicVariables(t *testing.T) {
	v1 := BuildVariable{"key", "value", false}
	v2 := BuildVariable{"public", "value", true}
	v3 := BuildVariable{"private", "value", false}
	all := BuildVariables{v1, v2, v3}
	public := all.Public()
	assert.Contains(t, public, v2)
	assert.NotContains(t, public, v1)
	assert.NotContains(t, public, v3)
}
开发者ID:mikew,项目名称:gitlab-ci-multi-runner,代码行数:10,代码来源:variables_test.go

示例7: TestStdLogger

func TestStdLogger(t *testing.T) {

	var buf bytes.Buffer

	sl := log.NewStdLogger(
		log.SetStdLevel(log.StdLevelTrace),
		log.SetStdTrace(&buf, "TEST-TRACE ", std.LstdFlags),
		log.SetStdDebug(&buf, "TEST-DEBUG ", std.LstdFlags),
		log.SetStdInfo(&buf, "TEST-INFO ", std.LstdFlags),
		log.SetStdWarn(&buf, "TEST-WARN ", std.LstdFlags),
		log.SetStdError(&buf, "TEST-ERROR ", std.LstdFlags),
		log.SetStdFatal(&buf, "TEST-FATAL ", std.LstdFlags),
	)
	sl.SetLevel(log.StdLevelInfo)
	assert.False(t, sl.IsTrace())
	assert.False(t, sl.IsDebug())
	assert.True(t, sl.IsInfo())
	assert.True(t, sl.IsWarn())

	sl.Trace("my trace1")
	sl.Trace("my trace2", "int", 29)
	sl.Debug("my Debug", "float", 3.14152)
	sl.Debug("my Debug2", 2.14152)
	sl.Info("InfoTEST")
	sl.Warn("WarnTEST")
	haveErr := sl.Error("ErrorTEST", "err1a", 1, "err2", 32.4232)
	assert.Contains(t, "ErrorTEST53", sl.Error("ErrorTEST53").Error())
	logs := buf.String()

	assert.EqualError(t, haveErr, "ErrorTEST")
	assert.Contains(t, logs, "InfoTEST")
	assert.Contains(t, logs, "WarnTEST")
	assert.Contains(t, logs, "ErrorTEST")
	assert.NotContains(t, logs, "trace1")
	assert.NotContains(t, logs, "Debug2")

	buf.Reset()
	sl.SetLevel(log.StdLevelTrace)
	assert.True(t, sl.IsTrace())
	assert.True(t, sl.IsDebug())
	assert.True(t, sl.IsInfo())
	assert.True(t, sl.IsWarn())
	sl.Trace("my trace1")
	sl.Trace("my trace2", "int", 29)
	sl.Debug("my Debug", "float", 3.14152)
	sl.Debug("my Debug2", 2.14152)
	sl.Info("InfoTEST")

	logs = buf.String()

	assert.Contains(t, logs, "InfoTEST")
	assert.Contains(t, logs, "trace1")
	assert.Contains(t, logs, "Debug2")

}
开发者ID:hafeez3000,项目名称:csfw,代码行数:55,代码来源:stdLib_test.go

示例8: TestAutoTag

func TestAutoTag(t *testing.T) {
	c := newConfig()
	c.Hostname = "cb01.test.localdomain"
	tags := c.GetTags()
	assert.Len(t, tags, 2)
	assert.NotContains(t, tags, "cb01")
	assert.NotContains(t, tags, "cb")
	assert.Contains(t, tags, "test")
	assert.Contains(t, tags, "localdomain")
	assert.NotContains(t, tags, "")
}
开发者ID:RobinUS2,项目名称:indispenso,代码行数:11,代码来源:conf_test.go

示例9: TestLogLevelError

func TestLogLevelError(t *testing.T) {
	stdout, stderr := captureOutputs(func() {
		logger := NewLogger(LEVEL_ERROR)
		logger.Debug("DEBUG", "some debug log")
		logger.Info("INFO", "some info log")
		logger.Error("ERROR", "some error log")
	})

	assert.NotContains(t, string(stdout), "DEBUG")
	assert.NotContains(t, string(stdout), "INFO")
	assert.Contains(t, string(stderr), "ERROR")
}
开发者ID:reneedv,项目名称:bosh,代码行数:12,代码来源:logger_test.go

示例10: TestDiff

// TestDiff tests the diff.go source file
func TestDiff(t *testing.T) {
	cmp := CompareStringLists([]string{"a", "b", "b", "a"}, []string{"a", "c"})
	assert.Len(t, cmp, 1)
	assert.NotContains(t, cmp, "a")
	assert.Contains(t, cmp, "b")

	cmp = CompareStringListsInBoth([]string{"a", "a", "b", "c"}, []string{"a", "c", "c"})
	assert.Len(t, cmp, 2)
	assert.NotContains(t, cmp, "b")
	assert.Contains(t, cmp, "a")
	assert.Contains(t, cmp, "c")
}
开发者ID:robinjha,项目名称:clair,代码行数:13,代码来源:utils_test.go

示例11: TestPrepareAttributes

func TestPrepareAttributes(t *testing.T) {
	prepared := prepareAttributes(Attributes{
		"v":         "asd",
		"id":        "test",
		"attr":      "value",
		"name":      "value",
		"forbidden": "value",
	}, []string{"name", "forbidden"})
	assert.Contains(t, prepared, " v=\"asd\"", "")
	assert.Contains(t, prepared, " id=\"test\"", "")
	assert.Contains(t, prepared, " attr=\"value\"", "")
	assert.NotContains(t, prepared, " name=\"value\"", "")
	assert.NotContains(t, prepared, " forbidden=\"value\"", "")
}
开发者ID:Alkemic,项目名称:forms,代码行数:14,代码来源:helpers_test.go

示例12: TestSitemap_AddEntry

func TestSitemap_AddEntry(t *testing.T) {
	sitemap := NewSitemap()
	sitemap.AddEntry("http://foo.bar/1", "http://foo.bar", false)
	sitemap.AddEntry("http://foo.bar/2", "http://foo.bar", false)
	sitemap.AddEntry("http://foo.bar/3", "http://foo.bar/1", true)

	assert.Contains(t, sitemap.entries, "http://foo.bar")
	assert.Contains(t, sitemap.entries, "http://foo.bar/1")
	assert.NotContains(t, sitemap.entries, "http://foo.bar/2")
	assert.NotContains(t, sitemap.entries, "http://foo.bar/3")

	assert.Contains(t, sitemap.entries["http://foo.bar"], "http://foo.bar/1")
	assert.Contains(t, sitemap.entries["http://foo.bar"], "http://foo.bar/2")
	assert.Contains(t, sitemap.entries["http://foo.bar/1"], "http://foo.bar/3")
}
开发者ID:alexmic,项目名称:sitemapper,代码行数:15,代码来源:crawl_test.go

示例13: TestVersionMiddleware

// Ensure that version validation middleware passes through request
// on a valid version, and returns a 400 on an invalid version.
func TestVersionMiddleware(t *testing.T) {
	assert := assert.New(t)

	api := NewAPI(&Configuration{})
	handler := new(MockResourceHandler)
	handler.On("Authenticate").Return(nil)
	handler.On("ValidVersions").Return([]string{"1"})
	handler.On("Rules").Return(&rules{})
	handler.On("ResourceName").Return("widgets")
	handler.On("ReadResourceList").Return([]Resource{"foo"}, "", nil)

	api.RegisterResourceHandler(handler)

	// Valid version
	req, _ := http.NewRequest("GET", "http://example.com/api/v1/widgets", nil)
	w := httptest.NewRecorder()
	api.ServeHTTP(w, req)
	assert.Equal(w.Code, 200)
	assert.Contains(w.Body.String(), "foo")

	// Invalid version
	req, _ = http.NewRequest("GET", "http://example.com/api/v2/widgets", nil)
	w = httptest.NewRecorder()
	api.ServeHTTP(w, req)
	assert.Equal(w.Code, http.StatusBadRequest)
	assert.NotContains(w.Body.String(), "foo")
}
开发者ID:Workiva,项目名称:go-rest,代码行数:29,代码来源:api_test.go

示例14: TestIncomingReplication

func TestIncomingReplication(t *testing.T) {
	if testing.Short() {
		t.Skip()
	}

	rep := createMockupReplication()
	close(rep.(*mockupReplication).syncChan) //Make sure no deadlock occur

	ns := auth.NamespaceFrom("ns1")

	r := newInMemoryRegistry(nil, rep)
	assert.NotContains(t, r.(*inMemoryRegistry).namespaces, ns)

	inst := newServiceInstance("Calc1", "192.168.0.1", 9080)
	payload, _ := json.Marshal(inst)
	data, _ := json.Marshal(&replicatedMsg{RepType: REGISTER, Payload: payload})
	rep.(*mockupReplication).NotifyChannel <- &replication.InMessage{cluster.MemberID("192.1.1.3:6100"), ns, data}

	catalog, err := r.GetCatalog(auth.NamespaceFrom("ns1"))

	// NOTICE, it may fail, since a race between the registry and the test...
	time.Sleep(time.Duration(5) * time.Second)

	assert.NoError(t, err)

	instances1, err1 := catalog.List("Calc1", protocolPredicate)
	assert.NoError(t, err1)
	assert.Len(t, instances1, 1)
}
开发者ID:charshy,项目名称:registry,代码行数:29,代码来源:in_memory_registry_test.go

示例15: TestServerHelp

func TestServerHelp(t *testing.T) {
	x := runFull(t, "hyperkube test1 --help")
	assert.NoError(t, x.err)
	assert.Contains(t, x.output, "A simple server named test1")
	assert.Contains(t, x.output, "-h, --help                                         help for hyperkube")
	assert.NotContains(t, x.output, "test1 Run")
}
开发者ID:simonswine,项目名称:kubernetes,代码行数:7,代码来源:hyperkube_test.go


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