fix(*): fix various style issues from make test-style

Closes #847.
pull/905/head
Matt Butcher 8 years ago
parent 2eada26477
commit 2c07a32a6b

@ -71,7 +71,7 @@ func runPackage(cmd *cobra.Command, args []string) error {
} }
if filepath.Base(path) != ch.Metadata.Name { if filepath.Base(path) != ch.Metadata.Name {
return fmt.Errorf("directory name (%s) and Chart.yaml name (%s) must match.", filepath.Base(path), ch.Metadata.Name) return fmt.Errorf("directory name (%s) and Chart.yaml name (%s) must match", filepath.Base(path), ch.Metadata.Name)
} }
// Save to the current working directory. // Save to the current working directory.

@ -24,29 +24,30 @@ import (
) )
const ( const (
// $HELM_HOST envvar // HelmHostEnvVar is the $HELM_HOST envvar
HelmHostEnvVar = "HELM_HOST" HelmHostEnvVar = "HELM_HOST"
// $HELM_HOME envvar // HelmHomeEnvVar is the $HELM_HOME envvar
HelmHomeEnvVar = "HELM_HOME" HelmHomeEnvVar = "HELM_HOME"
// Default tiller server host address. // DefaultHelmHost is the default tiller server host address.
DefaultHelmHost = ":44134" DefaultHelmHost = ":44134"
// Default $HELM_HOME envvar value // DefaultHelmHome is the default $HELM_HOME envvar value
DefaultHelmHome = "$HOME/.helm" DefaultHelmHome = "$HOME/.helm"
) )
// Helm client manages client side of the helm-tiller protocol // Client manages client side of the helm-tiller protocol
type Client struct { type Client struct {
opts options opts options
} }
// NewClient creates a new client.
func NewClient(opts ...Option) *Client { func NewClient(opts ...Option) *Client {
return new(Client).Init().Option(opts...) return new(Client).Init().Option(opts...)
} }
// Configure the helm client with the provided options // Option configures the helm client with the provided options
func (h *Client) Option(opts ...Option) *Client { func (h *Client) Option(opts ...Option) *Client {
for _, opt := range opts { for _, opt := range opts {
opt(&h.opts) opt(&h.opts)
@ -54,7 +55,7 @@ func (h *Client) Option(opts ...Option) *Client {
return h return h
} }
// Initializes the helm client with default options // Init initializes the helm client with default options
func (h *Client) Init() *Client { func (h *Client) Init() *Client {
return h.Option(HelmHost(DefaultHelmHost)). return h.Option(HelmHost(DefaultHelmHost)).
Option(HelmHome(os.ExpandEnv(DefaultHelmHome))) Option(HelmHome(os.ExpandEnv(DefaultHelmHome)))
@ -87,7 +88,7 @@ func (h *Client) InstallRelease(chStr string, opts ...InstallOption) (*rls.Insta
return h.opts.rpcInstallRelease(chart, rls.NewReleaseServiceClient(c), opts...) return h.opts.rpcInstallRelease(chart, rls.NewReleaseServiceClient(c), opts...)
} }
// UninstallRelease uninstalls a named release and returns the response. // DeleteRelease uninstalls a named release and returns the response.
// //
// Note: there aren't currently any supported DeleteOptions, but they are // Note: there aren't currently any supported DeleteOptions, but they are
// kept in the API signature as a placeholder for future additions. // kept in the API signature as a placeholder for future additions.

@ -23,10 +23,13 @@ import (
// These APIs are a temporary abstraction layer that captures the interaction between the current cmd/helm and old // These APIs are a temporary abstraction layer that captures the interaction between the current cmd/helm and old
// pkg/helm implementations. Post refactor the cmd/helm package will use the APIs exposed on helm.Client directly. // pkg/helm implementations. Post refactor the cmd/helm package will use the APIs exposed on helm.Client directly.
// Config is the base configuration
var Config struct { var Config struct {
ServAddr string ServAddr string
} }
// ListReleases lists releases. DEPRECATED.
//
// Soon to be deprecated helm ListReleases API. // Soon to be deprecated helm ListReleases API.
func ListReleases(limit int, offset string, sort rls.ListSort_SortBy, order rls.ListSort_SortOrder, filter string) (*rls.ListReleasesResponse, error) { func ListReleases(limit int, offset string, sort rls.ListSort_SortBy, order rls.ListSort_SortOrder, filter string) (*rls.ListReleasesResponse, error) {
opts := []ReleaseListOption{ opts := []ReleaseListOption{
@ -39,21 +42,26 @@ func ListReleases(limit int, offset string, sort rls.ListSort_SortBy, order rls.
return NewClient(HelmHost(Config.ServAddr)).ListReleases(opts...) return NewClient(HelmHost(Config.ServAddr)).ListReleases(opts...)
} }
// GetReleaseStatus gets a release status. DEPRECATED
//
// Soon to be deprecated helm GetReleaseStatus API. // Soon to be deprecated helm GetReleaseStatus API.
func GetReleaseStatus(rlsName string) (*rls.GetReleaseStatusResponse, error) { func GetReleaseStatus(rlsName string) (*rls.GetReleaseStatusResponse, error) {
return NewClient(HelmHost(Config.ServAddr)).ReleaseStatus(rlsName) return NewClient(HelmHost(Config.ServAddr)).ReleaseStatus(rlsName)
} }
// GetReleaseContent gets the content of a release.
// Soon to be deprecated helm GetReleaseContent API. // Soon to be deprecated helm GetReleaseContent API.
func GetReleaseContent(rlsName string) (*rls.GetReleaseContentResponse, error) { func GetReleaseContent(rlsName string) (*rls.GetReleaseContentResponse, error) {
return NewClient(HelmHost(Config.ServAddr)).ReleaseContent(rlsName) return NewClient(HelmHost(Config.ServAddr)).ReleaseContent(rlsName)
} }
// UpdateRelease updates a release.
// Soon to be deprecated helm UpdateRelease API. // Soon to be deprecated helm UpdateRelease API.
func UpdateRelease(rlsName string) (*rls.UpdateReleaseResponse, error) { func UpdateRelease(rlsName string) (*rls.UpdateReleaseResponse, error) {
return NewClient(HelmHost(Config.ServAddr)).UpdateRelease(rlsName) return NewClient(HelmHost(Config.ServAddr)).UpdateRelease(rlsName)
} }
// InstallRelease runs an install for a release.
// Soon to be deprecated helm InstallRelease API. // Soon to be deprecated helm InstallRelease API.
func InstallRelease(vals []byte, rlsName, chStr string, dryRun bool) (*rls.InstallReleaseResponse, error) { func InstallRelease(vals []byte, rlsName, chStr string, dryRun bool) (*rls.InstallReleaseResponse, error) {
client := NewClient(HelmHost(Config.ServAddr)) client := NewClient(HelmHost(Config.ServAddr))
@ -63,6 +71,7 @@ func InstallRelease(vals []byte, rlsName, chStr string, dryRun bool) (*rls.Insta
return client.InstallRelease(chStr, ValueOverrides(vals), ReleaseName(rlsName)) return client.InstallRelease(chStr, ValueOverrides(vals), ReleaseName(rlsName))
} }
// UninstallRelease destroys an existing release.
// Soon to be deprecated helm UninstallRelease API. // Soon to be deprecated helm UninstallRelease API.
func UninstallRelease(rlsName string, dryRun bool) (*rls.UninstallReleaseResponse, error) { func UninstallRelease(rlsName string, dryRun bool) (*rls.UninstallReleaseResponse, error) {
client := NewClient(HelmHost(Config.ServAddr)) client := NewClient(HelmHost(Config.ServAddr))

@ -28,12 +28,16 @@ import (
"k8s.io/helm/pkg/proto/hapi/chart" "k8s.io/helm/pkg/proto/hapi/chart"
) )
const badChartDir = "testdata/badchartfile" const (
const goodChartDir = "testdata/goodone" badChartDir = "testdata/badchartfile"
goodChartDir = "testdata/goodone"
)
var badChartFilePath string = filepath.Join(badChartDir, "Chart.yaml") var (
var goodChartFilePath string = filepath.Join(goodChartDir, "Chart.yaml") badChartFilePath = filepath.Join(badChartDir, "Chart.yaml")
var nonExistingChartFilePath string = filepath.Join(os.TempDir(), "Chart.yaml") goodChartFilePath = filepath.Join(goodChartDir, "Chart.yaml")
nonExistingChartFilePath = filepath.Join(os.TempDir(), "Chart.yaml")
)
var badChart, chatLoadRrr = chartutil.LoadChartfile(badChartFilePath) var badChart, chatLoadRrr = chartutil.LoadChartfile(badChartFilePath)
var goodChart, _ = chartutil.LoadChartfile(goodChartFilePath) var goodChart, _ = chartutil.LoadChartfile(goodChartFilePath)

@ -32,6 +32,7 @@ import (
"text/template" "text/template"
) )
// Templates lints the templates in the Linter.
func Templates(linter *support.Linter) { func Templates(linter *support.Linter) {
templatesPath := filepath.Join(linter.ChartDir, "templates") templatesPath := filepath.Join(linter.ChartDir, "templates")
@ -222,18 +223,19 @@ func validateNoError(readError error) (lintError support.LintError) {
func validateYamlContent(filePath string, err error) (lintError support.LintError) { func validateYamlContent(filePath string, err error) (lintError support.LintError) {
if err != nil { if err != nil {
lintError = fmt.Errorf("templates: \"%s\". Wrong YAML content.", filePath) lintError = fmt.Errorf("templates: \"%s\". Wrong YAML content", filePath)
} }
return return
} }
func validateNoNamespace(filePath string, yamlStruct K8sYamlStruct) (lintError support.LintError) { func validateNoNamespace(filePath string, yamlStruct K8sYamlStruct) (lintError support.LintError) {
if yamlStruct.Metadata.Namespace != "" { if yamlStruct.Metadata.Namespace != "" {
lintError = fmt.Errorf("templates: \"%s\". namespace option is currently NOT supported.", filePath) lintError = fmt.Errorf("templates: \"%s\". namespace option is currently NOT supported", filePath)
} }
return return
} }
// K8sYamlStruct stubs a Kubernetes YAML file.
// Need to access for now to Namespace only // Need to access for now to Namespace only
type K8sYamlStruct struct { type K8sYamlStruct struct {
Metadata struct { Metadata struct {

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/*Package lint contains tools for linting charts. /*Package support contains tools for linting charts.
Linting is the process of testing charts for errors or warnings regarding Linting is the process of testing charts for errors or warnings regarding
formatting, compilation, or standards compliance. formatting, compilation, or standards compliance.

@ -41,11 +41,13 @@ type Message struct {
Text string Text string
} }
// Linter encapsulates a linting run of a particular chart.
type Linter struct { type Linter struct {
Messages []Message Messages []Message
ChartDir string ChartDir string
} }
// LintError describes an error encountered while linting.
type LintError interface { type LintError interface {
error error
} }
@ -57,7 +59,7 @@ func (m Message) String() string {
return fmt.Sprintf("[%s] %s", sev[m.Severity], m.Text) return fmt.Sprintf("[%s] %s", sev[m.Severity], m.Text)
} }
// Returns true if the validation passed // RunLinterRule returns true if the validation passed
func (l *Linter) RunLinterRule(severity int, lintError LintError) bool { func (l *Linter) RunLinterRule(severity int, lintError LintError) bool {
// severity is out of bound // severity is out of bound
if severity < 0 || severity >= len(sev) { if severity < 0 || severity >= len(sev) {

@ -21,7 +21,7 @@ import (
"testing" "testing"
) )
var linter Linter = Linter{} var linter = Linter{}
var lintError LintError = fmt.Errorf("Foobar") var lintError LintError = fmt.Errorf("Foobar")
func TestRunLinterRule(t *testing.T) { func TestRunLinterRule(t *testing.T) {

Loading…
Cancel
Save