예제 #1
0
func Usage(cmd string) {
	fmt.Println(strings.Repeat("-", 100))
	fmt.Println("Ssh version Check by haifeng11")
	fmt.Println("Usage:")
	fmt.Printf("%s iplist_file\n", cmd)
	fmt.Println(strings.Repeat("-", 100))
}
예제 #2
0
파일: kv_test.go 프로젝트: ringtail/etcd
func TestKVPutError(t *testing.T) {
	defer testutil.AfterTest(t)

	var (
		maxReqBytes = 1.5 * 1024 * 1024
		quota       = int64(maxReqBytes * 1.2)
	)
	clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1, QuotaBackendBytes: quota})
	defer clus.Terminate(t)

	kv := clientv3.NewKV(clus.RandClient())
	ctx := context.TODO()

	_, err := kv.Put(ctx, "", "bar")
	if err != rpctypes.ErrEmptyKey {
		t.Fatalf("expected %v, got %v", rpctypes.ErrEmptyKey, err)
	}

	_, err = kv.Put(ctx, "key", strings.Repeat("a", int(maxReqBytes+100))) // 1.5MB
	if err != rpctypes.ErrRequestTooLarge {
		t.Fatalf("expected %v, got %v", rpctypes.ErrRequestTooLarge, err)
	}

	_, err = kv.Put(ctx, "foo1", strings.Repeat("a", int(maxReqBytes-50)))
	if err != nil { // below quota
		t.Fatal(err)
	}

	time.Sleep(500 * time.Millisecond) // give enough time for commit

	_, err = kv.Put(ctx, "foo2", strings.Repeat("a", int(maxReqBytes-50)))
	if err != rpctypes.ErrNoSpace { // over quota
		t.Fatalf("expected %v, got %v", rpctypes.ErrNoSpace, err)
	}
}
예제 #3
0
func formatTwoColumns(w io.Writer, indent, padding, width int, rows [][2]string) {
	// Find size of first column.
	s := 0
	for _, row := range rows {
		if c := len(row[0]); c > s && c < 30 {
			s = c
		}
	}

	indentStr := strings.Repeat(" ", indent)
	offsetStr := strings.Repeat(" ", s+padding)

	for _, row := range rows {
		buf := bytes.NewBuffer(nil)
		doc.ToText(buf, row[1], "", preIndent, width-s-padding-indent)
		lines := strings.Split(strings.TrimRight(buf.String(), "\n"), "\n")
		fmt.Fprintf(w, "%s%-*s%*s", indentStr, s, row[0], padding, "")
		if len(row[0]) >= 30 {
			fmt.Fprintf(w, "\n%s%s", indentStr, offsetStr)
		}
		fmt.Fprintf(w, "%s\n", lines[0])
		for _, line := range lines[1:] {
			fmt.Fprintf(w, "%s%s%s\n", indentStr, offsetStr, line)
		}
	}
}
예제 #4
0
func TestValidFieldNames(t *testing.T) {
	testCases := []struct {
		name  string
		valid bool
	}{
		{"Normal", true},
		{"Also_OK_123", true},
		{"Not so great", false},
		{"lower_case", false},
		{"Exclaim!", false},
		{"Hello세상아 안녕", false},
		{"", false},
		{"Hεllo", false},
		{strings.Repeat("A", 500), true},
		{strings.Repeat("A", 501), false},
	}

	for _, tc := range testCases {
		_, _, err := saveDoc(&FieldList{
			Field{Name: tc.name, Value: "val"},
		})
		if err != nil && !strings.Contains(err.Error(), "invalid field name") {
			t.Errorf("unexpected err %q for field name %q", err, tc.name)
		}
		if (err == nil) != tc.valid {
			t.Errorf("field %q: expected valid %t, received err %v", tc.name, tc.valid, err)
		}
	}
}
예제 #5
0
func TestIsDelegation(t *testing.T) {
	f := require.False
	tr := require.True
	for val, check := range map[string]func(require.TestingT, bool, ...interface{}){
		// false checks
		path.Join(CanonicalTargetsRole, strings.Repeat("x", 255-len(CanonicalTargetsRole))): f,
		"":                                                                                  f,
		CanonicalRootRole:                                                                   f,
		path.Join(CanonicalRootRole, "level1"):                                              f,
		CanonicalTargetsRole:                                                                f,
		CanonicalTargetsRole + "/":                                                          f,
		path.Join(CanonicalTargetsRole, "level1") + "/":                                     f,
		path.Join(CanonicalTargetsRole, "UpperCase"):                                        f,
		path.Join(CanonicalTargetsRole, "directory") + "/../../traversal":                   f,
		CanonicalTargetsRole + "///test/middle/slashes":                                     f,
		CanonicalTargetsRole + "/./././":                                                    f,
		path.Join("  ", CanonicalTargetsRole, "level1"):                                     f,
		path.Join("  "+CanonicalTargetsRole, "level1"):                                      f,
		path.Join(CanonicalTargetsRole, "level1"+"  "):                                      f,
		path.Join(CanonicalTargetsRole, "white   space"+"level2"):                           f,
		path.Join(CanonicalTargetsRole, strings.Repeat("x", 256-len(CanonicalTargetsRole))): f,

		// true checks
		path.Join(CanonicalTargetsRole, "level1"):                     tr,
		path.Join(CanonicalTargetsRole, "level1", "level2", "level3"): tr,
		path.Join(CanonicalTargetsRole, "under_score"):                tr,
		path.Join(CanonicalTargetsRole, "hyphen-hyphen"):              tr,
	} {
		check(t, IsDelegation(val))
	}

}
func TestValidateLogGroupName(t *testing.T) {
	validNames := []string{
		"ValidLogGroupName",
		"ValidLogGroup.Name",
		"valid/Log-group",
		"1234",
		"YadaValid#0123",
		"Also_valid-name",
		strings.Repeat("W", 512),
	}
	for _, v := range validNames {
		_, errors := validateLogGroupName(v, "name")
		if len(errors) != 0 {
			t.Fatalf("%q should be a valid Log Metric Filter Transformation Name: %q", v, errors)
		}
	}

	invalidNames := []string{
		"Here is a name with: colon",
		"and here is another * invalid name",
		"also $ invalid",
		"This . is also %% invalid@!)+(",
		"*",
		"",
		// length > 512
		strings.Repeat("W", 513),
	}
	for _, v := range invalidNames {
		_, errors := validateLogGroupName(v, "name")
		if len(errors) == 0 {
			t.Fatalf("%q should be an invalid Log Metric Filter Transformation Name", v)
		}
	}
}
func TestValidateS3BucketLifecycleRuleId(t *testing.T) {
	validId := []string{
		"YadaHereAndThere",
		"Valid-5Rule_ID",
		"This . is also %% valid@!)+*(:ID",
		"1234",
		strings.Repeat("W", 255),
	}
	for _, v := range validId {
		_, errors := validateS3BucketLifecycleRuleId(v, "id")
		if len(errors) != 0 {
			t.Fatalf("%q should be a valid lifecycle rule id: %q", v, errors)
		}
	}

	invalidId := []string{
		// length > 255
		strings.Repeat("W", 256),
	}
	for _, v := range invalidId {
		_, errors := validateS3BucketLifecycleRuleId(v, "id")
		if len(errors) == 0 {
			t.Fatalf("%q should be an invalid lifecycle rule id", v)
		}
	}
}
예제 #8
0
func TestIsValidLabelValue(t *testing.T) {
	successCases := []string{
		"simple",
		"now-with-dashes",
		"1-starts-with-num",
		"end-with-num-1",
		"1234",                  // only num
		strings.Repeat("a", 63), // to the limit
		"", // empty value
	}
	for i := range successCases {
		if !IsValidLabelValue(successCases[i]) {
			t.Errorf("case %s expected success", successCases[i])
		}
	}

	errorCases := []string{
		"nospecialchars%^=@",
		"Tama-nui-te-rā.is.Māori.sun",
		"\\backslashes\\are\\bad",
		"-starts-with-dash",
		"ends-with-dash-",
		".starts.with.dot",
		"ends.with.dot.",
		strings.Repeat("a", 64), // over the limit
	}
	for i := range errorCases {
		if IsValidLabelValue(errorCases[i]) {
			t.Errorf("case[%d] expected failure", i)
		}
	}
}
예제 #9
0
func TestIsDNS952Label(t *testing.T) {
	goodValues := []string{
		"a", "ab", "abc", "a1", "a-1", "a--1--2--b",
		strings.Repeat("a", 24),
	}
	for _, val := range goodValues {
		if !IsDNS952Label(val) {
			t.Errorf("expected true for '%s'", val)
		}
	}

	badValues := []string{
		"0", "01", "012", "1a", "1-a", "1--a--b--2",
		"", "A", "ABC", "aBc", "A1", "A-1", "1-A",
		"-", "a-", "-a", "1-", "-1",
		"_", "a_", "_a", "a_b", "1_", "_1", "1_2",
		".", "a.", ".a", "a.b", "1.", ".1", "1.2",
		" ", "a ", " a", "a b", "1 ", " 1", "1 2",
		strings.Repeat("a", 25),
	}
	for _, val := range badValues {
		if IsDNS952Label(val) {
			t.Errorf("expected false for '%s'", val)
		}
	}
}
예제 #10
0
func TestBasic(t *testing.T) {
	testLiterals(t, []string{
		strings.Repeat("a", 1000),
		strings.Repeat("b", 97270),
		strings.Repeat("c", 8000),
	})
}
예제 #11
0
파일: sudoku.go 프로젝트: qur2/go-cover
func (s *SudokuSolver) Eureka(O *Solution) {
	grid := make([][]int, s.Dim)
	for i := 0; i < s.Dim; i++ {
		grid[i] = make([]int, s.Dim)
	}
	for _, n := range *O {
		nodes := make([]*Node, 4)
		nodes = append(nodes, n)
		for m := n.Right; n != m; m = m.Right {
			nodes = append(nodes, m)
		}
		x, y, digit := s.coverToGrid(nodes)
		grid[x][y] = digit
	}
	sdim := int(math.Sqrt(float64(s.Dim)))
	delim := "+" + strings.Repeat(strings.Repeat("-", sdim*2+1)+"+", sdim)
	for i, line := range grid {
		if i%sdim == 0 {
			fmt.Println(delim)
		}
		for j, cell := range line {
			if j%sdim == 0 {
				if j > 0 {
					fmt.Print(" ")
				}
				fmt.Print("|")
			}
			fmt.Print(" ", cell)
		}
		fmt.Print(" |\n")
	}
	fmt.Println(delim)
}
예제 #12
0
func TestNoIndexOnSliceProperties(t *testing.T) {
	// Check that ExcludeFromIndexes is set on the inner elements,
	// rather than the top-level ArrayValue value.
	ctx := context.Background()
	pl := PropertyList{
		Property{
			Name: "repeated",
			Value: []interface{}{
				123,
				false,
				"short",
				strings.Repeat("a", 1503),
			},
			NoIndex: true,
		},
	}
	key := NewKey(ctx, "dummy", "dummy", 0, nil)

	entity, err := saveEntity(key, &pl)
	if err != nil {
		t.Fatalf("saveEntity: %v", err)
	}

	want := &pb.Value{
		ValueType: &pb.Value_ArrayValue{&pb.ArrayValue{[]*pb.Value{
			{ValueType: &pb.Value_IntegerValue{123}, ExcludeFromIndexes: true},
			{ValueType: &pb.Value_BooleanValue{false}, ExcludeFromIndexes: true},
			{ValueType: &pb.Value_StringValue{"short"}, ExcludeFromIndexes: true},
			{ValueType: &pb.Value_StringValue{strings.Repeat("a", 1503)}, ExcludeFromIndexes: true},
		}}},
	}
	if got := entity.Properties["repeated"]; !proto.Equal(got, want) {
		t.Errorf("Entity proto differs\ngot:  %v\nwant: %v", got, want)
	}
}
예제 #13
0
파일: common_test.go 프로젝트: richm/origin
func TestRandomBuildTag(t *testing.T) {
	tests := []struct {
		namespace, name string
		want            string
	}{
		{"test", "build-1", "test/build-1:f1f85ff5"},
		// For long build namespace + build name, the returned random build tag
		// would be longer than the limit of reference.NameTotalLengthMax (255
		// chars). We do not truncate the repository name because it could create an
		// invalid repository name (e.g., namespace=abc, name=d, repo=abc/d,
		// trucated=abc/ -> invalid), so we simply take a SHA1 hash of the
		// repository name (which is guaranteed to be a valid repository name) and
		// preserve the random tag.
		{
			"namespace" + strings.Repeat(".namespace", 20),
			"name" + strings.Repeat(".name", 20),
			"47c1d5c686ce4563521c625457e79ca23c07bc27:f1f85ff5",
		},
	}
	for _, tt := range tests {
		rand.Seed(0)
		got := randomBuildTag(tt.namespace, tt.name)
		if !reflect.DeepEqual(got, tt.want) {
			t.Errorf("randomBuildTag(%q, %q) = %q, want %q", tt.namespace, tt.name, got, tt.want)
		}
	}
}
예제 #14
0
func (t *RandomReaderTest) UpgradesSequentialReads_ExistingReader() {
	t.object.Size = 1 << 40
	const readSize = 10

	// Simulate an existing reader at the correct offset, which will be exhausted
	// by the read below.
	const existingSize = 3
	r := strings.NewReader(strings.Repeat("x", existingSize))

	t.rr.wrapped.reader = ioutil.NopCloser(r)
	t.rr.wrapped.cancel = func() {}
	t.rr.wrapped.start = 1
	t.rr.wrapped.limit = 1 + existingSize

	// The bucket should be asked to read up to the end of the object.
	r = strings.NewReader(strings.Repeat("x", readSize-existingSize))
	rc := ioutil.NopCloser(r)

	ExpectCall(t.bucket, "NewReader")(
		Any(),
		AllOf(rangeStartIs(1+existingSize), rangeLimitIs(t.object.Size))).
		WillOnce(Return(rc, nil))

	// Call through.
	buf := make([]byte, readSize)
	t.rr.ReadAt(buf, 1)

	// Check the state now.
	ExpectEq(1+readSize, t.rr.wrapped.start)
	ExpectEq(t.object.Size, t.rr.wrapped.limit)
}
func CreateTable(tbl PicklesTableArgument) string {
	Html := ""
	if len(tbl.HeaderRow) > 0 {
		Html += "<table>"
		for n, y := range tbl.DataRows {
			if n == 1 && y[0] == strings.Repeat("-", strings.Count(y[0], "")-1) {
				continue
			}
			if n == len(tbl.DataRows)-1 && y[0] == strings.Repeat("-", strings.Count(y[0], "")-1) {
				continue
			}
			//fmt.Printf("ligne %d grp[%s] chaine lue [%s] taille:[%d] chaine de tiret [%s]\n",n,y,y[0],strings.Count(y[0],""),strings.Repeat("-", strings.Count(y[0],"")))
			Html += "<tr>"
			for _, z := range y {
				if n == 0 {
					Html += fmt.Sprintf("<th>%s</th>", z)
				} else {
					Html += fmt.Sprintf("<td>%s</td>", z)
				}
			}
			Html += "</tr>"
			//fmt.Printf("TableArgument.DataRows[%d]: %v\n", n,y)
		}
		Html += "</table>"
		// debug log.Fatalf("Stop %s",Html)

	}
	return Html
}
예제 #16
0
func TestValidateDomain(t *testing.T) {
	assert.False(t, ValidateDomainPart(strings.Repeat("a", 256)),
		"Max domain length is 255")
	assert.False(t, ValidateDomainPart(strings.Repeat("a", 64)+".com"),
		"Max label length is 63")
	assert.True(t, ValidateDomainPart(strings.Repeat("a", 63)+".com"),
		"Should allow 63 char label")

	var testTable = []struct {
		input  string
		expect bool
		msg    string
	}{
		{"", false, "Empty domain is not valid"},
		{"hostname", true, "Just a hostname is valid"},
		{"github.com", true, "Two labels should be just fine"},
		{"my-domain.com", true, "Hyphen is allowed mid-label"},
		{"_domainkey.foo.com", true, "Underscores are allowed"},
		{"bar.com.", true, "Must be able to end with a dot"},
		{"ABC.6DBS.com", true, "Mixed case is OK"},
		{"mail.123.com", true, "Number only label valid"},
		{"123.com", true, "Number only label valid"},
		{"google..com", false, "Double dot not valid"},
		{".foo.com", false, "Cannot start with a dot"},
		{"google\r.com", false, "Special chars not allowed"},
		{"foo.-bar.com", false, "Label cannot start with hyphen"},
		{"foo-.bar.com", false, "Label cannot end with hyphen"},
	}

	for _, tt := range testTable {
		if ValidateDomainPart(tt.input) != tt.expect {
			t.Errorf("Expected %v for %q: %s", tt.expect, tt.input, tt.msg)
		}
	}
}
예제 #17
0
func TestValidateLogMetricTransformationName(t *testing.T) {
	validNames := []string{
		"YadaHereAndThere",
		"Valid-5Metric_Name",
		"This . is also %% valid@!)+(",
		"1234",
		"",
		strings.Repeat("W", 255),
	}
	for _, v := range validNames {
		_, errors := validateLogMetricFilterTransformationName(v, "name")
		if len(errors) != 0 {
			t.Fatalf("%q should be a valid Log Metric Filter Transformation Name: %q", v, errors)
		}
	}

	invalidNames := []string{
		"Here is a name with: colon",
		"and here is another * invalid name",
		"also $ invalid",
		"*",
		// length > 255
		strings.Repeat("W", 256),
	}
	for _, v := range invalidNames {
		_, errors := validateLogMetricFilterTransformationName(v, "name")
		if len(errors) == 0 {
			t.Fatalf("%q should be an invalid Log Metric Filter Transformation Name", v)
		}
	}
}
예제 #18
0
// PrintRunningStep ...
func PrintRunningStep(title, version string, idx int) {
	if len(version) > 25 {
		version = "..." + stringutil.MaxLastChars(version, 22)
	}
	content := fmt.Sprintf("| (%d) %s (%s) |", idx, title, version)
	charDiff := len(content) - stepRunSummaryBoxWidthInChars

	if charDiff < 0 {
		// shorter than desired - fill with space
		content = fmt.Sprintf("| (%d) %s (%s)%s |", idx, title, version, strings.Repeat(" ", -charDiff))
	} else if charDiff > 0 {
		// longer than desired - trim title
		trimmedTitleWidth := len(title) - charDiff - 3
		if trimmedTitleWidth < 0 {
			log.Errorf("Step Version too long, can't present title at all! : %s", version)
		} else {
			content = fmt.Sprintf("| (%d) %s... (%s) |", idx, title[0:trimmedTitleWidth], version)
		}
	}

	sep := strings.Repeat("-", len(content))
	log.Info(sep)
	log.Infof(content)
	log.Info(sep)
	log.Info("|" + strings.Repeat(" ", stepRunSummaryBoxWidthInChars-2) + "|")
}
예제 #19
0
func TestValidateS3BucketReplicationRulePrefix(t *testing.T) {
	validId := []string{
		"YadaHereAndThere",
		"Valid-5Rule_ID",
		"This . is also %% valid@!)+*(:ID",
		"1234",
		strings.Repeat("W", 1024),
	}
	for _, v := range validId {
		_, errors := validateS3BucketReplicationRulePrefix(v, "id")
		if len(errors) != 0 {
			t.Fatalf("%q should be a valid lifecycle rule id: %q", v, errors)
		}
	}

	invalidId := []string{
		// length > 1024
		strings.Repeat("W", 1025),
	}
	for _, v := range invalidId {
		_, errors := validateS3BucketReplicationRulePrefix(v, "id")
		if len(errors) == 0 {
			t.Fatalf("%q should be an invalid replication configuration rule id", v)
		}
	}
}
예제 #20
0
파일: amua.go 프로젝트: deweerdt/amua
func drawKnownMaildirs(amua *Amua, g *gocui.Gui, v *gocui.View) error {
	v.Clear()
	v.Frame = false
	w, h := v.Size()
	displayed := len(amua.knownMaildirs)
	if len(amua.knownMaildirs) > h {
		displayed = h
	}
	fillers := h - displayed
	space := 1
	for i := 0; i < displayed; i++ {
		current := amua.knownMaildirs[i].maildir == amua.curMaildirView.md
		nrMsgs := fmt.Sprintf("(%d)", len(amua.knownMaildirs[i].maildir.messages))
		availableWidth := w - space - len(nrMsgs) - 3
		strfmt := fmt.Sprintf(" %%-%ds %s ", availableWidth, nrMsgs)
		str := fmt.Sprintf(strfmt, util.TruncateString(amua.knownMaildirs[i].path, availableWidth))
		if current {
			colorstring.Fprintf(v, "[bold]%s", str)
		} else {
			fmt.Fprint(v, str)
		}
		fmt.Fprintf(v, strings.Repeat(" ", space-1))
		fmt.Fprintln(v, "|")
	}
	for i := 0; i < fillers; i++ {
		fmt.Fprintf(v, strings.Repeat(" ", w-1))
		fmt.Fprintln(v, "|")
	}
	return nil
}
예제 #21
0
파일: board.go 프로젝트: paulcoyle/tetris
// Outputs the board as a string that kinda sorta looks like a tetris board.
func (b *Board) String() string {
	var out string = "  ┌"
	out += strings.Repeat("─", b.width)
	out += "┐\n"
	for row := 0; row < b.height; row++ {
		r := strconv.Itoa(row)
		out += r
		if row < 10 {
			out += " "
		}

		out += "│"
		for col := 0; col < b.width; col++ {
			if b.data[row][col] {
				out += "X"
			} else {
				out += " "
			}
		}
		out += "│\n"
	}
	out += "  └"
	out += strings.Repeat("─", b.width)
	out += "┘\n"

	out += "   "
	for i := 0; i < b.width; i++ {
		r := strconv.Itoa(i)
		out += r
	}
	out += "\n"

	return out
}
예제 #22
0
파일: public_test.go 프로젝트: crooks/yamn
func TestWritePubring(t *testing.T) {
	f, err := os.Create("pubring.mix")
	if err != nil {
		t.Fatal(err)
	}
	defer f.Close()
	var options string
	for n := 0; n < 10; n++ {
		counter := fmt.Sprintf("%02d", n)
		keyid := strings.Repeat("0", 32-len(counter)) + counter
		key := strings.Repeat("0", 32) + keyid
		if n < 4 {
			options = "E"
		} else {
			options = "M"
		}
		header := fmt.Sprintf(
			"test%02d test%[email protected] %s 4:0.2a %s 2016-01-01 2100-12-31\n\n",
			n,
			n,
			keyid,
			options,
		)
		f.WriteString(header)
		f.WriteString("-----Begin Mix Key-----\n")
		f.WriteString(keyid + "\n")
		f.WriteString(key + "\n")
		f.WriteString("-----End Mix Key-----\n\n")
	}
}
예제 #23
0
func (pb *ProgressBar) printToTerminal(printTo io.Writer, numColumns int, padding bool, maxBefore, maxAfter int) {
	pb.lock.Lock()
	before := pb.printBefore
	after := pb.printAfter

	if padding {
		before = before + strings.Repeat(" ", maxBefore-len(before))
		after = strings.Repeat(" ", maxAfter-len(after)) + after
	}

	progressBarSize := numColumns - (len(fmt.Sprintf("%s [] %s", before, after)))
	progressBar := ""
	if progressBarSize > 0 {
		currentProgress := int(pb.currentProgress * float64(progressBarSize))
		progressBar = fmt.Sprintf("[%s%s] ",
			strings.Repeat("=", currentProgress),
			strings.Repeat(" ", progressBarSize-currentProgress))
	} else {
		// If we can't fit the progress bar, better to not pad the before/after.
		before = pb.printBefore
		after = pb.printAfter
	}

	fmt.Fprintf(printTo, "%s %s%s\n", before, progressBar, after)
	pb.lock.Unlock()
}
예제 #24
0
파일: menu.go 프로젝트: Chownie/termbox-go
func DrawBox(x, y, width, height int) {
	DrawText(x, y, TOPLEFT+strings.Repeat(HORIZONTAL, width+2)+TOPRIGHT)
	for i := 1; i < height+1; i++ {
		DrawText(x, y+i, VERTICAL+strings.Repeat(" ", width+2)+VERTICAL)
	}
	DrawText(x, y+height, BOTTOMLEFT+strings.Repeat(HORIZONTAL, width+2)+BOTTOMRIGHT)
}
예제 #25
0
func TestDb_GetFromFrozen(t *testing.T) {
	h := newDbHarnessWopt(t, &opt.Options{WriteBuffer: 100100})
	defer h.close()

	h.put("foo", "v1")
	h.getVal("foo", "v1")

	h.stor.DelaySync(storage.TypeTable)      // Block sync calls
	h.put("k1", strings.Repeat("x", 100000)) // Fill memtable
	h.put("k2", strings.Repeat("y", 100000)) // Trigger compaction
	for i := 0; h.db.getFrozenMem() == nil && i < 100; i++ {
		time.Sleep(10 * time.Microsecond)
	}
	if h.db.getFrozenMem() == nil {
		h.stor.ReleaseSync(storage.TypeTable)
		t.Fatal("No frozen mem")
	}
	h.getVal("foo", "v1")
	h.stor.ReleaseSync(storage.TypeTable) // Release sync calls

	h.reopenDB()
	h.getVal("foo", "v1")
	h.get("k1", true)
	h.get("k2", true)
}
예제 #26
0
파일: cli.go 프로젝트: justone/goseeping
func summarize(good int) {

	last_10 := math.Max(0, float64(good-50))
	first_50 := (math.Min(0, float64(good-50)) + 50) / 10

	fmt.Printf("|%s%s%s%s| %d\n", strings.Repeat("#", int(first_50)), strings.Repeat(".", 5-int(first_50)), strings.Repeat("%", int(last_10)), strings.Repeat(".", 10-int(last_10)), good)
}
예제 #27
0
// PrintRunningStepFooter ..
func PrintRunningStepFooter(stepRunResult models.StepRunResultsModel, isLastStepInWorkflow bool) {
	iconBoxWidth := len("    ")
	timeBoxWidth := len(" time (s) ")
	titleBoxWidth := stepRunSummaryBoxWidthInChars - 4 - iconBoxWidth - timeBoxWidth
	sep := fmt.Sprintf("+%s+%s+%s+", strings.Repeat("-", iconBoxWidth), strings.Repeat("-", titleBoxWidth), strings.Repeat("-", timeBoxWidth))

	fmt.Println("|" + strings.Repeat(" ", stepRunSummaryBoxWidthInChars-2) + "|")

	fmt.Println(sep)
	fmt.Println(getRunningStepFooterMainSection(stepRunResult))
	fmt.Println(sep)
	if stepRunResult.Error != nil || stepRunResult.StepInfo.GlobalInfo.RemovalDate != "" {
		footerSubSection := getRunningStepFooterSubSection(stepRunResult)
		if footerSubSection != "" {
			fmt.Println(footerSubSection)
			fmt.Println(sep)
		}
	}

	if !isLastStepInWorkflow {
		fmt.Println()
		fmt.Println(strings.Repeat(" ", 42) + "â–¼")
		fmt.Println()
	}
}
예제 #28
0
func TestValidateSQSQueueName(t *testing.T) {
	validNames := []string{
		"valid-name",
		"valid02-name",
		"Valid-Name1",
		"_",
		"-",
		strings.Repeat("W", 80),
	}
	for _, v := range validNames {
		if errors := validateSQSQueueName(v, "name"); len(errors) > 0 {
			t.Fatalf("%q should be a valid SQS queue Name", v)
		}
	}

	invalidNames := []string{
		"Here is a name with: colon",
		"another * invalid name",
		"also $ invalid",
		"This . is also %% invalid@!)+(",
		"*",
		"",
		" ",
		".",
		strings.Repeat("W", 81), // length > 80
	}
	for _, v := range invalidNames {
		if errors := validateSQSQueueName(v, "name"); len(errors) == 0 {
			t.Fatalf("%q should be an invalid SQS queue Name", v)
		}
	}
}
예제 #29
0
// String returns the string of Decimal.
func (this Decimal) String() string {
	this.ensureValid()

	unscaledString := strings.TrimLeft(this.integer.String(), "-")
	if this.scale == 0 {
		return unscaledString
	}

	pointIndex := len(unscaledString) - this.scale
	switch {
	case pointIndex < 0:
		if this.integer.Sign() == -1 {
			return "-0." + strings.Repeat("0", -1*pointIndex) + unscaledString
		}

		return "0." + strings.Repeat("0", -1*pointIndex) + unscaledString
	case pointIndex > 0:
		if this.integer.Sign() == -1 {
			return "-" + unscaledString[0:pointIndex] + "." + unscaledString[pointIndex:]
		}

		return unscaledString[0:pointIndex] + "." + unscaledString[pointIndex:]
	default: // pointIndex == 0
		if this.integer.Sign() == -1 {
			return "-0." + unscaledString
		}

		return "0." + unscaledString
	}
}
예제 #30
0
파일: bdd.go 프로젝트: manveru/gobdd
func BuildSpecReport() (string, bool) {
	var s string

	ok := len(testingErrors) == 0

	if !ok {
		s += redColor

		for _, error := range testingErrors {
			indents := 0

			for _, contextStr := range error.Contexts {
				s += fmt.Sprintf("%s- %s\n", strings.Repeat("  ", indents), contextStr)
				indents++
			}

			s += fmt.Sprintf("%s  %s\n\n", strings.Repeat("  ", indents), error.ItString)
			s += fmt.Sprintf("%s\n\t%s\n", error.String, error.ErrorLine)
		}

		s += resetColors
	} else {
		s += greenColor
		s += fmt.Sprintf("All tests passed. %d examples. 0 failures.\n", testingExamples)
		s += resetColors
	}

	return s, ok
}