func main() { fake, _ := faker.New("en") db := connectSqliteDB() db.DB().Ping() db.LogMode(true) var cdrs []CDRgorm // var cdrs []map[string]interface{} // db.Raw("SELECT rowid, caller_id_name, destination_number FROM cdr LIMIT ?", 10).Scan(cdrs) db.Limit(10).Find(&cdrs) // fmt.Printf("%s - %v\n", query, cdrs) fmt.Println(cdrs) fmt.Println("-------------------------------") var listcdr = []CDRgorm{} var cdr CDRgorm for i := 0; i < 2; i++ { uuid4, _ := uuid.NewV4() cdr = CDRgorm{CallerIDName: fake.Name(), CallerIDNumber: fake.PhoneNumber(), DestinationNumber: fake.CellPhoneNumber(), UUID: uuid4.String(), Duration: random(30, 300), Billsec: random(30, 300), StartStamp: time.Now(), AnswerStamp: time.Now(), EndStamp: time.Now()} listcdr = append(listcdr, cdr) } fmt.Println("listcdr:\n%# v\n\n", listcdr) fmt.Println(db.NewRecord(cdr)) db.Create(listcdr) fmt.Println(db.NewRecord(cdr)) }
func genFakeUsers(total int) []instagram.User { f, _ := faker.New("en") f.Rand = rand.New(rand.NewSource(42)) fakeUsers := make([]instagram.User, total) for i := 0; i < total; i++ { fakeUsers[i] = genFakeUser(f) } return fakeUsers }
// GenerateCDR creates a certain amount of CDRs to a given SQLite database func GenerateCDR(sqliteDBpath string, amount int) error { once.Do(func() { orm.RegisterDriver("sqlite3", orm.DRSqlite) orm.RegisterDataBase("default", "sqlite3", sqliteDBpath) orm.RegisterModel(new(CDR)) // You may wish to automatically create your database tables // Database alias. name := "default" // Drop table and re-create. force := true verbose := true err := orm.RunSyncdb(name, force, verbose) if err != nil { log.Error(err) } }) log.Debug("!!! We will populate " + sqliteDBpath + " with " + strconv.Itoa(amount) + " CDRs !!!") fake, _ := faker.New("en") // connectSqliteDB(sqliteDBpath) o := orm.NewOrm() // orm.Debug = true o.Using("default") var listcdr = []CDR{} for i := 0; i < amount; i++ { uuid4, _ := uuid.NewV4() cidname := fake.Name() // cidnum := fake.PhoneNumber() cidnum := fmt.Sprintf("+%d600%d", random(25, 39), random(100000, 999999)) // TODO: create fake.IntPhoneNumber // dstnum := fake.CellPhoneNumber() dstnum := fmt.Sprintf("+%d800%d", random(25, 49), random(100000, 999999)) duration := random(30, 300) billsec := duration - 10 hangupcause_id := random(15, 20) cdr := CDR{CallerIDName: cidname, CallerIDNumber: cidnum, DestinationNumber: dstnum, UUID: uuid4.String(), Duration: duration, Billsec: billsec, StartStamp: time.Now(), AnswerStamp: time.Now(), EndStamp: time.Now(), HangupCauseID: hangupcause_id, AccountCode: "1"} listcdr = append(listcdr, cdr) } successNums, err := o.InsertMulti(50, listcdr) if err != nil { log.Error(err.Error()) return err } log.Info("Generate Fake CDRs, inserted: ", successNums) return nil }
func genFakeUser(f *faker.Faker) instagram.User { if f == nil { f, _ = faker.New("en") f.Rand = rand.New(rand.NewSource(42)) } return instagram.User{ Username: f.Name(), FullName: f.UserName(), } }
func NewMarketSeeder() *marketseeder { f, _ := faker.New("en") m := NewMarket() return &marketseeder{ conn: NewRedisConnection(), faker: f, market: m, } }
func createRepo(t *testing.T, record bool) string { // Create new Faker instance since it's not thread-safe // https://github.com/manveru/faker/issues/6 faker, err := faker.New("en") require.Nil(t, err) // create repo repo := TestPrefix + faker.UserName() req := Client.NewRequest(t, "POST", "/user/repos", jsons.Parse(`{"name": %q}`, repo)) if record { req.EnableRecording("repo_create.apib") } j := Client.Do(t, req, 201).JSON(t) assert.Equal(t, jsons.Parse(`{"name": %q, "full_name": %q}`, repo, Login+"/"+repo), j.KeepFields("name", "full_name")) assert.Equal(t, jsons.Parse(`{"login": %q}`, Login), j.Get("/owner").KeepFields("login")) return repo }
func main() { fake, _ := faker.New("en") o := orm.NewOrm() o.Using("default") fmt.Println("-------------------------------") var listcdr = []CDR{} var cdr CDR for i := 0; i < 100; i++ { uuid4, _ := uuid.NewV4() cdr = CDR{CallerIDName: fake.Name(), CallerIDNumber: fake.PhoneNumber(), DestinationNumber: fake.CellPhoneNumber(), UUID: uuid4.String(), Duration: random(30, 300), Billsec: random(30, 300), StartStamp: time.Now(), AnswerStamp: time.Now(), EndStamp: time.Now()} listcdr = append(listcdr, cdr) } successNums, err := o.InsertMulti(50, listcdr) fmt.Printf("ID: %d, ERR: %v\n", successNums, err) // fmt.Println("listcdr:\n%# v\n\n", listcdr) }
func newFaker() *faker.Faker { fake, _ := faker.New("en") fake.Rand = rand.New(rand.NewSource(time.Now().UTC().UnixNano())) return fake }