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

Tool 1651 validate version #696

Merged
merged 27 commits into from
Feb 4, 2020
Merged

Tool 1651 validate version #696

merged 27 commits into from
Feb 4, 2020

Conversation

trapacska
Copy link
Collaborator

@trapacska trapacska commented Jan 23, 2020

@trapacska trapacska requested a review from a team January 23, 2020 14:06
@ghost ghost requested review from lszucs and removed request for a team January 23, 2020 14:06
Copy link
Contributor

@lszucs lszucs left a comment

Choose a reason for hiding this comment

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

I raised one minor issue, please consider it.

models/models.go Outdated
}

func (stepIDData StepIDData) validate(defaultStepLibSource string) (err error) {
if !stepIDData.isLatest() &&
Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend to inline the isLatest function.

From the perspective of the validate function, the rule is not to "validate version string if not latest", but to validate it "if not empty".

There is no added value in the context of the validate function if we know, that an empty version string resolves to the latest version.

lszucs
lszucs previously approved these changes Jan 24, 2020
Copy link
Contributor

@godrei godrei left a comment

Choose a reason for hiding this comment

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

pls check my notes

models/models.go Outdated
@@ -104,6 +104,15 @@ type StepIDData struct {
Version string
}

func (stepIDData StepIDData) validate(defaultStepLibSource string) (err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

pls apply the version validation for every step from any stepLib

@@ -288,6 +288,15 @@ func (workflow *WorkflowModel) Validate() ([]string, error) {
return warnings, err
}

stepIDData, err := CreateStepIDDataFromString(stepID, defaultStepLibSource)
Copy link
Contributor

Choose a reason for hiding this comment

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

pls solve to replace this function, as the new input (defaultStepLibSource), is only needed for using the CreateStepIDDataFromString, but we do not need the StepSource information otherwise

}

if err := stepIDData.validate(defaultStepLibSource); err != nil {
return warnings, fmt.Errorf("invalid version format (%s) specified for step ID: %s", stepIDData.Version, stepIDData.IDorURI)
Copy link
Contributor

Choose a reason for hiding this comment

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

it is a generic stepIDData validator, we can not be sure that only the version is wrong

Copy link
Contributor

@godrei godrei left a comment

Choose a reason for hiding this comment

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

pls check my notes

}
for _, tt := range []struct {
composite string
stepSrc string
Copy link
Contributor

Choose a reason for hiding this comment

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

stepSrc should be defaultSteplibSource

{
composite: "steplib-src::[email protected]", stepSrc: "",
wantStepSrc: "steplib-src", wantVersion: "0.0.1", wantStepID: "step-id", wantErr: false,
name: "default / long / verbose ID mode",
Copy link
Contributor

Choose a reason for hiding this comment

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

name should be the first as it describes the test case, so it lets you understand the following test case properties.

}{
{
composite: "steplib-src::[email protected]", stepSrc: "",
wantStepSrc: "steplib-src", wantVersion: "0.0.1", wantStepID: "step-id", wantErr: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

if you change the order of wantStepID and wantVersion it is easiert toreview (as it composite has a format: src::id@version)

Copy link
Contributor

Choose a reason for hiding this comment

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

suggested structure:

name: "default / long / verbose ID mode",
composite: "steplib-src::[email protected]", defaultStepLib: "",
wantStepSrc: "steplib-src", wantStepID: "step-id", wantVersion: "0.0.1",  
wantErr: false,

name: "no steplib & no version, only step-id",
},
{
composite: "", stepSrc: "def-step-src",
Copy link
Contributor

Choose a reason for hiding this comment

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

clear def-step-src and unify it, sometimes you use: def-step-src, sometimes: default-steplib-src, use a short stepSrc, like (StepLib)

name: "special empty test",
},
{
composite: "path::/some/path", stepSrc: "",
Copy link
Contributor

Choose a reason for hiding this comment

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

move the different sources into different test (something like TestCreateStepIDDataFromString_steplib, TestCreateStepIDDataFromString_path, TestCreateStepIDDataFromString_git, TestCreateStepIDDataFromString_legacy)

@trapacska trapacska requested a review from godrei January 28, 2020 14:23
Copy link
Contributor

@godrei godrei left a comment

Choose a reason for hiding this comment

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

please check my notes

@@ -288,6 +288,14 @@ func (workflow *WorkflowModel) Validate() ([]string, error) {
return warnings, err
}

stepNode := stepNode(stepID)

if ver, src := stepNode.version(), stepNode.source(); len(ver) > 0 && src == stepSourceUnknown {
Copy link
Contributor

Choose a reason for hiding this comment

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

src == stepSourceUnknown or any step library

stepSourceStepLibIndependent stepSource = "_"
)

func (sn stepNode) source() stepSource {
Copy link
Contributor

Choose a reason for hiding this comment

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

could you please comment 1-1 examples to the below functions to make the review easier

composite := sn.composite()

s := strings.Split(composite, "@")
if item := s[0]; item == "git" {
Copy link
Contributor

Choose a reason for hiding this comment

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

would be great to resolve code duplications

Copy link
Contributor

@godrei godrei left a comment

Choose a reason for hiding this comment

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

pls check my notes, we are close

@@ -458,7 +464,7 @@ func (config *BitriseDataModel) Validate() ([]string, error) {
warns, err := workflow.Validate()
warnings = append(warnings, warns...)
if err != nil {
return warnings, err
return warnings, fmt.Errorf("validation error in workflow: %s, error: %s", ID, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

avoid adding , error: suffix, the idiomatic error looks like: reason: deeper reason: even deeper reason

@@ -1580,3 +1535,296 @@ workflows:
}
}
}

func Test_stepNode(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.

i suggest to drop implementation details tests

@trapacska trapacska requested a review from godrei January 30, 2020 10:21
godrei
godrei previously approved these changes Jan 31, 2020
Copy link
Contributor

@godrei godrei left a comment

Choose a reason for hiding this comment

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

pls fix the ci builds, other than that: ok

@trapacska trapacska merged commit 9934e80 into master Feb 4, 2020
@trapacska trapacska deleted the TOOL-1651-validate-version branch February 4, 2020 10:03
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.

3 participants