From 6ac98b5e58be471f66b8b0111e84e92ec3c9f414 Mon Sep 17 00:00:00 2001 From: Irene Velychko Date: Wed, 12 Sep 2018 21:35:50 +0200 Subject: [PATCH 1/9] Generate random string for string type --- datafiller.go | 14 +++++++++++++- datafiller_test.go | 6 ++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/datafiller.go b/datafiller.go index dc3a804..556e1fe 100644 --- a/datafiller.go +++ b/datafiller.go @@ -17,6 +17,10 @@ func init() { const ( taggedStructKey = "datafiller" + // for random string generation + letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + letterIdxBits = 6 // 6 bits to represent a letter index + letterIdxMask = 1< Date: Wed, 10 Apr 2019 10:51:42 -0700 Subject: [PATCH 2/9] Increased string size to 12 instead of 10 --- datafiller.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/datafiller.go b/datafiller.go index 556e1fe..ea287f0 100644 --- a/datafiller.go +++ b/datafiller.go @@ -18,7 +18,7 @@ func init() { const ( taggedStructKey = "datafiller" // for random string generation - letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" letterIdxBits = 6 // 6 bits to represent a letter index letterIdxMask = 1< Date: Wed, 10 Apr 2019 11:12:17 -0700 Subject: [PATCH 3/9] Fixed random int generation that was occasionally failing the tests that checked for a zero value in the generated int --- datafiller.go | 4 ++-- go.mod | 8 ++++++++ go.sum | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 go.mod create mode 100644 go.sum diff --git a/datafiller.go b/datafiller.go index ea287f0..3ce9044 100644 --- a/datafiller.go +++ b/datafiller.go @@ -126,14 +126,14 @@ func (self *Filler) recursiveSet(val reflect.Value) { val.Kind() == reflect.Int16 || val.Kind() == reflect.Int32 || val.Kind() == reflect.Int64 { - val.SetInt(self.randSeed.Int63n(100)) + val.SetInt(self.randSeed.Int63n((100 - 1) + 1)) return } else if val.Kind() == reflect.Uint || val.Kind() == reflect.Uint8 || val.Kind() == reflect.Uint16 || val.Kind() == reflect.Uint32 || val.Kind() == reflect.Uint64 { - val.SetUint(uint64(self.randSeed.Int63n(100))) + val.SetUint(uint64(self.randSeed.Int63n((100 - 1) + 1))) return } else if val.Kind() == reflect.Float32 || val.Kind() == reflect.Float64 { diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..24263b4 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module datafiller + +go 1.12 + +require ( + github.com/Pallinder/go-randomdata v1.1.0 + github.com/tvi/datafiller v0.0.0-20170207191639-26c75631fdca +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..885f972 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/Pallinder/go-randomdata v1.1.0 h1:gUubB1IEUliFmzjqjhf+bgkg1o6uoFIkRsP3VrhEcx8= +github.com/Pallinder/go-randomdata v1.1.0/go.mod h1:yHmJgulpD2Nfrm0cR9tI/+oAgRqCQQixsA8HyRZfV9Y= +github.com/tvi/datafiller v0.0.0-20170207191639-26c75631fdca h1:pKL7Xjs3N/mbwM5tkKeyrPOkhAdf1TVS6WezlfIaj6U= +github.com/tvi/datafiller v0.0.0-20170207191639-26c75631fdca/go.mod h1:0TsW2YcdzAzALzz2AIVkNbS8fEjoISeFCfx1Y4EKSL0= From 5fa2bef4244c4353d73be46b7c9d128ddf6179bd Mon Sep 17 00:00:00 2001 From: chipkeyes Date: Wed, 10 Apr 2019 11:27:18 -0700 Subject: [PATCH 4/9] Fixed go mod file import --- example/easy.go | 3 ++- go.mod | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/example/easy.go b/example/easy.go index 1e16caf..1803a92 100644 --- a/example/easy.go +++ b/example/easy.go @@ -3,7 +3,8 @@ package main import ( "encoding/json" "fmt" - "github.com/tvi/datafiller" + + "datafiller" ) type S struct { diff --git a/go.mod b/go.mod index 24263b4..71580e0 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,6 @@ module datafiller go 1.12 -require ( - github.com/Pallinder/go-randomdata v1.1.0 - github.com/tvi/datafiller v0.0.0-20170207191639-26c75631fdca -) +require github.com/Pallinder/go-randomdata v1.1.0 + +replace datafiller => ./ From 380d486f5ebab6c6653a2c5a28b82e67dcd26853 Mon Sep 17 00:00:00 2001 From: chipkeyes Date: Wed, 10 Apr 2019 11:35:08 -0700 Subject: [PATCH 5/9] Fixed go mod file import --- example/easy.go | 3 +-- go.mod | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/example/easy.go b/example/easy.go index 1803a92..592ff83 100644 --- a/example/easy.go +++ b/example/easy.go @@ -1,10 +1,9 @@ package main import ( + "datafiller" "encoding/json" "fmt" - - "datafiller" ) type S struct { diff --git a/go.mod b/go.mod index 71580e0..8d73090 100644 --- a/go.mod +++ b/go.mod @@ -3,5 +3,3 @@ module datafiller go 1.12 require github.com/Pallinder/go-randomdata v1.1.0 - -replace datafiller => ./ From 694da8aa8bca9c2a8be70150ab6f5fc22d9bb7ec Mon Sep 17 00:00:00 2001 From: chipkeyes Date: Wed, 10 Apr 2019 11:37:20 -0700 Subject: [PATCH 6/9] removed example file that was causing issues with the module system. --- README.md | 4 ++-- example/easy.go | 26 -------------------------- 2 files changed, 2 insertions(+), 28 deletions(-) delete mode 100644 example/easy.go diff --git a/README.md b/README.md index 5746f6f..53e19dc 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A Golang package for filling structs by random data. # Installation -`go get github.com/erggo/datafiller` +`go get github.com/HelpfulHuman/datafiller` # Sample Usage ```go @@ -16,7 +16,7 @@ package main import ( "encoding/json" "fmt" - "github.com/erggo/datafiller" + "github.com/HelpfulHuman/datafiller" ) type S struct { diff --git a/example/easy.go b/example/easy.go deleted file mode 100644 index 592ff83..0000000 --- a/example/easy.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -import ( - "datafiller" - "encoding/json" - "fmt" -) - -type S struct { - A string - B struct { - C string - D string - E int - } -} - -func main() { - i := S{} - datafiller.Fill(&i) - b, err := json.Marshal(i) - if err != nil { - return - } - fmt.Println(string(b)) -} From ba118215012d7f3e2d1218f3444bc9159bc11b18 Mon Sep 17 00:00:00 2001 From: chipkeyes Date: Wed, 10 Apr 2019 11:50:49 -0700 Subject: [PATCH 7/9] updated the go.sum which was still pulling in datafiller as a dependancy --- go.sum | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.sum b/go.sum index 885f972..34756b7 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,2 @@ github.com/Pallinder/go-randomdata v1.1.0 h1:gUubB1IEUliFmzjqjhf+bgkg1o6uoFIkRsP3VrhEcx8= github.com/Pallinder/go-randomdata v1.1.0/go.mod h1:yHmJgulpD2Nfrm0cR9tI/+oAgRqCQQixsA8HyRZfV9Y= -github.com/tvi/datafiller v0.0.0-20170207191639-26c75631fdca h1:pKL7Xjs3N/mbwM5tkKeyrPOkhAdf1TVS6WezlfIaj6U= -github.com/tvi/datafiller v0.0.0-20170207191639-26c75631fdca/go.mod h1:0TsW2YcdzAzALzz2AIVkNbS8fEjoISeFCfx1Y4EKSL0= From 389ab8accf979d17f7eb037f8727f18925b50dbd Mon Sep 17 00:00:00 2001 From: chipkeyes Date: Wed, 10 Apr 2019 13:52:31 -0700 Subject: [PATCH 8/9] Updated mod file with correct module definition. --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 8d73090..ed248da 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module datafiller +module github.com/HelpfulHuman/datafiller go 1.12 From aae751aee445cabca5c9cb300bb8ebc41cec08c1 Mon Sep 17 00:00:00 2001 From: Irene Velychko Date: Mon, 15 Jul 2019 18:34:13 +0300 Subject: [PATCH 9/9] Fix random int generation (set minimum int to 1) --- datafiller.go | 4 ++-- datafiller_test.go | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/datafiller.go b/datafiller.go index 3ce9044..ff8f550 100644 --- a/datafiller.go +++ b/datafiller.go @@ -126,14 +126,14 @@ func (self *Filler) recursiveSet(val reflect.Value) { val.Kind() == reflect.Int16 || val.Kind() == reflect.Int32 || val.Kind() == reflect.Int64 { - val.SetInt(self.randSeed.Int63n((100 - 1) + 1)) + val.SetInt(self.randSeed.Int63n(100) + 1) return } else if val.Kind() == reflect.Uint || val.Kind() == reflect.Uint8 || val.Kind() == reflect.Uint16 || val.Kind() == reflect.Uint32 || val.Kind() == reflect.Uint64 { - val.SetUint(uint64(self.randSeed.Int63n((100 - 1) + 1))) + val.SetUint(uint64(self.randSeed.Int63n(100) + 1)) return } else if val.Kind() == reflect.Float32 || val.Kind() == reflect.Float64 { diff --git a/datafiller_test.go b/datafiller_test.go index cf96e12..f23107c 100644 --- a/datafiller_test.go +++ b/datafiller_test.go @@ -146,16 +146,16 @@ func TestSimpleValues(t *testing.T) { value interface{} expectedValue interface{} }{ - {&IntV, int(55)}, - {&Int8V, int8(55)}, - {&Int16V, int16(55)}, - {&Int32V, int32(55)}, - {&Int64V, int64(55)}, - {&UintV, uint(55)}, - {&Uint8V, uint8(55)}, - {&Uint16V, uint16(55)}, - {&Uint32V, uint32(55)}, - {&Uint64V, uint64(55)}, + {&IntV, int(56)}, + {&Int8V, int8(56)}, + {&Int16V, int16(56)}, + {&Int32V, int32(56)}, + {&Int64V, int64(56)}, + {&UintV, uint(56)}, + {&Uint8V, uint8(56)}, + {&Uint16V, uint16(56)}, + {&Uint32V, uint32(56)}, + {&Uint64V, uint64(56)}, {&Float32V, float32(0.91889215)}, {&Float64V, float64(0.9188921451568604)}, // {&Complex64V, complex(0.91889215, 0.23150717)},