mirror of https://github.com/helm/helm
* cleanup and results are not implemented yet Signed-off-by: Michelle Noorali <michellemolu@gmail.com>pull/5418/head
parent
b64066b445
commit
ce0a2a3c98
@ -0,0 +1,59 @@
|
||||
/*
|
||||
Copyright The Helm 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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/helm/cmd/helm/require"
|
||||
"k8s.io/helm/pkg/helm"
|
||||
)
|
||||
|
||||
const releaseTestCleanupDesc = `
|
||||
This command deletes the all test pods for the given release. The argument
|
||||
this command takes is the name of a deployed release.
|
||||
|
||||
Example usage:
|
||||
$ helm test cleanup [RELEASE]
|
||||
`
|
||||
|
||||
type releaseTestCleanupOptions struct {
|
||||
name string
|
||||
client helm.Interface
|
||||
}
|
||||
|
||||
func newReleaseTestCleanupCmd(c helm.Interface, out io.Writer) *cobra.Command {
|
||||
o := &releaseTestCleanupOptions{client: c}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "cleanup [RELEASE]",
|
||||
Short: "delete test pods for a release",
|
||||
Long: releaseTestCleanupDesc,
|
||||
Args: require.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
o.name = args[0]
|
||||
o.client = ensureHelmClient(o.client, false)
|
||||
fmt.Fprintf(out, "NOT IMPLEMENTED YET\n")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
Copyright The Helm 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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/helm/cmd/helm/require"
|
||||
"k8s.io/helm/pkg/helm"
|
||||
)
|
||||
|
||||
const releaseTestResultsDesc = `
|
||||
This command prints the results of the last test run execution for a
|
||||
given release.
|
||||
|
||||
Example usage:
|
||||
$ helm test results: [RELEASE]
|
||||
`
|
||||
|
||||
type releaseTestResultsOptions struct {
|
||||
name string
|
||||
client helm.Interface
|
||||
}
|
||||
|
||||
func newReleaseTestResultsCmd(c helm.Interface, out io.Writer) *cobra.Command {
|
||||
o := &releaseTestResultsOptions{client: c}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "results [RELEASE]",
|
||||
Short: "show latest test results for a release",
|
||||
Long: releaseTestResultsDesc,
|
||||
Args: require.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
o.name = args[0]
|
||||
o.client = ensureHelmClient(o.client, false)
|
||||
fmt.Fprintf(out, "NOT IMPLEMENTED YET")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
/*
|
||||
Copyright The Helm 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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/helm/cmd/helm/require"
|
||||
"k8s.io/helm/pkg/hapi/release"
|
||||
"k8s.io/helm/pkg/helm"
|
||||
)
|
||||
|
||||
const releaseTestRunDesc = `
|
||||
This command executes the tests for the given release. The argument this
|
||||
command takes is the name of a deployed release. The tests to be run are
|
||||
defined in the chart that was installed.
|
||||
|
||||
Example usage:
|
||||
$ helm test run [RELEASE]
|
||||
`
|
||||
|
||||
type releaseTestRunOptions struct {
|
||||
name string
|
||||
client helm.Interface
|
||||
timeout int64
|
||||
cleanup bool
|
||||
}
|
||||
|
||||
func newReleaseTestRunCmd(c helm.Interface, out io.Writer) *cobra.Command {
|
||||
o := &releaseTestRunOptions{client: c}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "run [RELEASE]",
|
||||
Short: "execute tests for a release",
|
||||
Long: releaseTestRunDesc,
|
||||
Args: require.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
o.name = args[0]
|
||||
o.client = ensureHelmClient(o.client, false)
|
||||
return o.run(out)
|
||||
},
|
||||
}
|
||||
|
||||
f := cmd.Flags()
|
||||
f.Int64Var(&o.timeout, "timeout", 300, "time in seconds to wait for any individual Kubernetes operation (like Jobs for hooks)")
|
||||
f.BoolVar(&o.cleanup, "cleanup", false, "delete test pods upon completion")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (o *releaseTestRunOptions) run(out io.Writer) (err error) {
|
||||
c, errc := o.client.RunReleaseTest(
|
||||
o.name,
|
||||
helm.ReleaseTestTimeout(o.timeout),
|
||||
helm.ReleaseTestCleanup(o.cleanup),
|
||||
)
|
||||
testErr := &testErr{}
|
||||
|
||||
for {
|
||||
select {
|
||||
case err := <-errc:
|
||||
if err == nil && testErr.failed > 0 {
|
||||
return testErr.Error()
|
||||
}
|
||||
return err
|
||||
case res, ok := <-c:
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
|
||||
if res.Status == release.TestRunFailure {
|
||||
testErr.failed++
|
||||
}
|
||||
fmt.Fprintf(out, res.Msg+"\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type testErr struct {
|
||||
failed int
|
||||
}
|
||||
|
||||
func (err *testErr) Error() error {
|
||||
return errors.Errorf("%v test(s) failed", err.failed)
|
||||
}
|
Loading…
Reference in new issue