github.com/kbehouse/nsc@v0.0.6/cmd/options_test.go (about)

     1  /*
     2   * Copyright 2020 The NATS Authors
     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 cmd
    17  
    18  import (
    19  	"os"
    20  	"path/filepath"
    21  	"testing"
    22  
    23  	"github.com/stretchr/testify/require"
    24  )
    25  
    26  func TestNoGitIgnore(t *testing.T) {
    27  	require.NoError(t, os.Setenv(NscNoGitIgnoreEnv, "true"))
    28  	defer func() {
    29  		require.NoError(t, os.Unsetenv(NscNoGitIgnoreEnv))
    30  	}()
    31  	SetEnvOptions()
    32  	ts := NewTestStore(t, "O")
    33  	defer ts.Done(t)
    34  	ts.DoesNotExist(t, filepath.Join(ts.Dir, "keys", ".gitignore"))
    35  }
    36  
    37  func TestCwdOnly(t *testing.T) {
    38  	require.NoError(t, os.Setenv(NscCwdOnlyEnv, "true"))
    39  	defer func() {
    40  		require.NoError(t, os.Unsetenv(NscCwdOnlyEnv))
    41  	}()
    42  	SetEnvOptions()
    43  	ts := NewTestStore(t, "O")
    44  	defer ts.Done(t)
    45  
    46  	_, stderr, err := ExecuteCmd(GetRootCmd(), "env")
    47  	require.NoError(t, err)
    48  	stderr = StripTableDecorations(stderr)
    49  	require.Contains(t, stderr, "$NSC_CWD_ONLY Yes")
    50  
    51  	_, _, err = ExecuteCmd(createEnvCmd(), "--account", "A")
    52  	require.Error(t, err)
    53  	require.Contains(t, err.Error(), "$NSC_CWD_ONLY is set")
    54  }