-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
new init prompt function and helper functions #5141
Merged
MarlonGamez
merged 4 commits into
GoogleContainerTools:master
from
MarlonGamez:confirm-init-options
Dec 14, 2020
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,76 @@ | ||
/* | ||
Copyright 2020 The Skaffold Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package prompt | ||
|
||
import ( | ||
"errors" | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/AlecAivazis/survey/v2" | ||
|
||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" | ||
"github.com/GoogleContainerTools/skaffold/testutil" | ||
) | ||
|
||
func TestConfirmInitOptions(t *testing.T) { | ||
tests := []struct { | ||
description string | ||
config *latest.SkaffoldConfig | ||
promptResponse bool | ||
expectedDone bool | ||
shouldErr bool | ||
}{ | ||
{ | ||
description: "yes response", | ||
config: &latest.SkaffoldConfig{}, | ||
promptResponse: true, | ||
expectedDone: false, | ||
shouldErr: false, | ||
}, | ||
{ | ||
description: "no response", | ||
config: &latest.SkaffoldConfig{}, | ||
promptResponse: false, | ||
expectedDone: true, | ||
shouldErr: false, | ||
}, | ||
{ | ||
description: "error", | ||
config: &latest.SkaffoldConfig{}, | ||
promptResponse: false, | ||
expectedDone: true, | ||
shouldErr: true, | ||
}, | ||
} | ||
for _, test := range tests { | ||
testutil.Run(t, test.description, func(t *testutil.T) { | ||
t.Override(&askOne, func(_ survey.Prompt, response interface{}, _ ...survey.AskOpt) error { | ||
r := response.(*bool) | ||
*r = test.promptResponse | ||
|
||
if test.shouldErr { | ||
return errors.New("error") | ||
} | ||
return nil | ||
}) | ||
|
||
done, err := ConfirmInitOptions(ioutil.Discard, test.config) | ||
t.CheckErrorAndDeepEqual(test.shouldErr, err, test.expectedDone, done) | ||
}) | ||
} | ||
} |
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,60 @@ | ||
/* | ||
Copyright 2020 The Skaffold Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package util | ||
|
||
import ( | ||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/misc" | ||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" | ||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" | ||
) | ||
|
||
// ListBuilders returns a list of builder names being used in the given build config. | ||
func ListBuilders(build *latest.BuildConfig) []string { | ||
if build == nil { | ||
return []string{} | ||
} | ||
|
||
results := util.NewStringSet() | ||
for _, artifact := range build.Artifacts { | ||
results.Insert(misc.ArtifactType(artifact)) | ||
} | ||
|
||
return results.ToList() | ||
} | ||
|
||
// ListDeployers returns a list of deployer names being used in the given deploy config. | ||
func ListDeployers(deploy *latest.DeployConfig) []string { | ||
if deploy == nil { | ||
return []string{} | ||
} | ||
|
||
results := util.NewStringSet() | ||
if deploy.HelmDeploy != nil { | ||
results.Insert("helm") | ||
} | ||
if deploy.KptDeploy != nil { | ||
results.Insert("kpt") | ||
} | ||
if deploy.KubectlDeploy != nil { | ||
results.Insert("kubectl") | ||
} | ||
if deploy.KustomizeDeploy != nil { | ||
results.Insert("kustomize") | ||
} | ||
|
||
return results.ToList() | ||
} |
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,103 @@ | ||
/* | ||
Copyright 2020 The Skaffold Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package util | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" | ||
"github.com/GoogleContainerTools/skaffold/testutil" | ||
) | ||
|
||
func TestListBuilders(t *testing.T) { | ||
tests := []struct { | ||
description string | ||
build *latest.BuildConfig | ||
expected []string | ||
}{ | ||
{ | ||
description: "nil config", | ||
build: nil, | ||
expected: []string{}, | ||
}, | ||
{ | ||
description: "multiple same builder config", | ||
build: &latest.BuildConfig{ | ||
Artifacts: []*latest.Artifact{ | ||
{ImageName: "img1", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}, | ||
{ImageName: "img2", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}, | ||
}, | ||
}, | ||
expected: []string{"docker"}, | ||
}, | ||
{ | ||
description: "different builders config", | ||
build: &latest.BuildConfig{ | ||
Artifacts: []*latest.Artifact{ | ||
{ImageName: "img1", ArtifactType: latest.ArtifactType{DockerArtifact: &latest.DockerArtifact{}}}, | ||
{ImageName: "img2", ArtifactType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{}}}, | ||
}, | ||
}, | ||
expected: []string{"docker", "jib"}, | ||
}, | ||
} | ||
for _, test := range tests { | ||
testutil.Run(t, test.description, func(t *testutil.T) { | ||
got := ListBuilders(test.build) | ||
t.CheckDeepEqual(test.expected, got) | ||
}) | ||
} | ||
} | ||
|
||
func TestListDeployers(t *testing.T) { | ||
tests := []struct { | ||
description string | ||
deploy *latest.DeployConfig | ||
expected []string | ||
}{ | ||
{ | ||
description: "nil config", | ||
deploy: nil, | ||
expected: []string{}, | ||
}, | ||
{ | ||
description: "single deployer config", | ||
deploy: &latest.DeployConfig{ | ||
DeployType: latest.DeployType{ | ||
KubectlDeploy: &latest.KubectlDeploy{}, | ||
}, | ||
}, | ||
expected: []string{"kubectl"}, | ||
}, | ||
{ | ||
description: "multiple deployers config", | ||
deploy: &latest.DeployConfig{ | ||
DeployType: latest.DeployType{ | ||
HelmDeploy: &latest.HelmDeploy{}, | ||
KubectlDeploy: &latest.KubectlDeploy{}, | ||
}, | ||
}, | ||
expected: []string{"helm", "kubectl"}, | ||
}, | ||
} | ||
for _, test := range tests { | ||
testutil.Run(t, test.description, func(t *testutil.T) { | ||
got := ListDeployers(test.deploy) | ||
t.CheckDeepEqual(test.expected, got) | ||
}) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good just thought this function might be useful since I used it for the same use case so I think it could help here too by using it as the underlying function. It just uses the yaml that deploy *latest.DeployConfig unmarshals to, to get the list of deployers.
skaffold/pkg/skaffold/instrumentation/meter.go
Line 87 in d781368
skaffold/pkg/skaffold/yamltags/tags.go
Lines 80 to 92 in 1f200b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also now realizing there's a tab right before
kubectl
in the comment that shouldn't be there 😅There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for sharing this, I think your function is probably what I should use here because it should be fine in the case of a new deployer being added to skaffold