Repository: bxcodec/faker
Pull request #104 (2020-06-07 09:38:27)

added gender tag

codecov[bot]: # [Codecov](https://codecov.io/gh/bxcodec/faker/pull/104?src=pr&el=h1) Report
> Merging [#104](https://codecov.io/gh/bxcodec/faker/pull/104?src=pr&el=desc) into [master](https://codecov.io/gh/bxcodec/faker/commit/9169c33ae9926e5b8f8732909790ee20b10b736a&el=desc) will **decrease** coverage by `0.59%`.
> The diff coverage is `44.44%`.

[![Impacted file tree graph](https://codecov.io/gh/bxcodec/faker/pull/104/graphs/tree.svg?width=650&height=150&src=pr&token=cLPGB7MHVc)](https://codecov.io/gh/bxcodec/faker/pull/104?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #104      +/-   ##
==========================================
- Coverage   95.04%   94.45%   -0.60%     
==========================================
  Files          10       10              
  Lines         989     1010      +21     
==========================================
+ Hits          940      954      +14     
- Misses         27       33       +6     
- Partials       22       23       +1     
```


| [Impacted Files](https://codecov.io/gh/bxcodec/faker/pull/104?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [faker.go](https://codecov.io/gh/bxcodec/faker/pull/104/diff?src=pr&el=tree#diff-ZmFrZXIuZ28=) | `90.67% <ø> (-0.20%)` | :arrow_down: |
| [person.go](https://codecov.io/gh/bxcodec/faker/pull/104/diff?src=pr&el=tree#diff-cGVyc29uLmdv) | `93.90% <44.44%> (-6.10%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/bxcodec/faker/pull/104?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/bxcodec/faker/pull/104?src=pr&el=footer). Last update [9169c33...879b8bf](https://codecov.io/gh/bxcodec/faker/pull/104?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/faker.go b/faker.go
index 228dda7..2f27ea5 100644
--- a/faker.go
+++ b/faker.go
@@ -88,6 +88,7 @@ const (
 	FirstNameFemaleTag    = "first_name_female"
 	LastNameTag           = "last_name"
 	NAME                  = "name"
+	GENDER                = "gender"
 	UnixTimeTag           = "unix_time"
 	DATE                  = "date"
 	TIME                  = "time"
@@ -137,6 +138,7 @@ var defaultTag = map[string]string{
 	FirstNameFemaleTag:    FirstNameFemaleTag,
 	LastNameTag:           LastNameTag,
 	NAME:                  NAME,
+	GENDER:                GENDER,
 	UnixTimeTag:           UnixTimeTag,
 	DATE:                  DATE,
 	TIME:                  TimeFormat,
@@ -185,6 +187,7 @@ var mapperTag = map[string]TaggedFunction{
 	FirstNameFemaleTag:    GetPerson().FirstNameFemale,
 	LastNameTag:           GetPerson().LastName,
 	NAME:                  GetPerson().Name,
+	GENDER:                GetPerson().Gender,
 	UnixTimeTag:           GetDateTimer().UnixTime,
 	DATE:                  GetDateTimer().Date,
 	TIME:                  GetDateTimer().Time,
diff --git a/person.go b/person.go
index 5b4b650..26cd0a9 100644
--- a/person.go
+++ b/person.go
@@ -15,6 +15,7 @@ type Dowser interface {
 	FirstNameFemale(v reflect.Value) (interface{}, error)
 	LastName(v reflect.Value) (interface{}, error)
 	Name(v reflect.Value) (interface{}, error)
+	Gender(v reflect.Value) (interface{}, error)
 }
 
 var person Dowser
@@ -108,6 +109,8 @@ var lastNames = []string{
 }
 var randNameFlag = rand.Intn(100)
 
+var genders = []string{"Male", "Female", "Prefer to skip"}
+
 // GetPerson returns a new Dowser interface of Person struct
 func GetPerson() Dowser {
 	mu.Lock()
@@ -249,3 +252,20 @@ func Name() string {
 		return p.name()
 	}).(string)
 }
+
+// Gender returns a random gender
+func (p Person) Gender(v reflect.Value) (interface{}, error) {
+	return p.gender(), nil
+}
+
+func (p Person) gender() string {
+	return randomElementFromSliceString(genders)
+}
+
+// Gender get fake gender
+func Gender() string {
+	return singleFakeData(GENDER, func() interface{} {
+		p := Person{}
+		return p.gender()
+	}).(string)
+}


Test patch:
diff --git a/person_test.go b/person_test.go
index 8b425a5..52dea9c 100644
--- a/person_test.go
+++ b/person_test.go
@@ -148,3 +148,13 @@ func TestFakeNameFemale(t *testing.T) {
 		t.Error("Expected from function name string get empty string")
 	}
 }
+
+func TestFakeGender(t *testing.T) {
+	gender, err := GetPerson().Gender(reflect.Value{})
+	if err != nil {
+		t.Error("Expected  not error, got err", err)
+	}
+	if !slice.Contains(genders, gender.(string)) {
+		t.Error("Expected value from variable genders in function Gender")
+	}
+}