Skip to content

feat: Add custom faker#52

Merged
yevgenypats merged 2 commits intomainfrom
feat/faker
Sep 5, 2022
Merged

feat: Add custom faker#52
yevgenypats merged 2 commits intomainfrom
feat/faker

Conversation

@yevgenypats
Copy link
Copy Markdown
Contributor

https://github.com/bxcodec/faker had a lot of issues
including inherent race conditions and features we didn't need.

This introduces custom faker which will make our life easier
in mock tests.

Summary


Use the following steps to ensure your PR is ready to be reviewed

  • Read the contribution guidelines 🧑‍🎓
  • Run go fmt to format your code 🖊
  • Lint your changes via golangci-lint run 🚨 (install golangci-lint here)
  • Update or add tests 🧪
  • Ensure the status checks below are successful ✅

@github-actions github-actions bot added the feat label Sep 4, 2022
@yevgenypats yevgenypats force-pushed the feat/faker branch 2 times, most recently from 4b560ea to 3677d27 Compare September 4, 2022 13:53
Copy link
Copy Markdown
Member

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

Looks good pending some code clean up

return fmt.Errorf("object is nil %s", reflectType.Elem().String())
}
f := &faker{
max_depth: 12,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
max_depth: 12,
max_depth: 2,

I think that should be sufficient for our use cases WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For me no, usually around 6,7 as I fake the whole response struct and it's quite nested


func TestSourcePluginSync(t *testing.T, plugin *SourcePlugin, spec specs.Source) {
t.Parallel()
// t.Parallel()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// t.Parallel()
// t.Parallel()

faker/faker.go Outdated
Comment on lines +181 to +210
// func FakeStruct(obj interface{}) error {
// e := reflect.ValueOf(obj)
// if e.Kind() == reflect.Pointer {
// e = e.Elem()
// }
// if e.Kind() != reflect.Struct {
// return fmt.Errorf("expected struct, got %s", e.Kind())
// }

// for i := 0; i < e.NumField(); i++ {
// field := e.Type().Field(i)
// if len(field.Name) == 0 {
// continue
// }
// if unicode.IsLower(rune(field.Name[0])) {
// continue
// }

// // field.

// columnType, err := valueToSchemaType(field.Type)
// if err != nil {
// fmt.Printf("skipping field %s, got err: %v\n", field.Name, err)
// continue
// }

// }

// return nil
// }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// func FakeStruct(obj interface{}) error {
// e := reflect.ValueOf(obj)
// if e.Kind() == reflect.Pointer {
// e = e.Elem()
// }
// if e.Kind() != reflect.Struct {
// return fmt.Errorf("expected struct, got %s", e.Kind())
// }
// for i := 0; i < e.NumField(); i++ {
// field := e.Type().Field(i)
// if len(field.Name) == 0 {
// continue
// }
// if unicode.IsLower(rune(field.Name[0])) {
// continue
// }
// // field.
// columnType, err := valueToSchemaType(field.Type)
// if err != nil {
// fmt.Printf("skipping field %s, got err: %v\n", field.Name, err)
// continue
// }
// }
// return nil
// }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed

https://github.com/bxcodec/faker had a lot of issues
including inherent race conditions and features we didn't need.

This introduces custom faker which will make our life easier
in mock tests.
@yevgenypats
Copy link
Copy Markdown
Contributor Author

Looks good pending some code clean up

Thanks! I'll give it some more testing and I think it will be good to merge

@yevgenypats yevgenypats merged commit 34bef4b into main Sep 5, 2022
@yevgenypats yevgenypats deleted the feat/faker branch September 5, 2022 22:18
@cq-bot cq-bot mentioned this pull request Sep 5, 2022
kodiakhq bot pushed a commit that referenced this pull request Sep 6, 2022
🤖 I have created a release *beep* *boop*
---


## [0.1.1](v0.1.0...v0.1.1) (2022-09-06)


### Features

* Add custom faker ([#52](#52)) ([34bef4b](34bef4b))
* Add sentry for serve.Serve function ([#54](#54)) ([c1b508f](c1b508f))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants