mirror of
https://github.com/helm/helm.git
synced 2026-03-18 08:40:09 -04:00
* spelling: constraint Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: cryptographic Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: dependency Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: doesnot Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: don't Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: unexpected Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: dreadnought Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: default Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: envvars Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: evaluates Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: execute Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: extractor Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: frobnitz Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: generated Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: implementation Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: jabba Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: keywords Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: kubernetes Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: override Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: package Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: parsable Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: progress Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: recursively Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: release Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: cache Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: representing Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: serializer Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: subchart Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: utilities Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
105 lines
2.3 KiB
Go
105 lines
2.3 KiB
Go
/*
|
|
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 cli
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/spf13/pflag"
|
|
)
|
|
|
|
func TestEnvSettings(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
|
|
// input
|
|
args string
|
|
envvars map[string]string
|
|
|
|
// expected values
|
|
ns, kcontext string
|
|
debug bool
|
|
}{
|
|
{
|
|
name: "defaults",
|
|
ns: "default",
|
|
},
|
|
{
|
|
name: "with flags set",
|
|
args: "--debug --namespace=myns",
|
|
ns: "myns",
|
|
debug: true,
|
|
},
|
|
{
|
|
name: "with envvars set",
|
|
envvars: map[string]string{"HELM_DEBUG": "1", "HELM_NAMESPACE": "yourns"},
|
|
ns: "yourns",
|
|
debug: true,
|
|
},
|
|
{
|
|
name: "with flags and envvars set",
|
|
args: "--debug --namespace=myns",
|
|
envvars: map[string]string{"HELM_DEBUG": "1", "HELM_NAMESPACE": "yourns"},
|
|
ns: "myns",
|
|
debug: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
defer resetEnv()()
|
|
|
|
for k, v := range tt.envvars {
|
|
os.Setenv(k, v)
|
|
}
|
|
|
|
flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
|
|
|
|
settings := New()
|
|
settings.AddFlags(flags)
|
|
flags.Parse(strings.Split(tt.args, " "))
|
|
|
|
if settings.Debug != tt.debug {
|
|
t.Errorf("expected debug %t, got %t", tt.debug, settings.Debug)
|
|
}
|
|
if settings.Namespace() != tt.ns {
|
|
t.Errorf("expected namespace %q, got %q", tt.ns, settings.Namespace())
|
|
}
|
|
if settings.KubeContext != tt.kcontext {
|
|
t.Errorf("expected kube-context %q, got %q", tt.kcontext, settings.KubeContext)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func resetEnv() func() {
|
|
origEnv := os.Environ()
|
|
|
|
// ensure any local envvars do not hose us
|
|
for e := range New().EnvVars() {
|
|
os.Unsetenv(e)
|
|
}
|
|
|
|
return func() {
|
|
for _, pair := range origEnv {
|
|
kv := strings.SplitN(pair, "=", 2)
|
|
os.Setenv(kv[0], kv[1])
|
|
}
|
|
}
|
|
}
|