github.com/wsand02/massren@v1.5.5-0.20191104203215-f721006d1e4e/profile_test.go (about)

     1  package main
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  )
     8  
     9  func Test_profileOpenClose(t *testing.T) {
    10  	if profileDb_ != nil {
    11  		t.Error("profileDb_ should be nil")
    12  	}
    13  
    14  	pwd, _ := os.Getwd()
    15  	homeDir_ = filepath.Join(pwd, "homedirtest")
    16  
    17  	err := profileOpen()
    18  	if err != nil {
    19  		t.Errorf("Expected no error, got %s", err)
    20  	}
    21  
    22  	if profileDb_ == nil {
    23  		t.Error("profileDb_ should be set")
    24  	}
    25  
    26  	profileClose()
    27  	if profileDb_ != nil {
    28  		t.Error("profileDb_ should be nil")
    29  	}
    30  
    31  	profileDelete()
    32  }
    33  
    34  func Test_profileFolder(t *testing.T) {
    35  	setup(t)
    36  	defer teardown(t)
    37  
    38  	profileFolder := profileFolder()
    39  	stat, err := os.Stat(profileFolder)
    40  	if err != nil {
    41  		t.Error(err)
    42  	}
    43  
    44  	if !stat.IsDir() {
    45  		t.Errorf("config folder is not a directory: %s", profileFolder)
    46  	}
    47  }
    48  
    49  func Test_handleConfigCommand_noArgs(t *testing.T) {
    50  	setup(t)
    51  	defer teardown(t)
    52  
    53  	var opts CommandLineOptions
    54  	var err error
    55  
    56  	err = handleConfigCommand(&opts, []string{})
    57  	if err != nil {
    58  		t.Error("Expected no error")
    59  	}
    60  
    61  	err = handleConfigCommand(&opts, []string{"testing", "123"})
    62  	if err != nil {
    63  		t.Errorf("Expected no error, got %s", err)
    64  	}
    65  
    66  	if config_.String("testing") != "123" {
    67  		t.Error("Value not set correctly")
    68  	}
    69  
    70  	handleConfigCommand(&opts, []string{"testing", "abcd"})
    71  	if config_.String("testing") != "abcd" {
    72  		t.Error("Value has not been changed")
    73  	}
    74  
    75  	err = handleConfigCommand(&opts, []string{"testing"})
    76  	if err != nil {
    77  		t.Errorf("Expected no error, got %s", err)
    78  	}
    79  
    80  	if config_.HasKey("testing") {
    81  		t.Error("Key has not been deleted")
    82  	}
    83  }