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


Golang strings.Contains函数代码示例

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


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

示例1: TestTrustedPushWithIncorrectPassphraseForNonRoot

func (s *DockerTrustSuite) TestTrustedPushWithIncorrectPassphraseForNonRoot(c *check.C) {
	repoName := fmt.Sprintf("%v/dockercliincorretpwd/trusted:latest", privateRegistryURL)
	// tag the image and upload it to the private registry
	dockerCmd(c, "tag", "busybox", repoName)

	// Push with default passphrases
	pushCmd := exec.Command(dockerBinary, "push", repoName)
	s.trustedCmd(pushCmd)
	out, _, err := runCommandWithOutput(pushCmd)
	if err != nil {
		c.Fatalf("trusted push failed: %s\n%s", err, out)
	}

	if !strings.Contains(string(out), "Signing and pushing trust metadata") {
		c.Fatalf("Missing expected output on trusted push:\n%s", out)
	}

	// Push with wrong passphrases
	pushCmd = exec.Command(dockerBinary, "push", repoName)
	s.trustedCmdWithPassphrases(pushCmd, "12345678", "87654321")
	out, _, err = runCommandWithOutput(pushCmd)
	if err == nil {
		c.Fatalf("Error missing from trusted push with short targets passphrase: \n%s", out)
	}

	if !strings.Contains(string(out), "password invalid, operation has failed") {
		c.Fatalf("Missing expected output on trusted push with short targets/snapsnot passphrase:\n%s", out)
	}
}
开发者ID:ranid,项目名称:docker,代码行数:29,代码来源:docker_cli_push_test.go

示例2: TestDefaultDescribers

func TestDefaultDescribers(t *testing.T) {
	out, err := DefaultObjectDescriber.DescribeObject(&api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}})
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	if !strings.Contains(out, "foo") {
		t.Errorf("unexpected output: %s", out)
	}

	out, err = DefaultObjectDescriber.DescribeObject(&api.Service{ObjectMeta: api.ObjectMeta{Name: "foo"}})
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	if !strings.Contains(out, "foo") {
		t.Errorf("unexpected output: %s", out)
	}

	out, err = DefaultObjectDescriber.DescribeObject(&api.ReplicationController{ObjectMeta: api.ObjectMeta{Name: "foo"}})
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	if !strings.Contains(out, "foo") {
		t.Errorf("unexpected output: %s", out)
	}

	out, err = DefaultObjectDescriber.DescribeObject(&api.Node{ObjectMeta: api.ObjectMeta{Name: "foo"}})
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	if !strings.Contains(out, "foo") {
		t.Errorf("unexpected output: %s", out)
	}
}
开发者ID:ngbinh,项目名称:kubernetes,代码行数:33,代码来源:describe_test.go

示例3: DialTLS

func (d *Dialer) DialTLS(network, address string) (net.Conn, error) {
	switch network {
	case "tcp", "tcp4", "tcp6":
		if host, port, err := net.SplitHostPort(address); err == nil {
			if alias0, ok := d.hosts.Lookup(host); ok {
				alias := alias0.(string)
				if hosts, err := d.iplist.Lookup(alias); err == nil {
					config := &tls.Config{
						InsecureSkipVerify: true,
						ServerName:         address,
					}
					if strings.Contains(address, ".appspot.com") ||
						strings.Contains(address, ".google") ||
						strings.Contains(address, ".gstatic.com") ||
						strings.Contains(address, ".ggpht.com") {
						config.ServerName = "www.bing.com"
						config.CipherSuites = []uint16{tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}
					}

					addrs := make([]string, len(hosts))
					for i, host := range hosts {
						addrs[i] = net.JoinHostPort(host, port)
					}
					return d.dialMultiTLS(network, addrs, config)
				}
			}
		}
	default:
		break
	}
	return tls.DialWithDialer(&d.Dialer, network, address, d.TLSConfig)
}
开发者ID:sunjiahz,项目名称:goproxy,代码行数:32,代码来源:dialer.go

示例4: Generate

// options:
//  url - url to generate codes from
//  notmog - turn off grabbing transmogged items from armory
func (g *Generator) Generate(options map[string]interface{}, w io.Writer) error {
	url := to.String(options["url"])
	var tmorphItems TMorphItems
	var err error
	switch {
	case strings.Contains(url, "wowhead.com"):
		tmorphItems, err = wowhead(options)
	case strings.Contains(url, "battle.net/wow"):
		tmorphItems, err = wowarmory(options)
	case strings.Contains(url, "http"):
		tmorphItems, err = generic(options)
	default:
		return errors.New("Do not recognize the URL.")
	}

	if err != nil {
		return err
	}

	g.lastTmorphItems = tmorphItems
	bonus := int(to.Int64(options["bonus"]))
	g.Bonus(bonus)
	g.Output(w)

	return nil
}
开发者ID:kdar,项目名称:morphgen,代码行数:29,代码来源:morph.go

示例5: TestBuildWithVolumeOwnership

func TestBuildWithVolumeOwnership(t *testing.T) {
	name := "testbuildimg"
	defer deleteImages(name)

	_, err := buildImage(name,
		`FROM busybox:latest
        RUN mkdir /test && chown daemon:daemon /test && chmod 0600 /test
        VOLUME /test`,
		true)

	if err != nil {
		t.Fatal(err)
	}

	cmd := exec.Command(dockerBinary, "run", "--rm", "testbuildimg", "ls", "-la", "/test")
	out, _, err := runCommandWithOutput(cmd)
	if err != nil {
		t.Fatal(err)
	}

	if expected := "drw-------"; !strings.Contains(out, expected) {
		t.Fatalf("expected %s received %s", expected, out)
	}

	if expected := "daemon   daemon"; !strings.Contains(out, expected) {
		t.Fatalf("expected %s received %s", expected, out)
	}

	logDone("build - volume ownership")
}
开发者ID:GloriaH,项目名称:docker,代码行数:30,代码来源:docker_cli_build_test.go

示例6: TestEventsFilterImageName

func (s *DockerSuite) TestEventsFilterImageName(c *check.C) {
	since := daemonUnixTime(c)

	out, _ := dockerCmd(c, "run", "--name", "container_1", "-d", "busybox:latest", "true")
	container1 := strings.TrimSpace(out)

	out, _ = dockerCmd(c, "run", "--name", "container_2", "-d", "busybox", "true")
	container2 := strings.TrimSpace(out)

	name := "busybox"
	out, _ = dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", fmt.Sprintf("image=%s", name))
	events := strings.Split(out, "\n")
	events = events[:len(events)-1]
	c.Assert(events, checker.Not(checker.HasLen), 0) //Expected events but found none for the image busybox:latest
	count1 := 0
	count2 := 0

	for _, e := range events {
		if strings.Contains(e, container1) {
			count1++
		} else if strings.Contains(e, container2) {
			count2++
		}
	}
	c.Assert(count1, checker.Not(checker.Equals), 0, check.Commentf("Expected event from container but got %d from %s", count1, container1))
	c.Assert(count2, checker.Not(checker.Equals), 0, check.Commentf("Expected event from container but got %d from %s", count2, container2))

}
开发者ID:Mic92,项目名称:docker,代码行数:28,代码来源:docker_cli_events_test.go

示例7: TestWithdrawalBuildQuery

func TestWithdrawalBuildQuery(t *testing.T) {
	fmt.Println("[INFO] -- TestWithdrawalBuildQuery start --")
	querystring := map[string][]string{"gte": {"quantity|200", "approved_at|123456789"}, "eq": {"product_id|45", "order_id|100", "name|h2oh", "2"}}
	w := Withdrawal{Query: querystring}

	query := w.BuildQuery()
	fmt.Println("[INFO] query = ", query)

	if !strings.Contains(query, "quantity>=200") {
		t.Error("[ERROR] Withdrawal BuildQuery() 'gte'  is broken")
	}

	if !strings.Contains(query, "approved_at>=123456789") {
		t.Error("[ERROR] Withdrawal BuildQuery() 'gte' is broken")
	}

	if !strings.Contains(query, "product_id=45") {
		t.Error("[ERROR] Withdrawal BuildQuery() 'eq' is broken")
	}

	if !strings.Contains(query, "order_id=100") {
		t.Error("[ERROR] Withdrawal BuildQuery() 'eq' is broken")
	}

	if !strings.Contains(query, "name='h2oh'") {
		t.Error("[ERROR] Withdrawal BuildQuery() 'eq' is broken")
	}

	fmt.Println("[INFO] -- TestWithdrawalBuildQuery end --\n")
}
开发者ID:asvins,项目名称:warehouse,代码行数:30,代码来源:api_test.go

示例8: TestRootHelp

func TestRootHelp(t *testing.T) {
	x := fullSetupTest("--help")

	checkResultContains(t, x, "Available Commands:")
	checkResultContains(t, x, "for more information about a command")

	if strings.Contains(x.Output, "unknown flag: --help") {
		t.Errorf("--help shouldn't trigger an error, Got: \n %s", x.Output)
	}

	if strings.Contains(x.Output, cmdEcho.Use) {
		t.Errorf("--help shouldn't display subcommand's usage, Got: \n %s", x.Output)
	}

	x = fullSetupTest("echo --help")

	if strings.Contains(x.Output, cmdTimes.Use) {
		t.Errorf("--help shouldn't display subsubcommand's usage, Got: \n %s", x.Output)
	}

	checkResultContains(t, x, "Available Commands:")
	checkResultContains(t, x, "for more information about a command")

	if strings.Contains(x.Output, "unknown flag: --help") {
		t.Errorf("--help shouldn't trigger an error, Got: \n %s", x.Output)
	}

}
开发者ID:QuentinPerez,项目名称:delve,代码行数:28,代码来源:cobra_test.go

示例9: SSLMatchHosts

func (options *ScanOptions) SSLMatchHosts(conn *tls.Conn) []string {
	hosts := make([]string, 0)
	options.hostsMutex.Lock()
	for _, host := range options.inputHosts {
		testhost := host.Host
		if strings.Contains(testhost, ".appspot.com") {
			testhost = "appengine.google.com"
		} else if strings.Contains(testhost, "ggpht.com") {
			testhost = "googleusercontent.com"
		} else if strings.Contains(testhost, ".books.google.com") {
			testhost = "books.google.com"
		} else if strings.Contains(testhost, ".googleusercontent.com") {
			testhost = "googleusercontent.com"
		}
		if conn.VerifyHostname(testhost) == nil {
			hosts = append(hosts, host.Host)
		}
	}
	options.hostsMutex.Unlock()
	dest := make([]string, len(hosts))
	perm := rand.Perm(len(hosts))
	for i, v := range perm {
		dest[v] = hosts[i]
	}
	hosts = dest
	return hosts
}
开发者ID:XiliangSong,项目名称:gscan,代码行数:27,代码来源:scan.go

示例10: main

func main() {
	data, err := os.Open(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	defer data.Close()
	scanner := bufio.NewScanner(data)
	for scanner.Scan() {
		maph := func(r rune) rune {
			if strings.Contains("0123456789", string(r)) {
				return r
			} else if strings.Contains("abcdefghij", string(r)) {
				return r - 'a' + '0'
			}
			return -1
		}
		t := strings.Map(maph, scanner.Text())

		if len(t) == 0 {
			fmt.Println("NONE")
		} else {
			fmt.Println(t)
		}
	}
}
开发者ID:oorja,项目名称:ce-challenges,代码行数:25,代码来源:hidden_digits.go

示例11: IsTerminalEmulator

func IsTerminalEmulator(fileName string) bool {
	keyFile := glib.NewKeyFile()
	defer keyFile.Free()
	_, err := keyFile.LoadFromFile(fileName, glib.KeyFileFlagsNone)
	if err != nil {
		logger.Debug("KeyFile Load File Failed:", err)
		return false
	}

	categories, err := keyFile.GetString(_DESKTOP_ENTRY, _CATEGORY)
	if err != nil {
		return false
	}

	if strings.Contains(categories, _TERMINAL_EMULATOR) {
		execName, err := keyFile.GetString(_DESKTOP_ENTRY, _EXEC)
		if err != nil {
			return false
		}

		if strings.Contains(execName, _X_TERMINAL_EMULATOR) {
			return false
		}

		for _, v := range _TerminalBlacklist {
			if strings.Contains(execName, v) {
				return false
			}
		}

		return true
	}

	return false
}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:35,代码来源:default_app.go

示例12: TestErrorString

func TestErrorString(t *testing.T) {
	e := &Error{Location: "<L>", Message: "<M>", Reason: "<R>"}
	got := e.Error()
	if !strings.Contains(got, "<L>") || !strings.Contains(got, "<M>") || !strings.Contains(got, "<R>") {
		t.Errorf(`got %q, expected to see "<L>", "<M>" and "<R>"`, got)
	}
}
开发者ID:rawlingsj,项目名称:gofabric8,代码行数:7,代码来源:error_test.go

示例13: TestTrustedPushWithExpiredTimestamp

func (s *DockerTrustSuite) TestTrustedPushWithExpiredTimestamp(c *check.C) {
	c.Skip("Currently changes system time, causing instability")
	repoName := fmt.Sprintf("%v/dockercliexpiredtimestamppush/trusted:latest", privateRegistryURL)
	// tag the image and upload it to the private registry
	dockerCmd(c, "tag", "busybox", repoName)

	// Push with default passphrases
	pushCmd := exec.Command(dockerBinary, "push", repoName)
	s.trustedCmd(pushCmd)
	out, _, err := runCommandWithOutput(pushCmd)
	if err != nil {
		c.Fatalf("trusted push failed: %s\n%s", err, out)
	}

	if !strings.Contains(string(out), "Signing and pushing trust metadata") {
		c.Fatalf("Missing expected output on trusted push:\n%s", out)
	}

	// The timestamps expire in two weeks. Lets check three
	threeWeeksLater := time.Now().Add(time.Hour * 24 * 21)

	// Should succeed because the server transparently re-signs one
	runAtDifferentDate(threeWeeksLater, func() {
		pushCmd := exec.Command(dockerBinary, "push", repoName)
		s.trustedCmd(pushCmd)
		out, _, err := runCommandWithOutput(pushCmd)
		if err != nil {
			c.Fatalf("Error running trusted push: %s\n%s", err, out)
		}
		if !strings.Contains(string(out), "Signing and pushing trust metadata") {
			c.Fatalf("Missing expected output on trusted push with expired timestamp:\n%s", out)
		}
	})
}
开发者ID:ranid,项目名称:docker,代码行数:34,代码来源:docker_cli_push_test.go

示例14: TestTrustedPushWithExpiredSnapshot

func (s *DockerTrustSuite) TestTrustedPushWithExpiredSnapshot(c *check.C) {
	c.Skip("Currently changes system time, causing instability")
	repoName := fmt.Sprintf("%v/dockercliexpiredsnapshot/trusted:latest", privateRegistryURL)
	// tag the image and upload it to the private registry
	dockerCmd(c, "tag", "busybox", repoName)

	// Push with default passphrases
	pushCmd := exec.Command(dockerBinary, "push", repoName)
	s.trustedCmd(pushCmd)
	out, _, err := runCommandWithOutput(pushCmd)
	if err != nil {
		c.Fatalf("trusted push failed: %s\n%s", err, out)
	}

	if !strings.Contains(string(out), "Signing and pushing trust metadata") {
		c.Fatalf("Missing expected output on trusted push:\n%s", out)
	}

	// Snapshots last for three years. This should be expired
	fourYearsLater := time.Now().Add(time.Hour * 24 * 365 * 4)

	runAtDifferentDate(fourYearsLater, func() {
		// Push with wrong passphrases
		pushCmd = exec.Command(dockerBinary, "push", repoName)
		s.trustedCmd(pushCmd)
		out, _, err = runCommandWithOutput(pushCmd)
		if err == nil {
			c.Fatalf("Error missing from trusted push with expired snapshot: \n%s", out)
		}

		if !strings.Contains(string(out), "repository out-of-date") {
			c.Fatalf("Missing expected output on trusted push with expired snapshot:\n%s", out)
		}
	})
}
开发者ID:ranid,项目名称:docker,代码行数:35,代码来源:docker_cli_push_test.go

示例15: TestRecover_sendRecoverEmail

func TestRecover_sendRecoverEmail(t *testing.T) {
	t.Parallel()

	r, _, _ := testSetup()

	mailer := mocks.NewMockMailer()
	r.EmailSubjectPrefix = "foo "
	r.RootURL = "bar"
	r.Mailer = mailer

	r.sendRecoverEmail("[email protected]", "abc=")
	if len(mailer.Last.To) != 1 {
		t.Error("Expected 1 to email")
	}
	if mailer.Last.To[0] != "[email protected]" {
		t.Error("Unexpected to email:", mailer.Last.To[0])
	}
	if mailer.Last.Subject != "foo Password Reset" {
		t.Error("Unexpected subject:", mailer.Last.Subject)
	}

	url := fmt.Sprintf("%s/recover/complete?token=abc%%3D", r.RootURL)
	if !strings.Contains(mailer.Last.HTMLBody, url) {
		t.Error("Expected HTMLBody to contain url:", url)
	}
	if !strings.Contains(mailer.Last.TextBody, url) {
		t.Error("Expected TextBody to contain url:", url)
	}
}
开发者ID:voiid,项目名称:authboss,代码行数:29,代码来源:recover_test.go


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