github.com/zaquestion/lab@v0.25.1/cmd/snippet_browse_test.go (about)

     1  package cmd
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/spf13/viper"
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func Test_snippetBrowse(t *testing.T) {
    11  	viper.SetConfigName("lab")
    12  	viper.SetConfigType("toml")
    13  	viper.AddConfigPath("../testdata")
    14  	err := viper.ReadInConfig()
    15  	if err != nil {
    16  		t.Error(err)
    17  	}
    18  
    19  	oldBrowse := browse
    20  	defer func() { browse = oldBrowse }()
    21  
    22  	browse = func(url string) error {
    23  		require.Equal(t, "https://gitlab.com/zaquestion/test/snippets", url)
    24  		return nil
    25  	}
    26  
    27  	snippetBrowseCmd.Run(nil, []string{})
    28  
    29  	browse = func(url string) error {
    30  		require.Equal(t, "https://gitlab.com/zaquestion/test/snippets/23", url)
    31  		return nil
    32  	}
    33  
    34  	snippetBrowseCmd.Run(nil, []string{"origin", "23"})
    35  }