Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the duplicate name issue while creating a template #270

Merged
merged 3 commits into from
Sep 1, 2020

Conversation

parauliya
Copy link
Contributor

@parauliya parauliya commented Aug 27, 2020

Name of the template which is used to provide with -n flag while creating a template should be unique.
But there was an issue because of which it was accepting duplicate name as well.
This PR fixed the above issue.

Signed-off-by: parauliya [email protected]

Description

Name of the template which is used to provide with -n flag while creating a template should be unique.
But there was an issue because of which it was accepting duplicate name as well.
This PR fixed the above issue.

Why is this needed

Same as Description.

How Has This Been Tested?

I tried to create multiple template with same name but now they are not being created because of the same name.

How are existing users impacted? What migration steps/scripts do we need?

User need to provide the unique name for each template it is creating in the database.

Checklist:

I have:

  • updated the documentation and/or roadmap (if required)
  • added unit or e2e tests
  • provided instructions on how to upgrade

Name of the template which is used to provide with -n flag while creating a template should be unique.
But there was an issue because of which it was accepting duplicate name as well.
This PR fixed the above issue.

Signed-off-by: parauliya <[email protected]>
@parauliya parauliya requested a review from gauravgahlot August 27, 2020 08:27
@codecov
Copy link

codecov bot commented Aug 27, 2020

Codecov Report

Merging #270 into master will increase coverage by 1.74%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #270      +/-   ##
==========================================
+ Coverage   15.34%   17.08%   +1.74%     
==========================================
  Files           9        9              
  Lines        1264     1264              
==========================================
+ Hits          194      216      +22     
+ Misses       1059     1036      -23     
- Partials       11       12       +1     
Impacted Files Coverage Δ
grpc-server/template.go 19.64% <100.00%> (+19.64%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e14ed36...d06e1b6. Read the comment docs.

@parauliya parauliya self-assigned this Aug 27, 2020
@parauliya parauliya added the kind/bug Categorizes issue or PR as related to a bug. label Aug 27, 2020
@parauliya parauliya added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Aug 27, 2020
@gianarb
Copy link
Contributor

gianarb commented Aug 27, 2020

Pretty good! Can you add a Table Test that accepts templates as input and validate the answers, please?

Let's make this coverage green bit by bit!

@gianarb gianarb added the needs-tests Needs supporting unit tests label Aug 27, 2020
@gauravgahlot gauravgahlot requested review from gianarb and removed request for gauravgahlot August 27, 2020 11:29
@parauliya parauliya force-pushed the template_unique_name branch from 6eb7d25 to dd74eb6 Compare August 28, 2020 09:15
timeout: 60`
)

func TestDuplicateTemplateName(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you call it TestCreateTemplate? and the table test has to work like this imho:
Table Test is not only for one specific use case, but it has to be flexible enough to allow all the one you can think about for the function you are testing, in our case CreateTemplate

// you don't need a testCases struct just use a []testCase
struct testCase type {
    db mock.DB
    name string
    input []string // or templates
    expect func() (*template.CreateResponse, error)
}

In order to figure out if the TableTest is well written can you add three other testcases please?

  1. Well formatted and successful template creation (only one)
  2. A random validation error if we have any
  3. Create 2 templates with a different name, both should work

Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, I will try to add couple of more test cases as you suggested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gianarb As mentioned by you I have modified the test struct ( not exactly as you suggested ) so that in future more tests can be added. And I have also added couple of more test cases. But I was not able to test for validation of template because we don't check the validation of a template in CreateTemplate function. Template is being validated while creating a workflow here https://github.com/tinkerbell/tink/blob/master/db/workflow.go#L98.

@parauliya parauliya force-pushed the template_unique_name branch from 3782f9e to c714e35 Compare September 1, 2020 08:06
@parauliya parauliya force-pushed the template_unique_name branch from 0d61ae6 to d06e1b6 Compare September 1, 2020 09:14
@parauliya parauliya requested a review from gianarb September 1, 2020 09:27
@gianarb gianarb added ready-to-merge Signal to Mergify to merge the PR. and removed needs-tests Needs supporting unit tests labels Sep 1, 2020
Copy link
Contributor

@gianarb gianarb left a comment

Choose a reason for hiding this comment

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

Great! Thanks +1.74%

@mergify mergify bot merged commit ac175e0 into tinkerbell:master Sep 1, 2020
@parauliya parauliya deleted the template_unique_name branch September 1, 2020 11:56
@gianarb gianarb mentioned this pull request Jan 5, 2021
5 tasks
@mmlb mmlb removed the ready-to-merge Signal to Mergify to merge the PR. label Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants