nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: goplus/gop
Pull request #980 (2021-11-29 15:34:13)

Fix tests on Windows
Maybe need a full specification of the eol style.


Patch:
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 00000000..b541ff26
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,5 @@
+*.expect text eol=lf
+*.golden text eol=lf
+
+*.gop text eol=lf
+*.go text eol=lf
\ No newline at end of file


Test patch:
diff --git a/parser/parserdir_test.go b/parser/parserdir_test.go
index 6f264154..4c59d526 100644
--- a/parser/parserdir_test.go
+++ b/parser/parserdir_test.go
@@ -22,7 +22,6 @@ import (
 	"os"
 	"path"
 	"reflect"
-	"runtime"
 	"strings"
 	"testing"
 
@@ -122,9 +121,6 @@ func TestParseGo(t *testing.T) {
 }
 
 func TestFromTestdata(t *testing.T) {
-	if runtime.GOOS == "windows" {
-		return // TODO: how to pass this testcase in windows
-	}
 	sel := ""
 	dir, err := os.Getwd()
 	if err != nil {
diff --git a/printer/gop_test.go b/printer/gop_test.go
index aa776a31..13cd9703 100644
--- a/printer/gop_test.go
+++ b/printer/gop_test.go
@@ -21,7 +21,6 @@ import (
 	"io/ioutil"
 	"os"
 	"path/filepath"
-	"runtime"
 	"testing"
 
 	"github.com/goplus/gop/ast"
@@ -118,9 +117,6 @@ func testFrom(t *testing.T, fpath string) {
 }
 
 func TestFromTestdata(t *testing.T) {
-	if runtime.GOOS == "windows" {
-		return // TODO: how to pass this testcase in windows
-	}
 	dir, err := os.Getwd()
 	if err != nil {
 		t.Fatal("Getwd failed:", err)
@@ -139,9 +135,6 @@ func TestFromTestdata(t *testing.T) {
 }
 
 func TestFromParse(t *testing.T) {
-	if runtime.GOOS == "windows" {
-		return // TODO: how to pass this testcase in windows
-	}
 	dir, err := os.Getwd()
 	if err != nil {
 		t.Fatal("Getwd failed:", err)
diff --git a/x/mod/modfile/read_test.go b/x/mod/modfile/read_test.go
index c278ef07..054013a9 100644
--- a/x/mod/modfile/read_test.go
+++ b/x/mod/modfile/read_test.go
@@ -23,7 +23,6 @@ import (
 	"os/exec"
 	"path/filepath"
 	"reflect"
-	"runtime"
 	"strings"
 	"testing"
 )
@@ -31,9 +30,6 @@ import (
 // Test that reading and then writing the golden files
 // does not change their output.
 func TestPrintGolden(t *testing.T) {
-	if runtime.GOOS == "windows" {
-		return // TODO: how to pass this testcase in windows
-	}
 	outs, err := filepath.Glob("testdata/*.golden")
 	if err != nil {
 		t.Fatal(err)
@@ -154,9 +150,6 @@ func TestParseLax(t *testing.T) {
 // and printed and parsed again, we get the same parse tree
 // both times.
 func TestPrintParse(t *testing.T) {
-	if runtime.GOOS == "windows" {
-		return // TODO: how to pass this testcase in windows
-	}
 	outs, err := filepath.Glob("testdata/*")
 	if err != nil {
 		t.Fatal(err)
Repository: goplus/gop
Pull request #984 (2021-11-30 01:01:28)

cl: class file check field spec type and value
fix https://github.com/goplus/gop/issues/978
```
var (
	a = 100
	b int = 100
)

println "hi"
```
```
index.gmx:2:2: missing field type in class file
index.gmx:3:2: cannot assign value to field in class file
```


Patch:
diff --git a/cl/compile.go b/cl/compile.go
index 5c150ebc..4bf51367 100644
--- a/cl/compile.go
+++ b/cl/compile.go
@@ -560,6 +560,15 @@ func preloadFile(p *gox.Package, parent *pkgCtx, file string, f *ast.File, targe
 				}
 				for _, v := range specs {
 					spec := v.(*ast.ValueSpec)
+					if spec.Type == nil {
+						pos := ctx.Position(v.Pos())
+						ctx.handleCodeErrorf(&pos, "missing field type in class file")
+						continue
+					}
+					if len(spec.Values) > 0 {
+						pos := ctx.Position(v.Pos())
+						ctx.handleCodeErrorf(&pos, "cannot assign value to field in class file")
+					}
 					typ := toType(ctx, spec.Type)
 					for _, name := range spec.Names {
 						flds = append(flds, types.NewField(name.Pos(), pkg, name.Name, typ, false))


Test patch:
diff --git a/cl/compile_spx_test.go b/cl/compile_spx_test.go
index db874b23..04b20236 100644
--- a/cl/compile_spx_test.go
+++ b/cl/compile_spx_test.go
@@ -73,6 +73,50 @@ func gopSpxTestEx(t *testing.T, gmx, spxcode, expected, gmxfile, spxfile string)
 	}
 }
 
+func gopSpxErrorTestEx(t *testing.T, msg, gmx, spxcode, gmxfile, spxfile string) {
+	fs := newTwoFileFS("/foo", spxfile, spxcode, gmxfile, gmx)
+	pkgs, err := parser.ParseFSDir(gblFset, fs, "/foo", nil, 0)
+	if err != nil {
+		scanner.PrintError(os.Stderr, err)
+		t.Fatal("ParseFSDir:", err)
+	}
+	conf := *baseConf.Ensure()
+	conf.NoFileLine = false
+	conf.WorkingDir = "/foo"
+	conf.TargetDir = "/foo"
+	bar := pkgs["main"]
+	_, err = cl.NewPackage("", bar, &conf)
+	if err == nil {
+		t.Fatal("no error?")
+	}
+	if ret := err.Error(); ret != msg {
+		t.Fatalf("\nError: \"%s\"\nExpected: \"%s\"\n", ret, msg)
+	}
+}
+
+func TestSpxError(t *testing.T) {
+	gopSpxErrorTestEx(t, `./Game.tgmx:4:2: cannot assign value to field in class file`, `
+var (
+	Kai Kai
+	userScore int = 100
+)
+`, `
+println "hi"
+`, "Game.tgmx", "Kai.tspx")
+
+	gopSpxErrorTestEx(t, `./Kai.tspx:3:2: missing field type in class file`, `
+var (
+	Kai Kai
+	userScore int
+)
+`, `
+var (
+	id = 100
+)
+println "hi"
+`, "Game.tgmx", "Kai.tspx")
+}
+
 func TestSpxBasic(t *testing.T) {
 	gopSpxTestEx(t, `
 func onInit() {
Repository: goplus/gop
Pull request #1014 (2021-12-02 12:10:57)

gop/x/format


Patch:
diff --git a/x/format/gopstyle.go b/x/format/gopstyle.go
new file mode 100644
index 00000000..1091ad80
--- /dev/null
+++ b/x/format/gopstyle.go
@@ -0,0 +1,39 @@
+package format
+
+import (
+	"github.com/goplus/gop/ast"
+)
+
+// -----------------------------------------------------------------------------
+
+func Gopstyle(file *ast.File) {
+	if identEqual(file.Name, "main") {
+		file.NoPkgDecl = true
+	}
+	if idx := findFuncDecl(file.Decls, "main"); idx >= 0 {
+		last := len(file.Decls) - 1
+		if idx != last {
+			fn := file.Decls[idx]
+			copy(file.Decls[idx:], file.Decls[idx+1:])
+			file.Decls[last] = fn
+		}
+		file.NoEntrypoint = true
+	}
+}
+
+func identEqual(v *ast.Ident, name string) bool {
+	return v != nil && v.Name == name
+}
+
+func findFuncDecl(decls []ast.Decl, name string) int {
+	for i, decl := range decls {
+		if fn, ok := decl.(*ast.FuncDecl); ok {
+			if identEqual(fn.Name, name) {
+				return i
+			}
+		}
+	}
+	return -1
+}
+
+// -----------------------------------------------------------------------------


Test patch:
diff --git a/x/format/gopstyle_test.go b/x/format/gopstyle_test.go
new file mode 100644
index 00000000..29de6a70
--- /dev/null
+++ b/x/format/gopstyle_test.go
@@ -0,0 +1,81 @@
+package format
+
+import (
+	"bytes"
+	"testing"
+
+	"github.com/goplus/gop/format"
+	"github.com/goplus/gop/parser"
+	"github.com/goplus/gop/token"
+)
+
+// -----------------------------------------------------------------------------
+
+func testFormat(t *testing.T, name string, src, expect string) {
+	t.Run(name, func(t *testing.T) {
+		fset := token.NewFileSet()
+		f, err := parser.ParseFile(fset, "foo.gop", src, parser.ParseComments)
+		if err != nil {
+			t.Fatal("parser.ParseFile failed:", err)
+		}
+		Gopstyle(f)
+		var buf bytes.Buffer
+		err = format.Node(&buf, fset, f)
+		if err != nil {
+			t.Fatal("format.Node failed:", err)
+		}
+		if ret := buf.String(); ret != expect {
+			t.Fatalf("%s => Expect:\n%s\n=> Got:\n%s\n", name, expect, ret)
+		}
+	})
+}
+
+func TestBasic1(t *testing.T) {
+	testFormat(t, "hello world", `package main
+
+import "fmt"
+
+func main() {
+	fmt.Println("Hello world")
+}
+`, `import "fmt"
+
+fmt.Println("Hello world")
+`)
+}
+
+func TestBasic2(t *testing.T) {
+	testFormat(t, "hello world", `package main
+
+import "fmt"
+
+func main() {
+	fmt.Println("Hello world")
+}
+
+func f() {
+}
+`, `import "fmt"
+
+func f() {
+}
+
+fmt.Println("Hello world")
+`)
+}
+
+func TestBasic3(t *testing.T) {
+	testFormat(t, "hello world", `package main
+
+import "fmt"
+
+func f() {
+}
+`, `import "fmt"
+
+func f() {
+}
+`)
+}
+
+// -----------------------------------------------------------------------------
Repository: goplus/gop
Pull request #1026 (2021-12-04 04:46:33)

Gopstyle: dont' swap main


Patch:
diff --git a/x/format/gopstyle.go b/x/format/gopstyle.go
index a5307d7a..66828b29 100644
--- a/x/format/gopstyle.go
+++ b/x/format/gopstyle.go
@@ -36,13 +36,16 @@ func Gopstyle(file *ast.File) {
 	}
 	if idx := findFuncDecl(file.Decls, "main"); idx >= 0 {
 		last := len(file.Decls) - 1
-		if idx != last { // swap main func to last
-			fn := file.Decls[idx]
-			copy(file.Decls[idx:], file.Decls[idx+1:])
-			file.Decls[last] = fn
+		if idx == last {
+			file.NoEntrypoint = true
+			// TODO: idx != last: swap main func to last
 			// TODO: should also swap file.Comments
+			/*
+				fn := file.Decls[idx]
+				copy(file.Decls[idx:], file.Decls[idx+1:])
+				file.Decls[last] = fn
+			*/
 		}
-		file.NoEntrypoint = true
 	}
 }
 


Test patch:
diff --git a/x/format/gopstyle_test.go b/x/format/gopstyle_test.go
index d6116bf5..b0a0f037 100644
--- a/x/format/gopstyle_test.go
+++ b/x/format/gopstyle_test.go
@@ -23,11 +23,16 @@ func TestBasic1(t *testing.T) {
 
 import "fmt"
 
+// this is main
 func main() {
+	// say hello
 	fmt.Println("Hello world")
 }
 `, `import "fmt"
 
+// this is main
+
+// say hello
 fmt.Println("Hello world")
 `)
 }
@@ -37,7 +42,9 @@ func TestBasic2(t *testing.T) {
 
 import "fmt"
 
+// this is main
 func main() {
+	// say hello
 	fmt.Println("Hello world")
 }
 
@@ -45,10 +52,14 @@ func f() {
 }
 `, `import "fmt"
 
-func f() {
+// this is main
+func main() {
+	// say hello
+	fmt.Println("Hello world")
 }
 
-fmt.Println("Hello world")
+func f() {
+}
 `)
 }
Repository: goplus/gop
Pull request #1040 (2021-12-08 08:21:32)

don't change fncall to lowerCase start if not extern call


Patch:
diff --git a/x/format/README.md b/x/format/README.md
index 956992d8..1b308cee 100644
--- a/x/format/README.md
+++ b/x/format/README.md
@@ -83,7 +83,7 @@ Note:
 * Only the outermost function call statement is converted into command style. So `fmt.Println(fmt.Println("Hello world"))` is converted into `println println("Hello world")`, not `println println "Hello world"`.
 
 
-### Function call starting with lowercase
+### pkg.Fncall starting with lowercase
 
 ```go
 import "math"
diff --git a/x/format/format.go b/x/format/format.go
index 15833ed6..112489ef 100644
--- a/x/format/format.go
+++ b/x/format/format.go
@@ -48,8 +48,11 @@ func fmtToBuiltin(ctx *importCtx, sel *ast.Ident, ref *ast.Expr) bool {
 }
 
 func commandStyleFirst(v *ast.CallExpr) {
-	if v.NoParenEnd == token.NoPos {
-		v.NoParenEnd = v.Rparen
+	switch v.Fun.(type) {
+	case *ast.Ident, *ast.SelectorExpr:
+		if v.NoParenEnd == token.NoPos {
+			v.NoParenEnd = v.Rparen
+		}
 	}
 }
 
@@ -57,8 +60,6 @@ func fncallStartingLowerCase(v *ast.CallExpr) {
 	switch fn := v.Fun.(type) {
 	case *ast.SelectorExpr:
 		startWithLowerCase(fn.Sel)
-	case *ast.Ident:
-		startWithLowerCase(fn)
 	}
 }
 


Test patch:
diff --git a/x/format/_testdata/collection/format.expect b/x/format/_testdata/collection/format.expect
index d70cf9e2..d4f69322 100644
--- a/x/format/_testdata/collection/format.expect
+++ b/x/format/_testdata/collection/format.expect
@@ -34,7 +34,7 @@ func Index(vs []string, t string) int {
 // Include returns `true` if the target string t is in the
 // slice.
 func Include(vs []string, t string) bool {
-	return index(vs, t) >= 0
+	return Index(vs, t) >= 0
 }
 
 // Any returns `true` if one of the strings in the slice
@@ -84,23 +84,23 @@ func Map(vs []string, f func(string) string) []string {
 // Here we try out our various collection functions.
 var strs = []string{"peach", "apple", "pear", "plum"}
 
-println index(strs, "pear")
+println Index(strs, "pear")
 
-println include(strs, "grape")
+println Include(strs, "grape")
 
-println any(strs, func(v string) bool {
+println Any(strs, func(v string) bool {
 	return strings.hasPrefix(v, "p")
 })
 
-println all(strs, func(v string) bool {
+println All(strs, func(v string) bool {
 	return strings.hasPrefix(v, "p")
 })
 
-println filter(strs, func(v string) bool {
+println Filter(strs, func(v string) bool {
 	return strings.contains(v, "e")
 })
 
 // The above examples all used anonymous functions,
 // but you can also use named functions of the correct
 // type.
-println map(strs, strings.ToUpper)
+println Map(strs, strings.ToUpper)
diff --git a/x/format/gopstyle_test.go b/x/format/gopstyle_test.go
index 42883c5a..5b1e8159 100644
--- a/x/format/gopstyle_test.go
+++ b/x/format/gopstyle_test.go
@@ -154,7 +154,7 @@ func f() {
 `, `import . "errors"
 
 func f() {
-	errorf "%w", new("hello")
+	errorf "%w", New("hello")
 	println "hello"
 }
 `)
Repository: goplus/gop
Pull request #1041 (2021-12-08 08:31:51)

formatType: *T, ...T


Patch:
diff --git a/x/format/stmt_expr_or_type.go b/x/format/stmt_expr_or_type.go
index 36ea11f6..60bec773 100644
--- a/x/format/stmt_expr_or_type.go
+++ b/x/format/stmt_expr_or_type.go
@@ -30,6 +30,8 @@ func formatType(ctx *formatCtx, typ ast.Expr, ref *ast.Expr) {
 	case *ast.Ident, nil:
 	case *ast.SelectorExpr:
 		formatSelectorExpr(ctx, t, ref)
+	case *ast.StarExpr:
+		formatType(ctx, t.X, &t.X)
 	case *ast.MapType:
 		formatType(ctx, t.Key, &t.Key)
 		formatType(ctx, t.Value, &t.Value)
@@ -44,6 +46,8 @@ func formatType(ctx *formatCtx, typ ast.Expr, ref *ast.Expr) {
 		formatFields(ctx, t.Methods)
 	case *ast.FuncType:
 		formatFuncType(ctx, t)
+	case *ast.Ellipsis:
+		formatType(ctx, t.Elt, &t.Elt)
 	default:
 		log.Panicln("TODO: format -", reflect.TypeOf(typ))
 	}


Test patch:
diff --git a/x/format/_testdata/syntax/format.expect b/x/format/_testdata/syntax/format.expect
index e7a56d54..52884fd9 100644
--- a/x/format/_testdata/syntax/format.expect
+++ b/x/format/_testdata/syntax/format.expect
@@ -1,3 +1,6 @@
+func f(...T) {
+}
+
 a++
 arr := [...]int{1: 3}
 m := make(map[string]chan interface{})
@@ -8,6 +11,7 @@ foo:
 	m["a"] <- true
 }
 for i := 0; i < 10; i++ {
+	var t *T
 	if false {
 	} else {
 	}
diff --git a/x/format/_testdata/syntax/index.gop b/x/format/_testdata/syntax/index.gop
index 8ad3c11e..27493942 100644
--- a/x/format/_testdata/syntax/index.gop
+++ b/x/format/_testdata/syntax/index.gop
@@ -1,5 +1,8 @@
 import "fmt"
 
+func f(...T) {
+}
+
 a++
 arr := [...]int{1: 3}
 m := make(map[string]chan interface{})
@@ -10,6 +13,7 @@ foo:
 	m["a"] <- true
 }
 for i := 0; i < 10; i++ {
+	var t *T
 	if false {
 	} else {
 	}
Repository: goplus/gop
Pull request #1045 (2021-12-08 17:23:12)

support fmt.print => print


Patch:
diff --git a/x/format/format.go b/x/format/format.go
index 112489ef..76212821 100644
--- a/x/format/format.go
+++ b/x/format/format.go
@@ -24,24 +24,26 @@ import (
 
 // -----------------------------------------------------------------------------
 
-var printFuncs = map[string]string{
-	"Errorf":   "errorf",
-	"Print":    "print",
-	"Printf":   "printf",
-	"Println":  "println",
-	"Fprint":   "fprint",
-	"Fprintf":  "fprintf",
-	"Fprintln": "fprintln",
-	"Sprint":   "sprint",
-	"Sprintf":  "sprintf",
-	"Sprintln": "sprintln",
+var printFuncs = [][2]string{
+	{"Errorf", "errorf"},
+	{"Print", "print"},
+	{"Printf", "printf"},
+	{"Println", "println"},
+	{"Fprint", "fprint"},
+	{"Fprintf", "fprintf"},
+	{"Fprintln", "fprintln"},
+	{"Sprint", "sprint"},
+	{"Sprintf", "sprintf"},
+	{"Sprintln", "sprintln"},
 }
 
 func fmtToBuiltin(ctx *importCtx, sel *ast.Ident, ref *ast.Expr) bool {
 	if ctx.pkgPath == "fmt" {
-		if v, ok := printFuncs[sel.Name]; ok {
-			*ref = &ast.Ident{NamePos: sel.NamePos, Name: v}
-			return true
+		for _, fns := range printFuncs {
+			if fns[0] == sel.Name || fns[1] == sel.Name {
+				*ref = &ast.Ident{NamePos: sel.NamePos, Name: fns[1]}
+				return true
+			}
 		}
 	}
 	return false


Test patch:
diff --git a/x/format/gopstyle_test.go b/x/format/gopstyle_test.go
index 5b1e8159..5492477e 100644
--- a/x/format/gopstyle_test.go
+++ b/x/format/gopstyle_test.go
@@ -170,7 +170,7 @@ import (
 
 func f() {
 	fmt.Errorf("%w", errors.New("hello"))
-	fmt.Println("hello")
+	fmt.println "hello"
 }
 `, `import (
 	"errors"
@@ -191,7 +191,7 @@ import "fmt"
 
 func f() {
 	_ = fmt.Errorf("%w", errors.New("hello"))
-	fmt.Println("hello")
+	fmt.println("hello")
 }
 `, `import "errors"
Repository: goplus/gop
Pull request #1108 (2022-01-20 13:22:10)

cl: check struct type fields name redeclared
fix https://github.com/goplus/gop/issues/1060

```
type Id struct {
}
type A struct {
	Id
	Id   int
	Id   string
	name string
	name string
}
```
error message compatible for **Go1.18** compile error message.
```
./bar.gop:6:2: Id redeclared
	./bar.gop:5:2 other declaration of Id
./bar.gop:7:2: Id redeclared
	./bar.gop:5:2 other declaration of Id
./bar.gop:9:2: name redeclared
	./bar.gop:8:2 other declaration of name
```

not used **Go1.16** compile error message.
```
./bar.go:13:2: duplicate field Id
./bar.go:14:2: duplicate field Id
./bar.go:16:2: duplicate field name
```



Patch:
diff --git a/cl/func_type_and_var.go b/cl/func_type_and_var.go
index f24de2da..632fadd0 100644
--- a/cl/func_type_and_var.go
+++ b/cl/func_type_and_var.go
@@ -209,15 +209,36 @@ func toStructType(ctx *blockCtx, v *ast.StructType) *types.Struct {
 	fieldList := v.Fields.List
 	fields := make([]*types.Var, 0, len(fieldList))
 	tags := make([]string, 0, len(fieldList))
+	names := make(map[string]token.Pos)
+	chkRedecl := func(name string, pos token.Pos) bool {
+		if name == "_" {
+			return false
+		}
+		if opos, ok := names[name]; ok {
+			npos := ctx.Position(pos)
+			ctx.handleCodeErrorf(&npos, "%v redeclared\n\t%v other declaration of %v",
+				name, ctx.Position(opos), name)
+			return true
+		}
+		names[name] = pos
+		return false
+	}
 	for _, field := range fieldList {
 		typ := toType(ctx, field.Type)
 		if field.Names == nil { // embedded
-			fld := types.NewField(token.NoPos, pkg, getTypeName(typ), typ, true)
+			name := getTypeName(typ)
+			if chkRedecl(name, field.Type.Pos()) {
+				continue
+			}
+			fld := types.NewField(token.NoPos, pkg, name, typ, true)
 			fields = append(fields, fld)
 			tags = append(tags, toFieldTag(field.Tag))
 			continue
 		}
 		for _, name := range field.Names {
+			if chkRedecl(name.Name, name.NamePos) {
+				continue
+			}
 			fld := types.NewField(token.NoPos, pkg, name.Name, typ, false)
 			fields = append(fields, fld)
 			tags = append(tags, toFieldTag(field.Tag))


Test patch:
diff --git a/cl/error_msg_test.go b/cl/error_msg_test.go
index 07563b08..bdba2d13 100644
--- a/cl/error_msg_test.go
+++ b/cl/error_msg_test.go
@@ -806,3 +806,22 @@ import "fmt"
 n, err := fmt.println
 `)
 }
+
+func TestFiledsNameRedecl(t *testing.T) {
+	codeErrorTest(t, `./bar.gop:6:2: Id redeclared
+	./bar.gop:5:2 other declaration of Id
+./bar.gop:7:2: Id redeclared
+	./bar.gop:5:2 other declaration of Id
+./bar.gop:9:2: name redeclared
+	./bar.gop:8:2 other declaration of name`, `
+type Id struct {
+}
+type A struct {
+	Id   int
+	Id   string
+	Id
+	name string
+	name string
+}
+`)
+}
Repository: firebase/firebase-admin-go
Pull request #445 (2021-05-26 20:13:29)

fix(auth): Fix incorrect import of partial user metadata.
It fixes the import issue described in https://github.com/firebase/firebase-admin-go/issues/443

valery-barysok: @hiranya911, I added test cases and created PR to dev branch.
hiranya911: CI has detected some code formatting issues. Please run `gofmt` and push the changes.
valery-barysok: @hiranya911, I resolved all comments. Could you please take a look?

Patch:
diff --git a/auth/import_users.go b/auth/import_users.go
index 198d261..b036aad 100644
--- a/auth/import_users.go
+++ b/auth/import_users.go
@@ -143,8 +143,15 @@ func (u *UserToImport) PhoneNumber(phoneNumber string) *UserToImport {
 
 // Metadata setter.
 func (u *UserToImport) Metadata(metadata *UserMetadata) *UserToImport {
-	u.set("createdAt", metadata.CreationTimestamp)
-	return u.set("lastLoginAt", metadata.LastLogInTimestamp)
+	if metadata.CreationTimestamp != 0 {
+		u.set("createdAt", metadata.CreationTimestamp)
+	}
+
+	if metadata.LastLogInTimestamp != 0 {
+		u.set("lastLoginAt", metadata.LastLogInTimestamp)
+	}
+
+	return u
 }
 
 // CustomClaims setter.


Test patch:
diff --git a/auth/user_mgt_test.go b/auth/user_mgt_test.go
index dcdcf45..f6552d1 100644
--- a/auth/user_mgt_test.go
+++ b/auth/user_mgt_test.go
@@ -1184,6 +1184,24 @@ func TestUserToImport(t *testing.T) {
 				"lastLoginAt": int64(150),
 			},
 		},
+		{
+			user: (&UserToImport{}).UID("test").Metadata(&UserMetadata{
+				CreationTimestamp: int64(100),
+			}),
+			want: map[string]interface{}{
+				"localId":   "test",
+				"createdAt": int64(100),
+			},
+		},
+		{
+			user: (&UserToImport{}).UID("test").Metadata(&UserMetadata{
+				LastLogInTimestamp: int64(150),
+			}),
+			want: map[string]interface{}{
+				"localId":     "test",
+				"lastLoginAt": int64(150),
+			},
+		},
 		{
 			user: (&UserToImport{}).UID("test").PasswordHash([]byte("password")),
 			want: map[string]interface{}{
Repository: firecracker-microvm/firecracker-containerd
Pull request #80 (2019-01-31 22:54:48)

naive: fix calculation for expected size
naive: fix calculation for expected size

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.



Patch:
diff --git a/snapshotter/naive/naive.go b/snapshotter/naive/naive.go
index 3d50c95..41f106c 100644
--- a/snapshotter/naive/naive.go
+++ b/snapshotter/naive/naive.go
@@ -36,6 +36,7 @@ const (
 	imageDirName      = "images"
 	imageFSType       = "ext4"
 	sparseImageSizeMB = 1024
+	mib               = 1048576
 )
 
 // Snapshotter implements naive snapshotter for containerd
@@ -302,7 +303,7 @@ func (s *Snapshotter) createImage(ctx context.Context, imagePath string, fileSiz
 		return err
 	}
 
-	if err := file.Truncate(int64(fileSizeMB) * 1048576); err != nil {
+	if err := file.Truncate(int64(fileSizeMB) * mib); err != nil {
 		return err
 	}
 


Test patch:
diff --git a/snapshotter/naive/naive_test.go b/snapshotter/naive/naive_test.go
index 7d43a5c..0d973ac 100644
--- a/snapshotter/naive/naive_test.go
+++ b/snapshotter/naive/naive_test.go
@@ -40,11 +40,11 @@ func TestCreateImage(t *testing.T) {
 	imgPath := filepath.Join(tempDir, "x.img")
 
 	const (
-		sizeMB    = 100
-		sizeBytes = sizeMB * 100000
+		sizeMiB   = 100
+		sizeBytes = sizeMiB * mib
 	)
 
-	err = snap.createImage(context.Background(), imgPath, sizeMB)
+	err = snap.createImage(context.Background(), imgPath, sizeMiB)
 	if err != nil {
 		t.Fatal(err)
 	}