-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new init prompt function and helper functions (#5141)
* new prompt function and helper functions * use survey.Confirm instead of survey.Select * use yamltags.GetYamlTags
- Loading branch information
1 parent
4f816d5
commit 9422d28
Showing
4 changed files
with
256 additions
and
0 deletions.
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,47 @@ | ||
/* | ||
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" | ||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/yamltags" | ||
) | ||
|
||
// 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{} | ||
} | ||
|
||
return yamltags.GetYamlTags(deploy.DeployType) | ||
} |
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) | ||
}) | ||
} | ||
} |