github.com/uhthomas/helm@v3.0.0-beta.3+incompatible/pkg/helmpath/lazypath_darwin_test.go (about)

     1  // Copyright The Helm Authors.
     2  // Licensed under the Apache License, Version 2.0 (the "License");
     3  // you may not use this file except in compliance with the License.
     4  // You may obtain a copy of the License at
     5  
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  // +build darwin
    15  
    16  package helmpath
    17  
    18  import (
    19  	"os"
    20  	"path/filepath"
    21  	"testing"
    22  
    23  	"k8s.io/client-go/util/homedir"
    24  
    25  	"helm.sh/helm/pkg/helmpath/xdg"
    26  )
    27  
    28  const (
    29  	appName  = "helm"
    30  	testFile = "test.txt"
    31  	lazy     = lazypath(appName)
    32  )
    33  
    34  func TestDataPath(t *testing.T) {
    35  	os.Unsetenv(xdg.DataHomeEnvVar)
    36  
    37  	expected := filepath.Join(homedir.HomeDir(), "Library", appName, testFile)
    38  
    39  	if lazy.dataPath(testFile) != expected {
    40  		t.Errorf("expected '%s', got '%s'", expected, lazy.dataPath(testFile))
    41  	}
    42  
    43  	os.Setenv(xdg.DataHomeEnvVar, "/tmp")
    44  
    45  	expected = filepath.Join("/tmp", appName, testFile)
    46  
    47  	if lazy.dataPath(testFile) != expected {
    48  		t.Errorf("expected '%s', got '%s'", expected, lazy.dataPath(testFile))
    49  	}
    50  }
    51  
    52  func TestConfigPath(t *testing.T) {
    53  	os.Unsetenv(xdg.ConfigHomeEnvVar)
    54  
    55  	expected := filepath.Join(homedir.HomeDir(), "Library", "Preferences", appName, testFile)
    56  
    57  	if lazy.configPath(testFile) != expected {
    58  		t.Errorf("expected '%s', got '%s'", expected, lazy.configPath(testFile))
    59  	}
    60  
    61  	os.Setenv(xdg.ConfigHomeEnvVar, "/tmp")
    62  
    63  	expected = filepath.Join("/tmp", appName, testFile)
    64  
    65  	if lazy.configPath(testFile) != expected {
    66  		t.Errorf("expected '%s', got '%s'", expected, lazy.configPath(testFile))
    67  	}
    68  }
    69  
    70  func TestCachePath(t *testing.T) {
    71  	os.Unsetenv(xdg.CacheHomeEnvVar)
    72  
    73  	expected := filepath.Join(homedir.HomeDir(), "Library", "Caches", appName, testFile)
    74  
    75  	if lazy.cachePath(testFile) != expected {
    76  		t.Errorf("expected '%s', got '%s'", expected, lazy.cachePath(testFile))
    77  	}
    78  
    79  	os.Setenv(xdg.CacheHomeEnvVar, "/tmp")
    80  
    81  	expected = filepath.Join("/tmp", appName, testFile)
    82  
    83  	if lazy.cachePath(testFile) != expected {
    84  		t.Errorf("expected '%s', got '%s'", expected, lazy.cachePath(testFile))
    85  	}
    86  }