Add user store tests

This commit is contained in:
Miguel de la Cruz 2021-09-11 23:50:53 +02:00
parent 143c3a8b81
commit 5d82d485c8
37 changed files with 3674 additions and 3 deletions

2
go.mod
View file

@ -5,11 +5,13 @@ go 1.17
require ( require (
github.com/Masterminds/squirrel v1.5.0 github.com/Masterminds/squirrel v1.5.0
github.com/google/uuid v1.3.0 github.com/google/uuid v1.3.0
github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428
github.com/mattn/go-sqlite3 v1.14.8 github.com/mattn/go-sqlite3 v1.14.8
github.com/stretchr/testify v1.7.0 github.com/stretchr/testify v1.7.0
) )
require ( require (
github.com/corpix/uarand v0.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect

12
go.sum
View file

@ -1,24 +1,36 @@
github.com/Masterminds/glide v0.13.2/go.mod h1:STyF5vcenH/rUqTEv+/hBXlSTo7KYwg2oc2f4tzPWic=
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Masterminds/squirrel v1.5.0 h1:JukIZisrUXadA9pl3rMkjhiamxiB0cXiu+HGp/Y8cY8= github.com/Masterminds/squirrel v1.5.0 h1:JukIZisrUXadA9pl3rMkjhiamxiB0cXiu+HGp/Y8cY8=
github.com/Masterminds/squirrel v1.5.0/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10= github.com/Masterminds/squirrel v1.5.0/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10=
github.com/Masterminds/vcs v1.13.0/go.mod h1:N09YCmOQr6RLxC6UNHzuVwAdodYbbnycGHSmwVJjcKA=
github.com/codegangsta/cli v1.20.0/go.mod h1:/qJNoX69yVSKu5o4jLyXAENLRyk1uhi7zkbQ3slBdOA=
github.com/corpix/uarand v0.1.1 h1:RMr1TWc9F4n5jiPDzFHtmaUXLKLNUFK0SgCLo4BhX/U=
github.com/corpix/uarand v0.1.1/go.mod h1:SFKZvkcRoLqVRFZ4u25xPmp6m9ktANfbpXZ7SJ0/FNU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428 h1:Mo9W14pwbO9VfRe+ygqZ8dFbPpoIK1HFrG/zjTuQ+nc=
github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428/go.mod h1:uhpZMVGznybq1itEKXj6RYw9I71qK4kH+OGMjRC4KEo=
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw= github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw=
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o= github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o=
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk= github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk=
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw= github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw=
github.com/mattn/go-sqlite3 v1.14.8 h1:gDp86IdQsN/xWjIEmr9MF6o9mpksUgh0fu+9ByFxzIU= github.com/mattn/go-sqlite3 v1.14.8 h1:gDp86IdQsN/xWjIEmr9MF6o9mpksUgh0fu+9ByFxzIU=
github.com/mattn/go-sqlite3 v1.14.8/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/mattn/go-sqlite3 v1.14.8/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/ngdinhtoan/glide-cleanup v0.2.0/go.mod h1:UQzsmiDOb8YV3nOsCxK/c9zPpCZVNoHScRE3EO9pVMM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View file

@ -29,13 +29,13 @@ func NewStore(path string) (*Store, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
s.Conn = conn
if err := s.EnsureSchema(); err != nil { if err := s.EnsureSchema(); err != nil {
return nil, err return nil, err
} }
s.Conn = conn // init stores
s.userStore = NewUserStore(s) s.userStore = NewUserStore(s)
return s, nil return s, nil

40
services/store/testlib.go Normal file
View file

@ -0,0 +1,40 @@
package store
import (
"testing"
"git.ctrlz.es/mgdelacroix/rmsn/model"
"github.com/icrowley/fake"
"github.com/stretchr/testify/require"
)
type TestHelper struct {
t *testing.T
store *Store
}
func NewTestHelper(t *testing.T) (*TestHelper, func()) {
s, err := NewStore(":memory:")
require.NoError(t, err)
teardown := func() {
require.NoError(t, s.Close())
}
return &TestHelper{t: t, store: s}, teardown
}
func (th *TestHelper) NewUser() *model.User {
user := &model.User{
Name: fake.FullName(),
Mail: fake.EmailAddress(),
Username: fake.UserName(),
Password: fake.SimplePassword(),
}
newUser, err := th.store.User().Create(user)
require.NoError(th.t, err)
return newUser
}

View file

@ -70,7 +70,7 @@ func (us *UserStore) GetByID(id int) (*model.User, error) {
func (us *UserStore) Create(user *model.User) (*model.User, error) { func (us *UserStore) Create(user *model.User) (*model.User, error) {
query := us.Q().Insert("users"). query := us.Q().Insert("users").
Columns(userColumns[0:len(userColumns)-1]...). Columns(userColumns[1:]...).
Values(user.Name, user.Mail, user.Username, user.Password) Values(user.Name, user.Mail, user.Username, user.Password)
res, err := query.Exec() res, err := query.Exec()

View file

@ -0,0 +1,44 @@
package store
import (
"testing"
"git.ctrlz.es/mgdelacroix/rmsn/model"
"github.com/stretchr/testify/require"
)
func TestCreateUser(t *testing.T) {
th, teardown := NewTestHelper(t)
defer teardown()
user := &model.User{
Name: "John",
Mail: "john_doe@example.com",
Username: "john_doe",
Password: "mysupersecret",
}
newUser, err := th.store.User().Create(user)
require.NoError(t, err)
require.NotZero(t, newUser.ID)
require.Equal(t, user.Name, newUser.Name)
require.Equal(t, user.Mail, newUser.Mail)
require.Equal(t, user.Username, newUser.Username)
require.Equal(t, user.Password, newUser.Password)
}
func TestGetByID(t *testing.T) {
th, teardown := NewTestHelper(t)
defer teardown()
user := th.NewUser()
user2, err := th.store.User().GetByID(user.ID)
require.NoError(t, err)
require.Equal(t, user.ID, user2.ID)
require.Equal(t, user.Name, user2.Name)
require.Equal(t, user.Mail, user2.Mail)
require.Equal(t, user.Username, user2.Username)
require.Equal(t, user.Password, user2.Password)
}

2
vendor/github.com/corpix/uarand/.gitignore generated vendored Normal file
View file

@ -0,0 +1,2 @@
/build
*~

3
vendor/github.com/corpix/uarand/.travis.yml generated vendored Normal file
View file

@ -0,0 +1,3 @@
language: nix
script: nix-shell --pure --command "make lint test"

24
vendor/github.com/corpix/uarand/LICENSE generated vendored Normal file
View file

@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>

32
vendor/github.com/corpix/uarand/Makefile generated vendored Normal file
View file

@ -0,0 +1,32 @@
.DEFAULT_GOAL = all
version := $(shell git rev-list --count HEAD).$(shell git rev-parse --short HEAD)
name := uarand
package := github.com/corpix/$(name)
.PHONY: all
all:: useragents.go
.PHONY: test
test:
go test -v ./...
.PHONY: lint
lint:
.PHONY: lint
lint:
golangci-lint --color=always \
--exclude='uses unkeyed fields' \
--exclude='type .* is unused' \
--exclude='should merge variable declaration with assignment on next line' \
--deadline=120s \
run ./...
.PHONY: check
check: lint test
.PHONY: useragents.go
useragents.go:
./scripts/fetch-user-agents | ./scripts/generate-useragents-go $(name) > $@
go fmt $@

38
vendor/github.com/corpix/uarand/README.md generated vendored Normal file
View file

@ -0,0 +1,38 @@
uarand
----------------
[![Build Status](https://travis-ci.org/corpix/uarand.svg?branch=master)](https://travis-ci.org/corpix/uarand)
Random user-agent producer for go.
## Example
``` go
package main
import (
"fmt"
"github.com/corpix/uarand"
)
func main() {
fmt.Println(uarand.GetRandom())
}
```
Save it to `snippet.go` and run:
``` shell
go run snippet.go
```
Which should produce something similar to:
``` text
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.0 Safari/537.36
```
## License
[Unlicense](https://unlicense.org/)

17
vendor/github.com/corpix/uarand/shell.nix generated vendored Normal file
View file

@ -0,0 +1,17 @@
let
nixpkgs = builtins.fetchTarball {
url = "https://github.com/nixos/nixpkgs/archive/ddf38a8241089d79c3bcd1777781b6438ab88d84.tar.gz";
sha256 = "0fjk69mn58h0gjzgxgnkfkhhf1l707bg2cn4823ma9xbjxbhl0ya";
};
in with import nixpkgs {};
stdenv.mkDerivation {
name = "nix-shell";
buildInputs = [
coreutils bashInteractive jq curl gcc git gnumake
go golangci-lint cacert openssl
];
shellHook = ''
unset GOPATH
export NIX_PATH=nixpkgs=${nixpkgs}
'';
}

63
vendor/github.com/corpix/uarand/uarand.go generated vendored Normal file
View file

@ -0,0 +1,63 @@
package uarand
import (
"math/rand"
"sync"
"time"
)
var (
// Default is the UARand with default settings.
Default = New(
rand.New(
rand.NewSource(time.Now().UnixNano()),
),
)
)
// Randomizer represents some entity which could provide us an entropy.
type Randomizer interface {
Seed(n int64)
Intn(n int) int
}
// UARand describes the user agent randomizer settings.
type UARand struct {
Randomizer
UserAgents []string
mutex sync.Mutex
}
// GetRandom returns a random user agent from UserAgents slice.
func (u *UARand) GetRandom() string {
u.mutex.Lock()
n := u.Intn(len(u.UserAgents))
u.mutex.Unlock()
return u.UserAgents[n]
}
// GetRandom returns a random user agent from UserAgents slice.
// This version is driven by Default configuration.
func GetRandom() string {
return Default.GetRandom()
}
// New return UserAgent randomizer settings with default user-agents list
func New(r Randomizer) *UARand {
return &UARand{
Randomizer: r,
UserAgents: UserAgents,
mutex: sync.Mutex{},
}
}
// NewWithCustomList return UserAgent randomizer settings with custom user-agents list
func NewWithCustomList(userAgents []string) *UARand {
return &UARand{
Randomizer: rand.New(rand.NewSource(time.Now().UnixNano())),
UserAgents: userAgents,
mutex: sync.Mutex{},
}
}

1735
vendor/github.com/corpix/uarand/useragents.go generated vendored Normal file

File diff suppressed because it is too large Load diff

26
vendor/github.com/icrowley/fake/.gitignore generated vendored Normal file
View file

@ -0,0 +1,26 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
/vendor
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof
.DS_Store

11
vendor/github.com/icrowley/fake/.go-makefile.json generated vendored Normal file
View file

@ -0,0 +1,11 @@
{
"build_id_generator": "0x$(shell echo $(version) | sha1sum | awk '{print $$1}')",
"host": "github.com",
"include": [],
"kind": "package",
"name": "fake",
"tool": [],
"user": "icrowley",
"version_generator": "$(shell git rev-list --count HEAD).$(shell git rev-parse --short HEAD)",
"version_variable": "cli.version"
}

11
vendor/github.com/icrowley/fake/.travis.yml generated vendored Normal file
View file

@ -0,0 +1,11 @@
sudo: false
language: go
go:
- 1.6
- 1.7
- 1.8
- master
- tip
script: make test

22
vendor/github.com/icrowley/fake/LICENSE generated vendored Normal file
View file

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2014 Dmitry Afanasyev
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

48
vendor/github.com/icrowley/fake/Makefile generated vendored Normal file
View file

@ -0,0 +1,48 @@
.DEFAULT_GOAL = all
numcpus := $(shell cat /proc/cpuinfo | grep '^processor\s*:' | wc -l)
version := $(shell git rev-list --count HEAD).$(shell git rev-parse --short HEAD)
name := fake
package := github.com/icrowley/$(name)
.PHONY: all
all:: dependencies
.PHONY: tools
tools::
@if [ ! -e "$(GOPATH)"/bin/glide ]; then go get github.com/Masterminds/glide; fi
@if [ ! -e "$(GOPATH)"/bin/godef ]; then go get github.com/rogpeppe/godef; fi
@if [ ! -e "$(GOPATH)"/bin/gocode ]; then go get github.com/nsf/gocode; fi
@if [ ! -e "$(GOPATH)"/bin/gometalinter ]; then go get github.com/alecthomas/gometalinter && gometalinter --install; fi
@if [ ! -e "$(GOPATH)"/src/github.com/stretchr/testify/assert ]; then go get github.com/stretchr/testify/assert; fi
.PHONY: dependencies
dependencies:: tools
glide install
.PHONY: clean
clean:: tools
glide cache-clear
.PHONY: test
test:: dependencies
go test -v \
$(shell glide novendor)
.PHONY: bench
bench:: dependencies
go test \
-bench=. -v \
$(shell glide novendor)
.PHONY: lint
lint:: dependencies
go vet $(shell glide novendor)
gometalinter \
--deadline=5m \
--concurrency=$(numcpus) \
$(shell glide novendor)
.PHONY: check
check:: lint test

90
vendor/github.com/icrowley/fake/README.md generated vendored Normal file
View file

@ -0,0 +1,90 @@
[![Build Status](https://img.shields.io/travis/icrowley/fake.svg?style=flat)](https://travis-ci.org/icrowley/fake) [![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/icrowley/fake) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/icrowley/fake/master/LICENSE)
Fake
====
Fake is a fake data generator for Go (Golang), heavily inspired by the forgery and ffaker Ruby gems.
## About
Most data and methods are ported from forgery/ffaker Ruby gems.
For the list of available methods please look at https://godoc.org/github.com/icrowley/fake.
Currently english and russian languages are available.
Fake embeds samples data files unless you call `UseExternalData(true)` in order to be able to work without external files dependencies when compiled, so, if you add new data files or make changes to existing ones don't forget to regenerate data.go file using `github.com/mjibson/esc` tool and `esc -o data.go -pkg fake data` command (or you can just use `go generate` command if you are using Go 1.4 or later).
## Install
```shell
go get github.com/icrowley/fake
```
## Import
```go
import (
"github.com/icrowley/fake"
)
```
## Documentation
Documentation can be found at godoc:
https://godoc.org/github.com/icrowley/fake
## Test
To run the project tests:
```shell
cd test
go test
```
## Examples
```go
name := fake.FirstName()
fullname := fake.FullName()
product := fake.Product()
```
Changing language:
```go
err := fake.SetLang("ru")
if err != nil {
panic(err)
}
password := fake.SimplePassword()
```
Using english fallback:
```go
err := fake.SetLang("ru")
if err != nil {
panic(err)
}
fake.EnFallback(true)
password := fake.Paragraph()
```
Using external data:
```go
fake.UseExternalData(true)
password := fake.Paragraph()
```
### Author
Dmitry Afanasyev,
http://twitter.com/i_crowley
dimarzio1986@gmail.com
### Maintainers
Dmitry Moskowski
https://github.com/corpix

69
vendor/github.com/icrowley/fake/addresses.go generated vendored Normal file
View file

@ -0,0 +1,69 @@
package fake
import "strconv"
// Continent generates random continent
func Continent() string {
return lookup(lang, "continents", true)
}
// Country generates random country
func Country() string {
return lookup(lang, "countries", true)
}
// City generates random city
func City() string {
city := lookup(lang, "cities", true)
switch r.Intn(5) {
case 0:
return join(cityPrefix(), city)
case 1:
return join(city, citySuffix())
default:
return city
}
}
func cityPrefix() string {
return lookup(lang, "city_prefixes", false)
}
func citySuffix() string {
return lookup(lang, "city_suffixes", false)
}
// State generates random state
func State() string {
return lookup(lang, "states", false)
}
// StateAbbrev generates random state abbreviation
func StateAbbrev() string {
return lookup(lang, "state_abbrevs", false)
}
// Street generates random street name
func Street() string {
street := lookup(lang, "streets", true)
return join(street, streetSuffix())
}
// StreetAddress generates random street name along with building number
func StreetAddress() string {
return join(Street(), strconv.Itoa(r.Intn(100)))
}
func streetSuffix() string {
return lookup(lang, "street_suffixes", true)
}
// Zip generates random zip code using one of the formats specifies in zip_format file
func Zip() string {
return generate(lang, "zips", true)
}
// Phone generates random phone number using one of the formats format specified in phone_format file
func Phone() string {
return generate(lang, "phones", true)
}

69
vendor/github.com/icrowley/fake/credit_cards.go generated vendored Normal file
View file

@ -0,0 +1,69 @@
package fake
import (
"strings"
"strconv"
)
type creditCard struct {
vendor string
length int
prefixes []int
}
var creditCards = map[string]creditCard{
"visa": {"VISA", 16, []int{4539, 4556, 4916, 4532, 4929, 40240071, 4485, 4716, 4}},
"mastercard": {"MasterCard", 16, []int{51, 52, 53, 54, 55}},
"amex": {"American Express", 15, []int{34, 37}},
"discover": {"Discover", 16, []int{6011}},
}
// CreditCardType returns one of the following credit values:
// VISA, MasterCard, American Express and Discover
func CreditCardType() string {
n := len(creditCards)
var vendors []string
for _, cc := range creditCards {
vendors = append(vendors, cc.vendor)
}
return vendors[r.Intn(n)]
}
// CreditCardNum generated credit card number according to the card number rules
func CreditCardNum(vendor string) string {
if vendor != "" {
vendor = strings.ToLower(vendor)
} else {
var vendors []string
for v := range creditCards {
vendors = append(vendors, v)
}
vendor = vendors[r.Intn(len(vendors))]
}
card := creditCards[vendor]
prefix := strconv.Itoa(card.prefixes[r.Intn(len(card.prefixes))])
num := []rune(prefix)
for i := 0; i < card.length-len(prefix); i++ {
num = append(num, genCCDigit(num))
}
return string(num)
}
func genCCDigit(num []rune) rune {
sum := 0
for i := len(num) - 1; i >= 0; i-- {
n := int(num[i])
if i%2 != 0 {
sum += n
} else {
if n*2 > 9 {
sum += n*2 - 9
} else {
sum += n * 2
}
}
}
return rune(((sum/10+1)*10 - sum) % 10)
}

11
vendor/github.com/icrowley/fake/currencies.go generated vendored Normal file
View file

@ -0,0 +1,11 @@
package fake
// Currency generates currency name
func Currency() string {
return lookup(lang, "currencies", true)
}
// CurrencyCode generates currency code
func CurrencyCode() string {
return lookup(lang, "currency_codes", true)
}

493
vendor/github.com/icrowley/fake/data.go generated vendored Normal file

File diff suppressed because one or more lines are too long

42
vendor/github.com/icrowley/fake/dates.go generated vendored Normal file
View file

@ -0,0 +1,42 @@
package fake
// Day generates day of the month
func Day() int {
return r.Intn(31) + 1
}
// WeekDay generates name ot the week day
func WeekDay() string {
return lookup(lang, "weekdays", true)
}
// WeekDayShort generates abbreviated name of the week day
func WeekDayShort() string {
return lookup(lang, "weekdays_short", true)
}
// WeekdayNum generates number of the day of the week
func WeekdayNum() int {
return r.Intn(7) + 1
}
// Month generates month name
func Month() string {
return lookup(lang, "months", true)
}
// MonthShort generates abbreviated month name
func MonthShort() string {
return lookup(lang, "months_short", true)
}
// MonthNum generates month number (from 1 to 12)
func MonthNum() int {
return r.Intn(12) + 1
}
// Year generates year using the given boundaries
func Year(from, to int) int {
n := r.Intn(to-from) + 1
return from + n
}

214
vendor/github.com/icrowley/fake/fake.go generated vendored Normal file
View file

@ -0,0 +1,214 @@
/*
Package fake is the fake data generatror for go (Golang), heavily inspired by forgery and ffaker Ruby gems
Most data and methods are ported from forgery/ffaker Ruby gems.
Currently english and russian languages are available.
For the list of available methods please look at https://godoc.org/github.com/icrowley/fake.
Fake embeds samples data files unless you call UseExternalData(true) in order to be able to work without external files dependencies when compiled, so, if you add new data files or make changes to existing ones don't forget to regenerate data.go file using github.com/mjibson/esc tool and esc -o data.go -pkg fake data command (or you can just use go generate command if you are using Go 1.4 or later).
Examples:
name := fake.FirstName()
fullname = := fake.FullName()
product := fake.Product()
Changing language:
err := fake.SetLang("ru")
if err != nil {
panic(err)
}
password := fake.SimplePassword()
Using english fallback:
err := fake.SetLang("ru")
if err != nil {
panic(err)
}
fake.EnFallback(true)
password := fake.Paragraph()
Using external data:
fake.UseExternalData(true)
password := fake.Paragraph()
*/
package fake
import (
"fmt"
"io/ioutil"
"math/rand"
"strconv"
"strings"
"sync"
"time"
)
//go:generate go get github.com/mjibson/esc
//go:generate esc -o data.go -pkg fake data
// cat/subcat/lang/samples
type samplesTree map[string]map[string][]string
var samplesLock sync.Mutex
var samplesCache = make(samplesTree)
var r = rand.New(&rndSrc{src: rand.NewSource(time.Now().UnixNano())})
var lang = "en"
var useExternalData = false
var enFallback = true
var availLangs = GetLangs()
var (
// ErrNoLanguageFn is the error that indicates that given language is not available
ErrNoLanguageFn = func(lang string) error { return fmt.Errorf("The language passed (%s) is not available", lang) }
// ErrNoSamplesFn is the error that indicates that there are no samples for the given language
ErrNoSamplesFn = func(lang string) error { return fmt.Errorf("No samples found for language: %s", lang) }
)
// Seed uses the provided seed value to initialize the internal PRNG to a
// deterministic state.
func Seed(seed int64) {
r.Seed(seed)
}
type rndSrc struct {
mtx sync.Mutex
src rand.Source
}
func (s *rndSrc) Int63() int64 {
s.mtx.Lock()
n := s.src.Int63()
s.mtx.Unlock()
return n
}
func (s *rndSrc) Seed(n int64) {
s.mtx.Lock()
s.src.Seed(n)
s.mtx.Unlock()
}
// GetLangs returns a slice of available languages
func GetLangs() []string {
var langs []string
for k, v := range data {
if v.isDir && k != "/" && k != "/data" {
langs = append(langs, strings.Replace(k, "/data/", "", 1))
}
}
return langs
}
// SetLang sets the language in which the data should be generated
// returns error if passed language is not available
func SetLang(newLang string) error {
found := false
for _, l := range availLangs {
if newLang == l {
found = true
break
}
}
if !found {
return ErrNoLanguageFn(newLang)
}
lang = newLang
return nil
}
// UseExternalData sets the flag that allows using of external files as data providers (fake uses embedded ones by default)
func UseExternalData(flag bool) {
useExternalData = flag
}
// EnFallback sets the flag that allows fake to fallback to englsh samples if the ones for the used languaged are not available
func EnFallback(flag bool) {
enFallback = flag
}
func (st samplesTree) hasKeyPath(lang, cat string) bool {
if _, ok := st[lang]; ok {
if _, ok = st[lang][cat]; ok {
return true
}
}
return false
}
func join(parts ...string) string {
var filtered []string
for _, part := range parts {
if part != "" {
filtered = append(filtered, part)
}
}
return strings.Join(filtered, " ")
}
func generate(lang, cat string, fallback bool) string {
format := lookup(lang, cat+"_format", fallback)
var result string
for _, ru := range format {
if ru != '#' {
result += string(ru)
} else {
result += strconv.Itoa(r.Intn(10))
}
}
return result
}
func lookup(lang, cat string, fallback bool) string {
samplesLock.Lock()
s := _lookup(lang, cat, fallback)
samplesLock.Unlock()
return s
}
func _lookup(lang, cat string, fallback bool) string {
var samples []string
if samplesCache.hasKeyPath(lang, cat) {
samples = samplesCache[lang][cat]
} else {
var err error
samples, err = populateSamples(lang, cat)
if err != nil {
if lang != "en" && fallback && enFallback && err.Error() == ErrNoSamplesFn(lang).Error() {
return _lookup("en", cat, false)
}
return ""
}
}
return samples[r.Intn(len(samples))]
}
func populateSamples(lang, cat string) ([]string, error) {
data, err := readFile(lang, cat)
if err != nil {
return nil, err
}
if _, ok := samplesCache[lang]; !ok {
samplesCache[lang] = make(map[string][]string)
}
samples := strings.Split(strings.TrimSpace(string(data)), "\n")
samplesCache[lang][cat] = samples
return samples, nil
}
func readFile(lang, cat string) ([]byte, error) {
fullpath := fmt.Sprintf("/data/%s/%s", lang, cat)
file, err := FS(useExternalData).Open(fullpath)
if err != nil {
return nil, ErrNoSamplesFn(lang)
}
defer file.Close()
return ioutil.ReadAll(file)
}

79
vendor/github.com/icrowley/fake/general.go generated vendored Normal file
View file

@ -0,0 +1,79 @@
package fake
var lowerLetters = []rune("abcdefghijklmnopqrstuvwxyz")
var upperLetters = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
var numeric = []rune("0123456789")
var specialChars = []rune(`!'@#$%^&*()_+-=[]{};:",./?`)
var hexDigits = []rune("0123456789abcdef")
func text(atLeast, atMost int, allowLower, allowUpper, allowNumeric, allowSpecial bool) string {
allowedChars := []rune{}
if allowLower {
allowedChars = append(allowedChars, lowerLetters...)
}
if allowUpper {
allowedChars = append(allowedChars, upperLetters...)
}
if allowNumeric {
allowedChars = append(allowedChars, numeric...)
}
if allowSpecial {
allowedChars = append(allowedChars, specialChars...)
}
result := []rune{}
nTimes := r.Intn(atMost-atLeast+1) + atLeast
for i := 0; i < nTimes; i++ {
result = append(result, allowedChars[r.Intn(len(allowedChars))])
}
return string(result)
}
// Password generates password with the length from atLeast to atMOst charachers,
// allow* parameters specify whether corresponding symbols can be used
func Password(atLeast, atMost int, allowUpper, allowNumeric, allowSpecial bool) string {
return text(atLeast, atMost, true, allowUpper, allowNumeric, allowSpecial)
}
// SimplePassword is a wrapper around Password,
// it generates password with the length from 6 to 12 symbols, with upper characters and numeric symbols allowed
func SimplePassword() string {
return Password(6, 12, true, true, false)
}
// Color generates color name
func Color() string {
return lookup(lang, "colors", true)
}
// DigitsN returns n digits as a string
func DigitsN(n int) string {
digits := make([]rune, n)
for i := 0; i < n; i++ {
digits[i] = numeric[r.Intn(len(numeric))]
}
return string(digits)
}
// Digits returns from 1 to 5 digits as a string
func Digits() string {
return DigitsN(r.Intn(5) + 1)
}
func hexDigitsStr(n int) string {
var num []rune
for i := 0; i < n; i++ {
num = append(num, hexDigits[r.Intn(len(hexDigits))])
}
return string(num)
}
// HexColor generates hex color name
func HexColor() string {
return hexDigitsStr(6)
}
// HexColorShort generates short hex color name
func HexColorShort() string {
return hexDigitsStr(3)
}

57
vendor/github.com/icrowley/fake/geo.go generated vendored Normal file
View file

@ -0,0 +1,57 @@
package fake
// Latitude generates latitude (from -90.0 to 90.0)
func Latitude() float32 {
return r.Float32()*180 - 90
}
// LatitudeDegrees generates latitude degrees (from -90 to 90)
func LatitudeDegrees() int {
return r.Intn(180) - 90
}
// LatitudeMinutes generates latitude minutes (from 0 to 60)
func LatitudeMinutes() int {
return r.Intn(60)
}
// LatitudeSeconds generates latitude seconds (from 0 to 60)
func LatitudeSeconds() int {
return r.Intn(60)
}
// LatitudeDirection generates latitude direction (N(orth) o S(outh))
func LatitudeDirection() string {
if r.Intn(2) == 0 {
return "N"
}
return "S"
}
// Longitude generates longitude (from -180 to 180)
func Longitude() float32 {
return r.Float32()*360 - 180
}
// LongitudeDegrees generates longitude degrees (from -180 to 180)
func LongitudeDegrees() int {
return r.Intn(360) - 180
}
// LongitudeMinutes generates (from 0 to 60)
func LongitudeMinutes() int {
return r.Intn(60)
}
// LongitudeSeconds generates (from 0 to 60)
func LongitudeSeconds() int {
return r.Intn(60)
}
// LongitudeDirection generates (W(est) or E(ast))
func LongitudeDirection() string {
if r.Intn(2) == 0 {
return "W"
}
return "E"
}

6
vendor/github.com/icrowley/fake/glide.lock generated vendored Normal file
View file

@ -0,0 +1,6 @@
hash: 9238b15272824ad573d8ef645fb468cb646b72598c63eae8977c3410ebfebe4a
updated: 2017-07-23T15:10:00.972860398Z
imports:
- name: github.com/corpix/uarand
version: 031be390f409fb4bac8fb299e3bcd101479f89f8
testImports: []

3
vendor/github.com/icrowley/fake/glide.yaml generated vendored Normal file
View file

@ -0,0 +1,3 @@
package: github.com/icrowley/fake
import:
- package: github.com/corpix/uarand

77
vendor/github.com/icrowley/fake/internet.go generated vendored Normal file
View file

@ -0,0 +1,77 @@
package fake
import (
"net"
"strings"
"github.com/corpix/uarand"
)
// UserName generates user name in one of the following forms
// first name + last name, letter + last names or concatenation of from 1 to 3 lowercased words
func UserName() string {
gender := randGender()
switch r.Intn(3) {
case 0:
return lookup("en", gender+"_first_names", false) + lookup(lang, gender+"_last_names", false)
case 1:
return Character() + lookup(lang, gender+"_last_names", false)
default:
return strings.Replace(WordsN(r.Intn(3)+1), " ", "_", -1)
}
}
// TopLevelDomain generates random top level domain
func TopLevelDomain() string {
return lookup(lang, "top_level_domains", true)
}
// DomainName generates random domain name
func DomainName() string {
return Company() + "." + TopLevelDomain()
}
// EmailAddress generates email address
func EmailAddress() string {
return UserName() + "@" + DomainName()
}
// EmailSubject generates random email subject
func EmailSubject() string {
return Sentence()
}
// EmailBody generates random email body
func EmailBody() string {
return Paragraphs()
}
// DomainZone generates random domain zone
func DomainZone() string {
return lookup(lang, "domain_zones", true)
}
// IPv4 generates IPv4 address
func IPv4() string {
size := 4
ip := make([]byte, size)
for i := 0; i < size; i++ {
ip[i] = byte(r.Intn(256))
}
return net.IP(ip).To4().String()
}
// IPv6 generates IPv6 address
func IPv6() string {
size := 16
ip := make([]byte, size)
for i := 0; i < size; i++ {
ip[i] = byte(r.Intn(256))
}
return net.IP(ip).To16().String()
}
// UserAgent generates a random user agent.
func UserAgent() string {
return uarand.GetRandom()
}

25
vendor/github.com/icrowley/fake/jobs.go generated vendored Normal file
View file

@ -0,0 +1,25 @@
package fake
import (
"strings"
)
// Company generates company name
func Company() string {
return lookup(lang, "companies", true)
}
// JobTitle generates job title
func JobTitle() string {
job := lookup(lang, "jobs", true)
return strings.Replace(job, "#{N}", jobTitleSuffix(), 1)
}
func jobTitleSuffix() string {
return lookup(lang, "jobs_suffixes", false)
}
// Industry generates industry name
func Industry() string {
return lookup(lang, "industries", true)
}

103
vendor/github.com/icrowley/fake/lorem_ipsum.go generated vendored Normal file
View file

@ -0,0 +1,103 @@
package fake
import (
"strings"
)
// Character generates random character in the given language
func Character() string {
return lookup(lang, "characters", true)
}
// CharactersN generates n random characters in the given language
func CharactersN(n int) string {
var chars []string
for i := 0; i < n; i++ {
chars = append(chars, Character())
}
return strings.Join(chars, "")
}
// Characters generates from 1 to 5 characters in the given language
func Characters() string {
return CharactersN(r.Intn(5) + 1)
}
// Word generates random word
func Word() string {
return lookup(lang, "words", true)
}
// WordsN generates n random words
func WordsN(n int) string {
words := make([]string, n)
for i := 0; i < n; i++ {
words[i] = Word()
}
return strings.Join(words, " ")
}
// Words generates from 1 to 5 random words
func Words() string {
return WordsN(r.Intn(5) + 1)
}
// Title generates from 2 to 5 titleized words
func Title() string {
return strings.ToTitle(WordsN(2 + r.Intn(4)))
}
// Sentence generates random sentence
func Sentence() string {
var words []string
for i := 0; i < 3+r.Intn(12); i++ {
word := Word()
if r.Intn(5) == 0 {
word += ","
}
words = append(words, Word())
}
sentence := strings.Join(words, " ")
if r.Intn(8) == 0 {
sentence += "!"
} else {
sentence += "."
}
return sentence
}
// SentencesN generates n random sentences
func SentencesN(n int) string {
sentences := make([]string, n)
for i := 0; i < n; i++ {
sentences[i] = Sentence()
}
return strings.Join(sentences, " ")
}
// Sentences generates from 1 to 5 random sentences
func Sentences() string {
return SentencesN(r.Intn(5) + 1)
}
// Paragraph generates paragraph
func Paragraph() string {
return SentencesN(r.Intn(10) + 1)
}
// ParagraphsN generates n paragraphs
func ParagraphsN(n int) string {
var paragraphs []string
for i := 0; i < n; i++ {
paragraphs = append(paragraphs, Paragraph())
}
return strings.Join(paragraphs, "\t")
}
// Paragraphs generates from 1 to 5 paragraphs
func Paragraphs() string {
return ParagraphsN(r.Intn(5) + 1)
}

147
vendor/github.com/icrowley/fake/names.go generated vendored Normal file
View file

@ -0,0 +1,147 @@
package fake
func randGender() string {
g := "male"
if r.Intn(2) == 0 {
g = "female"
}
return g
}
func firstName(gender string) string {
return lookup(lang, gender+"_first_names", true)
}
// MaleFirstName generates male first name
func MaleFirstName() string {
return firstName("male")
}
// FemaleFirstName generates female first name
func FemaleFirstName() string {
return firstName("female")
}
// FirstName generates first name
func FirstName() string {
return firstName(randGender())
}
func lastName(gender string) string {
return lookup(lang, gender+"_last_names", true)
}
// MaleLastName generates male last name
func MaleLastName() string {
return lastName("male")
}
// FemaleLastName generates female last name
func FemaleLastName() string {
return lastName("female")
}
// LastName generates last name
func LastName() string {
return lastName(randGender())
}
func patronymic(gender string) string {
return lookup(lang, gender+"_patronymics", false)
}
// MalePatronymic generates male patronymic
func MalePatronymic() string {
return patronymic("male")
}
// FemalePatronymic generates female patronymic
func FemalePatronymic() string {
return patronymic("female")
}
// Patronymic generates patronymic
func Patronymic() string {
return patronymic(randGender())
}
func prefix(gender string) string {
return lookup(lang, gender+"_name_prefixes", false)
}
func suffix(gender string) string {
return lookup(lang, gender+"_name_suffixes", false)
}
func fullNameWithPrefix(gender string) string {
return join(prefix(gender), firstName(gender), lastName(gender))
}
// MaleFullNameWithPrefix generates prefixed male full name
// if prefixes for the given language are available
func MaleFullNameWithPrefix() string {
return fullNameWithPrefix("male")
}
// FemaleFullNameWithPrefix generates prefixed female full name
// if prefixes for the given language are available
func FemaleFullNameWithPrefix() string {
return fullNameWithPrefix("female")
}
// FullNameWithPrefix generates prefixed full name
// if prefixes for the given language are available
func FullNameWithPrefix() string {
return fullNameWithPrefix(randGender())
}
func fullNameWithSuffix(gender string) string {
return join(firstName(gender), lastName(gender), suffix(gender))
}
// MaleFullNameWithSuffix generates suffixed male full name
// if suffixes for the given language are available
func MaleFullNameWithSuffix() string {
return fullNameWithPrefix("male")
}
// FemaleFullNameWithSuffix generates suffixed female full name
// if suffixes for the given language are available
func FemaleFullNameWithSuffix() string {
return fullNameWithPrefix("female")
}
// FullNameWithSuffix generates suffixed full name
// if suffixes for the given language are available
func FullNameWithSuffix() string {
return fullNameWithPrefix(randGender())
}
func fullName(gender string) string {
switch r.Intn(10) {
case 0:
return fullNameWithPrefix(gender)
case 1:
return fullNameWithSuffix(gender)
default:
return join(firstName(gender), lastName(gender))
}
}
// MaleFullName generates male full name
// it can occasionally include prefix or suffix
func MaleFullName() string {
return fullName("male")
}
// FemaleFullName generates female full name
// it can occasionally include prefix or suffix
func FemaleFullName() string {
return fullName("female")
}
// FullName generates full name
// it can occasionally include prefix or suffix
func FullName() string {
return fullName(randGender())
}

24
vendor/github.com/icrowley/fake/personal.go generated vendored Normal file
View file

@ -0,0 +1,24 @@
package fake
import (
"strings"
)
// Gender generates random gender
func Gender() string {
return lookup(lang, "genders", true)
}
// GenderAbbrev returns first downcased letter of the random gender
func GenderAbbrev() string {
g := Gender()
if g != "" {
return strings.ToLower(string(g[0]))
}
return ""
}
// Language generates random human language
func Language() string {
return lookup(lang, "languages", true)
}

26
vendor/github.com/icrowley/fake/products.go generated vendored Normal file
View file

@ -0,0 +1,26 @@
package fake
// Brand generates brand name
func Brand() string {
return Company()
}
// ProductName generates product name
func ProductName() string {
productName := lookup(lang, "adjectives", true) + " " + lookup(lang, "nouns", true)
if r.Intn(2) == 1 {
productName = lookup(lang, "adjectives", true) + " " + productName
}
return productName
}
// Product generates product title as brand + product name
func Product() string {
return Brand() + " " + ProductName()
}
// Model generates model name that consists of letters and digits, optionally with a hyphen between them
func Model() string {
seps := []string{"", " ", "-"}
return CharactersN(r.Intn(3)+1) + seps[r.Intn(len(seps))] + Digits()
}

6
vendor/modules.txt vendored
View file

@ -1,12 +1,18 @@
# github.com/Masterminds/squirrel v1.5.0 # github.com/Masterminds/squirrel v1.5.0
## explicit; go 1.14 ## explicit; go 1.14
github.com/Masterminds/squirrel github.com/Masterminds/squirrel
# github.com/corpix/uarand v0.1.1
## explicit; go 1.12
github.com/corpix/uarand
# github.com/davecgh/go-spew v1.1.1 # github.com/davecgh/go-spew v1.1.1
## explicit ## explicit
github.com/davecgh/go-spew/spew github.com/davecgh/go-spew/spew
# github.com/google/uuid v1.3.0 # github.com/google/uuid v1.3.0
## explicit ## explicit
github.com/google/uuid github.com/google/uuid
# github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428
## explicit
github.com/icrowley/fake
# github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 # github.com/lann/builder v0.0.0-20180802200727-47ae307949d0
## explicit ## explicit
github.com/lann/builder github.com/lann/builder