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


Golang assert.Regexp函数代码示例

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


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

示例1: TestCreateFeed

func TestCreateFeed(t *testing.T) {
	feedTitle := fmt.Sprintf("test-feed-%d", rand.Intn(1000000000))
	url := _url("/feeds/" + feedTitle)

	res, err := http.Get(url)
	require.Nil(t, err)
	require.Equal(t, res.StatusCode, 404)

	entryStr := "<entry><title>foo</title><content>bar</content></entry>"
	buf := bytes.NewBufferString(entryStr)
	res, err = http.Post(url, "application/atom+xml", buf)
	require.Nil(t, err)
	require.Equal(t, res.StatusCode, 201, "created feed")

	res, err = http.Get(url)
	require.Nil(t, err)
	require.Equal(t, res.StatusCode, 200, "got feed")

	feed, err := atom.DecodeFeed(res.Body)
	require.Nil(t, err, "parsed feed")
	assert.Equal(t, feed.Title.Raw, feedTitle, "feed title")
	require.NotNil(t, feed.Updated, "feed.updated")
	assert.Regexp(t, timeRe, *feed.Updated, "feed.updated")

	require.Equal(t, len(feed.Entries), 1, "got 1 entry")
	entry := feed.Entries[0]
	assert.Equal(t, entry.Content.Raw, "bar", "entry content")
	require.NotNil(t, entry.Updated, "entry.updated")
	assert.Regexp(t, timeRe, *entry.Updated, "entry.updated")
}
开发者ID:ironcamel,项目名称:go.atompub,代码行数:30,代码来源:atompub_test.go

示例2: TestRecognizesDateStringAboveQuote

func TestRecognizesDateStringAboveQuote(t *testing.T) {
	e := email(t, "email_1_4")

	assert.Regexp(t, regexp.MustCompile(`^Awesome`), e.Fragments[0].String())
	assert.Regexp(t, regexp.MustCompile(`(?m)^On`), e.Fragments[1].String())
	assert.Regexp(t, regexp.MustCompile(`Loader`), e.Fragments[1].String())
}
开发者ID:recapco,项目名称:emailreplyparser,代码行数:7,代码来源:email_test.go

示例3: TestLoggly

func TestLoggly(t *testing.T) {
	var buf bytes.Buffer
	var result map[string]interface{}
	loggly := loggly.New("token not required")
	loggly.Writer = &buf
	lw := logglyErrorWriter{client: loggly}
	golog.SetOutputs(lw, nil)
	log := golog.LoggerFor("test")

	log.Error("")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Regexp(t, regexp.MustCompile("logging_test.go:([0-9]+)"), result["message"])
	}

	buf.Reset()
	log.Error("short message")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Regexp(t, regexp.MustCompile("logging_test.go:([0-9]+) short message"), result["message"])
	}

	buf.Reset()
	log.Error("message with: reason")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Regexp(t, "logging_test.go:([0-9]+) message with: reason", result["message"])
	}

	buf.Reset()
	log.Error("deep reason: message with: reason")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Equal(t, "message with: reason", result["message"], "message should be last 2 chunks")
	}

	buf.Reset()
	log.Error("deep reason: an url https://a.com in message: reason")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "an url https://a.com in message: reason", result["message"], "should not truncate url")
	}

	buf.Reset()
	log.Error("deep reason: an url 127.0.0.1:8787 in message: reason")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Equal(t, "an url 127.0.0.1:8787 in message: reason", result["message"], "should not truncate url")
	}

	buf.Reset()
	longPrefix := "message with: really l"
	longMsg := longPrefix + strings.Repeat("o", 100) + "ng reason"
	log.Error(longMsg)
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])

		assert.Regexp(t, regexp.MustCompile("logging_test.go:([0-9]+) "+longPrefix+"(o+)"), result["message"])
		assert.Equal(t, 100, len(result["message"].(string)))
	}
}
开发者ID:Christeefym,项目名称:lantern,代码行数:60,代码来源:logging_test.go

示例4: TestDealsWithMultilineReplyHeaders

func TestDealsWithMultilineReplyHeaders(t *testing.T) {
	e := email(t, "email_1_6")

	assert.Regexp(t, regexp.MustCompile(`^I get`), e.Fragments[0].String())
	assert.Regexp(t, regexp.MustCompile(`(?m)^On`), e.Fragments[1].String())
	assert.Regexp(t, regexp.MustCompile(`Was this`), e.Fragments[1].String())
}
开发者ID:recapco,项目名称:emailreplyparser,代码行数:7,代码来源:email_test.go

示例5: TestUploadOrderMulti

func TestUploadOrderMulti(t *testing.T) {
	s, ops, args := loggingSvc()
	resp, err := s3manager.Upload(s, &s3manager.UploadInput{
		Bucket:               aws.String("Bucket"),
		Key:                  aws.String("Key"),
		Body:                 bytes.NewReader(buf12MB),
		ServerSideEncryption: aws.String("AES256"),
		ContentType:          aws.String("content/type"),
	}, nil)

	assert.NoError(t, err)
	assert.Equal(t, []string{"CreateMultipartUpload", "UploadPart", "UploadPart", "UploadPart", "CompleteMultipartUpload"}, *ops)
	assert.Equal(t, "https://location", resp.Location)
	assert.Equal(t, "UPLOAD-ID", resp.UploadID)

	// Validate input values

	// UploadPart
	assert.Equal(t, "UPLOAD-ID", val((*args)[1], "UploadID"))
	assert.Equal(t, "UPLOAD-ID", val((*args)[2], "UploadID"))
	assert.Equal(t, "UPLOAD-ID", val((*args)[3], "UploadID"))

	// CompleteMultipartUpload
	assert.Equal(t, "UPLOAD-ID", val((*args)[4], "UploadID"))
	assert.Equal(t, int64(1), val((*args)[4], "MultipartUpload.Parts[0].PartNumber"))
	assert.Equal(t, int64(2), val((*args)[4], "MultipartUpload.Parts[1].PartNumber"))
	assert.Equal(t, int64(3), val((*args)[4], "MultipartUpload.Parts[2].PartNumber"))
	assert.Regexp(t, `^ETAG\d+$`, val((*args)[4], "MultipartUpload.Parts[0].ETag"))
	assert.Regexp(t, `^ETAG\d+$`, val((*args)[4], "MultipartUpload.Parts[1].ETag"))
	assert.Regexp(t, `^ETAG\d+$`, val((*args)[4], "MultipartUpload.Parts[2].ETag"))

	// Custom headers
	assert.Equal(t, "AES256", val((*args)[0], "ServerSideEncryption"))
	assert.Equal(t, "content/type", val((*args)[0], "ContentType"))
}
开发者ID:kloudsio,项目名称:rancher-compose,代码行数:35,代码来源:upload_test.go

示例6: TestDealsWithWindowsLineEndings

func TestDealsWithWindowsLineEndings(t *testing.T) {
	e := email(t, "email_1_7")

	assert.Regexp(t, regexp.MustCompile(`:\+1:`), e.Fragments[0].String())
	assert.Regexp(t, regexp.MustCompile(`(?m)^On`), e.Fragments[1].String())
	assert.Regexp(t, regexp.MustCompile(`Steps 0-2`), e.Fragments[1].String())
}
开发者ID:recapco,项目名称:emailreplyparser,代码行数:7,代码来源:email_test.go

示例7: TestPolygonLayer

func TestPolygonLayer(t *testing.T) {
	m := New(&locator)
	m.SetNoMapBlock(true)

	m.AddLayer(mml.Layer{ID: "test", SRS: "4326", Type: mml.Polygon},
		[]mss.Rule{
			{Layer: "test", Properties: mss.NewProperties(
				"line-width", 1.0,
				"line-color", color.MustParse("red"),
				"line-opacity", 0.5,
				"line-dasharray", []mss.Value{3.0, 5.0},
				"polygon-fill", color.MustParse("blue"),
				"polygon-opacity", 0.2,
				"text-size", 10.0,
				"text-name", []mss.Value{mss.Field("name")},
			)},
		})
	result := m.String()
	assert.Contains(t, result, "WIDTH 1\n")
	assert.Contains(t, result, "OUTLINECOLOR \"#ff000080\"\n")
	assert.Regexp(t, `PATTERN\s+3\s+5\s+END`, result)
	assert.Contains(t, result, "COLOR \"#0000ff\"\n")
	assert.Contains(t, result, "OPACITY 20\n")
	assert.Regexp(t, `LABEL\s+ SIZE 7.4\d+`, result)
	assert.Regexp(t, `TEXT 'name'`, result)
}
开发者ID:nebulon42,项目名称:magnacarto,代码行数:26,代码来源:mapfile_test.go

示例8: TestScaledLineStringLayer

func TestScaledLineStringLayer(t *testing.T) {
	m := New(&locator)
	m.SetNoMapBlock(true)

	m.AddLayer(mml.Layer{ID: "test", SRS: "4326", Type: mml.LineString, ScaleFactor: 2.0},
		[]mss.Rule{
			{Layer: "test", Properties: mss.NewProperties(
				"line-width", 3.0,
				"line-opacity", 0.2,
				"line-dasharray", []mss.Value{2.0, 7.0},
			)},
		})
	m.AddLayer(mml.Layer{ID: "test", SRS: "4326", Type: mml.LineString},
		[]mss.Rule{
			{Layer: "test", Properties: mss.NewProperties(
				"line-width", 1.0,
				"line-color", color.MustParse("red"),
				"line-opacity", 0.5,
				"line-dasharray", []mss.Value{3.0, 5.0},
			)},
		})
	result := m.String()
	assert.Contains(t, result, "WIDTH 6\n")
	assert.Contains(t, result, "OPACITY 20\n")
	assert.Regexp(t, `PATTERN\s+4\s+14\s+END`, result)

	assert.Contains(t, result, "WIDTH 1\n")
	assert.Contains(t, result, "COLOR \"#ff0000\"\n")
	assert.Contains(t, result, "OPACITY 50\n")
	assert.Regexp(t, `PATTERN\s+3\s+5\s+END`, result)
}
开发者ID:nebulon42,项目名称:magnacarto,代码行数:31,代码来源:mapfile_test.go

示例9: TestUniqueId

func TestUniqueId(t *testing.T) {
	h, err := newTestHub()
	assert.NoError(t, err)
	defer h.Close()

	assert.Regexp(t, regexp.MustCompile(`^[0-9a-zA-Z]{10}-1$`), h.UniqueId())
	assert.Regexp(t, regexp.MustCompile(`^[0-9a-zA-Z]{10}-2$`), h.UniqueId())
	assert.Regexp(t, regexp.MustCompile(`^[0-9a-zA-Z]{10}-3$`), h.UniqueId())

}
开发者ID:SonOfBytes,项目名称:interfacehub,代码行数:10,代码来源:hub_test.go

示例10: TestMultipleOn

func TestMultipleOn(t *testing.T) {
	e := email(t, "greedy_on")

	assert.Regexp(t, regexp.MustCompile(`(?m)^On your remote host`), e.Fragments[0].String())
	assert.Regexp(t, regexp.MustCompile(`(?m)^On 9 Jan 2014`), e.Fragments[1].String())
	assert.Equal(t, []bool{false, true, false}, quoteds(e.Fragments))
	assert.Equal(t, []bool{false, false, false}, signatures(e.Fragments))
	assert.Equal(t, []bool{false, true, true}, hiddens(e.Fragments))

}
开发者ID:recapco,项目名称:emailreplyparser,代码行数:10,代码来源:email_test.go

示例11: TestResultsReportsFailures

func TestResultsReportsFailures(t *testing.T) {
	results := NewDetectionResults()
	results.Fail("some_filename", "Bomb")
	results.Fail("some_filename", "Complete & utter failure")
	results.Fail("another_filename", "Complete & utter failure")

	actualErrorReport := results.ReportFileFailures("some_filename")
	assert.Regexp(t, "The following errors were detected in some_filename", actualErrorReport, "Error report does not contain expected output")
	assert.Regexp(t, "Bomb", actualErrorReport, "Error report does not contain expected output")
	assert.Regexp(t, "Complete & utter failure", actualErrorReport, "Error report does not contain expected output")
}
开发者ID:Tsatsi,项目名称:talisman,代码行数:11,代码来源:detection_results_test.go

示例12: TestLoggingIgnoredFilesDoesNotCauseFailure

func TestLoggingIgnoredFilesDoesNotCauseFailure(t *testing.T) {
	results := NewDetectionResults()
	results.Ignore("some_file", "Ignoring this file, just because")
	results.Ignore("some/other_file", "Ignoring this file too")
	assert.True(t, results.Successful(), "Calling ignore should keep the result successful.")
	assert.True(t, results.HasIgnores(), "Calling ignore should be logged.")
	assert.False(t, results.HasFailures(), "Calling ignore should not cause a result to fail.")

	assert.Regexp(t, "Ignoring this file, just because", results.Report(), "foo")
	assert.Regexp(t, "Ignoring this file too", results.Report(), "foo")
}
开发者ID:Tsatsi,项目名称:talisman,代码行数:11,代码来源:detection_results_test.go

示例13: TestOAuth

func TestOAuth(t *testing.T) {
	oauthResponse, err := ccApi.OAuthToken(Password)
	assert.Nil(t, err)
	if assert.NotNil(t, oauthResponse) {
		assert.Regexp(t, md5Regex, oauthResponse.AccessToken)
		assert.Equal(t, oauthResponse.TokenType, "bearer")
		assert.Regexp(t, md5Regex, oauthResponse.RefreshToken)
		assert.True(t, oauthResponse.ExpiresIn > 0, "expires must be a non-negative integer")
		assert.Equal(t, "read write payments accounts export", oauthResponse.Scope)
	}
}
开发者ID:somespider,项目名称:cosmiccart,代码行数:11,代码来源:api_test.go

示例14: TestReadsTopPost

func TestReadsTopPost(t *testing.T) {
	e := email(t, "email_1_3")

	assert.Len(t, e.Fragments, 5)
	assert.Equal(t, []bool{false, false, true, false, false}, quoteds(e.Fragments))
	assert.Equal(t, []bool{false, true, true, true, true}, hiddens(e.Fragments))
	assert.Equal(t, []bool{false, true, false, false, true}, signatures(e.Fragments))
	assert.Regexp(t, regexp.MustCompile(`^Oh thanks.\n\nHaving`), e.Fragments[0].String())
	assert.Regexp(t, regexp.MustCompile(`^-A`), e.Fragments[1].String())
	assert.Regexp(t, regexp.MustCompile(`(?m)^On [^\:]+\:`), e.Fragments[2].String())
	assert.Regexp(t, regexp.MustCompile(`^_`), e.Fragments[4].String())
}
开发者ID:recapco,项目名称:emailreplyparser,代码行数:12,代码来源:email_test.go

示例15: TestHTTP

func TestHTTP(t *testing.T) {
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		time.Sleep(time.Second / 5)
		w.WriteHeader(200)
		w.Header().Set("Content-Type", "text/plain")
		fmt.Fprint(w, "OKOK")
	}))
	defer ts.Close()

	u, _ := url.Parse(ts.URL)

	host, port, _ := net.SplitHostPort(u.Host)

	testOk := func() {
		opts, err := parseArgs([]string{"-H", host, "-p", port, "--send", `GET / HTTP/1.0\r\n\r\n`, "-E", "-e", "OKOK"})
		assert.Equal(t, nil, err, "no errors")
		ckr := opts.run()
		fmt.Println(ckr)
		assert.Equal(t, checkers.OK, ckr.Status, "should be OK")
		assert.Regexp(t, `seconds response time on`, ckr.Message, "Unexpected response")
	}
	testOk()

	testUnexpected := func() {
		opts, err := parseArgs(
			[]string{"-H", host, "-p", port, "--send", `GET / HTTP/1.0\r\n\r\n`, "-E", "-e", "OKOKOK"})
		assert.Equal(t, nil, err, "no errors")
		ckr := opts.run()
		assert.Equal(t, checkers.CRITICAL, ckr.Status, "should be CRITICAL")
		assert.Regexp(t, `Unexpected response from`, ckr.Message, "Unexpected response")
	}
	testUnexpected()

	testOverWarn := func() {
		opts, err := parseArgs(
			[]string{"-H", host, "-p", port, "--send", `GET / HTTP/1.0\r\n\r\n`, "-E", "-e", "OKOK", "-w", "0.1"})
		assert.Equal(t, nil, err, "no errors")
		ckr := opts.run()
		assert.Equal(t, checkers.WARNING, ckr.Status, "should be Warning")
		assert.Regexp(t, `seconds response time on`, ckr.Message, "Unexpected response")
	}
	testOverWarn()

	testOverCrit := func() {
		opts, err := parseArgs(
			[]string{"-H", host, "-p", port, "--send", "GET / HTTP/1.0\r\n\r\n", "-e", "OKOK", "-c", "0.1"})
		assert.Equal(t, nil, err, "no errors")
		ckr := opts.run()
		assert.Equal(t, checkers.CRITICAL, ckr.Status, "should be Critical")
		assert.Regexp(t, `seconds response time on`, ckr.Message, "Unexpected response")
	}
	testOverCrit()
}
开发者ID:hiroakis,项目名称:go-check-plugins,代码行数:53,代码来源:check-tcp_test.go


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