github.com/migueleliasweb/helm@v2.6.1+incompatible/cmd/helm/version_test.go (about)

     1  /*
     2  Copyright 2016 The Kubernetes Authors All rights reserved.
     3  Licensed under the Apache License, Version 2.0 (the "License");
     4  you may not use this file except in compliance with the License.
     5  You may obtain a copy of the License at
     6  
     7  http://www.apache.org/licenses/LICENSE-2.0
     8  
     9  Unless required by applicable law or agreed to in writing, software
    10  distributed under the License is distributed on an "AS IS" BASIS,
    11  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  See the License for the specific language governing permissions and
    13  limitations under the License.
    14  */
    15  
    16  package main
    17  
    18  import (
    19  	"bytes"
    20  	"strings"
    21  	"testing"
    22  
    23  	"k8s.io/helm/pkg/helm"
    24  	"k8s.io/helm/pkg/version"
    25  )
    26  
    27  func TestVersion(t *testing.T) {
    28  
    29  	lver := version.GetVersionProto().SemVer
    30  	sver := "1.2.3-fakeclient+testonly"
    31  
    32  	tests := []struct {
    33  		name           string
    34  		client, server bool
    35  		args           []string
    36  		fail           bool
    37  	}{
    38  		{"default", true, true, []string{}, false},
    39  		{"client", true, false, []string{"-c"}, false},
    40  		{"server", false, true, []string{"-s"}, false},
    41  	}
    42  
    43  	settings.TillerHost = "fake-localhost"
    44  	for _, tt := range tests {
    45  		b := new(bytes.Buffer)
    46  		c := &helm.FakeClient{}
    47  
    48  		cmd := newVersionCmd(c, b)
    49  		cmd.ParseFlags(tt.args)
    50  		if err := cmd.RunE(cmd, tt.args); err != nil {
    51  			if tt.fail {
    52  				continue
    53  			}
    54  			t.Fatal(err)
    55  		}
    56  
    57  		if tt.client && !strings.Contains(b.String(), lver) {
    58  			t.Errorf("Expected %q to contain %q", b.String(), lver)
    59  		}
    60  		if tt.server && !strings.Contains(b.String(), sver) {
    61  			t.Errorf("Expected %q to contain %q", b.String(), sver)
    62  		}
    63  	}
    64  }