-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(blood): Added faker for blood types (#40)
* feat(blood): Added faker for blood types Added faker that will generate blood type, rh factor and group Signed-off-by: Rubem Mota <rubemmota89@gmail.com> * feat(blood): Added tag into main tag Signed-off-by: Rubem <rubemmota89@gmail.com> * fix(blood): Changed tag location to be used by default without options Signed-off-by: Rubem <rubemmota89@gmail.com> --------- Signed-off-by: Rubem Mota <rubemmota89@gmail.com> Signed-off-by: Rubem <rubemmota89@gmail.com>
- Loading branch information
Showing
4 changed files
with
132 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package faker | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
|
||
"github.com/go-faker/faker/v4/pkg/options" | ||
) | ||
|
||
var bloodTypes = []string{"O", "A", "B", "AB"} | ||
var bloodRhFactors = []string{"+", "-"} | ||
|
||
func GetBlood(opts ...options.OptionFunc) Blooder { | ||
opt := options.BuildOptions(opts) | ||
db := &Blood{ | ||
fakerOption: *opt, | ||
} | ||
return db | ||
} | ||
|
||
type Blooder interface { | ||
BloodType(v reflect.Value) (interface{}, error) | ||
BloodRHFactor(v reflect.Value) (interface{}, error) | ||
BloodGroup(v reflect.Value) (interface{}, error) | ||
} | ||
|
||
// Internet struct | ||
type Blood struct { | ||
fakerOption options.Options | ||
} | ||
|
||
func (b Blood) bloodType() string { | ||
return randomElementFromSliceString(bloodTypes) | ||
} | ||
|
||
func (b Blood) BloodType(v reflect.Value) (interface{}, error) { | ||
return b.bloodType(), nil | ||
} | ||
|
||
func (b Blood) bloodRhFactor() string { | ||
return randomElementFromSliceString(bloodRhFactors) | ||
} | ||
|
||
func (b Blood) BloodRHFactor(v reflect.Value) (interface{}, error) { | ||
return b.bloodRhFactor(), nil | ||
} | ||
|
||
func (b Blood) bloodGroup() string { | ||
return fmt.Sprintf("%s%s", b.bloodType(), b.bloodRhFactor()) | ||
} | ||
|
||
func (b Blood) BloodGroup(v reflect.Value) (interface{}, error) { | ||
return b.bloodGroup(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package faker | ||
|
||
import ( | ||
"reflect" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/go-faker/faker/v4/pkg/slice" | ||
) | ||
|
||
func TestBloodType(t *testing.T) { | ||
bloodType, err := GetBlood().BloodType(reflect.Value{}) | ||
if err != nil { | ||
t.Error("Expected not error, got err", err) | ||
} | ||
if !slice.Contains(bloodTypes, bloodType.(string)) { | ||
t.Error("Expected value from variable bloodType in function BloodType") | ||
} | ||
} | ||
|
||
func TestBloodRhFactor(t *testing.T) { | ||
bloodRhFactor, err := GetBlood().BloodRHFactor(reflect.Value{}) | ||
if err != nil { | ||
t.Error("Expected not error, got err", err) | ||
} | ||
if !slice.Contains(bloodRhFactors, bloodRhFactor.(string)) { | ||
t.Error("Expected value from variable bloodRhFactor in function BloodType") | ||
} | ||
} | ||
|
||
func TestBloodGroup(t *testing.T) { | ||
bloodTypes = []string{"O"} | ||
bloodRhFactors = []string{"+"} | ||
bloodGroup, err := GetBlood().BloodGroup(reflect.Value{}) | ||
if err != nil { | ||
t.Error("Expected not error, got err", err) | ||
} | ||
if !strings.Contains(bloodGroup.(string), "O+") { | ||
t.Error("Expected get url") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters