Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

feat(faker): unique data generation #77

Merged
merged 7 commits into from
Nov 15, 2019
Merged

feat(faker): unique data generation #77

merged 7 commits into from
Nov 15, 2019

Conversation

System-Glitch
Copy link
Contributor

@System-Glitch System-Glitch commented Oct 10, 2019

Refer to issue #76

  • Added a unique tag to generate unique data.
    • Call ResetUnique() after generating a dataset to forget all already generated values
  • Added tests for the new feature
  • Added unique support for Lorem generator as a proposal for the single fake data functions. My implementation is redundant. Any feedback would be appreciated before implementing it to the other single fake data functions.
    • Call SetGenerateUniqueValues(true) to enable unique data generation on single fake data functions
    • Call SetGenerateUniqueValues(false) to disable it
    • Call ResetUnique() to forget all already generated values

This change shouldn't break backwards compatibility.

TODO:

  • Update documentation
  • Implement unique handling in all single fake data functions

@bxcodec
Copy link
Owner

bxcodec commented Oct 26, 2019

Any updates on this PR @System-Glitch

@System-Glitch
Copy link
Contributor Author

System-Glitch commented Oct 26, 2019

@bxcodec Well I was waiting for feedback on the single fake data functions before continuing. Does this look ok for you? I feel like it's far from optimal.

@System-Glitch
Copy link
Contributor Author

System-Glitch commented Oct 27, 2019

if generateUniqueValues {
	v, err := generateUnique(PARAGRAPH, func() interface{} {
		return i.paragraph()
	})
	if err != nil {
		panic(err)
	}
	return v.(string)
}

This part is redundant. It has to be there for every single fake data function. Maybe you have an idea to make it better?

I though about another function to factor this.

func singleFakeData(dataType string, fn func() interface{}) interface{} {
	if generateUniqueValues {
		v, err := generateUnique(dataType, fn)
		if err != nil {
			panic(err)
		}
		return v
	}
	return fn()
}

That would shorten a single fake data function to this.

func Word() string {
	i := Lorem{}
	return singleFakeData(WORD, func() interface{} {
		return i.word()
	}).(string)
}

@System-Glitch
Copy link
Contributor Author

System-Glitch commented Oct 27, 2019

@bxcodec PR is ready to be merged.

@bxcodec bxcodec changed the title Unique data generation feat(faker): unique data generation Nov 15, 2019
Copy link
Owner

@bxcodec bxcodec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bxcodec
Copy link
Owner

bxcodec commented Nov 15, 2019

Thanks for the PR @System-Glitch 👍

@bxcodec bxcodec merged commit d1bb356 into bxcodec:master Nov 15, 2019
@bxcodec bxcodec mentioned this pull request Nov 15, 2019
@System-Glitch System-Glitch deleted the feature/unique branch November 15, 2019 07:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants