github.com/MichaelDarr/ahab@v0.0.0-20200528062404-c74c5106e605/internal/utils_test.go (about)

     1  package internal
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  )
     7  
     8  func TestExpandEnvs(t *testing.T) {
     9  	os.Setenv("WHERE", "WORLD")
    10  	os.Setenv("WHAT", "FOO")
    11  	testEnvStrings := []string{"HELLO=$WHERE", "$WHAT=BAR"}
    12  	expectedEnvStrings := []string{"HELLO=WORLD", "FOO=BAR"}
    13  	expandedStrings := expandEnvs(&testEnvStrings)
    14  	expectStrsEq(&expandedStrings, &expectedEnvStrings, t)
    15  }
    16  
    17  func TestPrepVolumeString(t *testing.T) {
    18  	os.Setenv("WHERE", "here")
    19  	configPath := "/home/ahab/src/ahab.json"
    20  	testVolStrings := []string{
    21  		"~/.config:/home/.config",
    22  		"./build:/build",
    23  		"/tmp:/tmp",
    24  		"~/$WHERE:/mnt/$WHERE",
    25  	}
    26  	expectedVolStrings := []string{
    27  		"/home/ahab/.config:/home/.config",
    28  		"/home/ahab/src/build:/build",
    29  		"/tmp:/tmp",
    30  		"/home/ahab/here:/mnt/here",
    31  	}
    32  	for i, testString := range testVolStrings {
    33  		expandedVol, err := prepVolumeString(testString, configPath)
    34  		if err != nil {
    35  			t.Errorf("Error preparing volume string: %s", err)
    36  		}
    37  		expectStrEq(expectedVolStrings[i], expandedVol, t)
    38  	}
    39  }
    40  
    41  func TestSplitGroups(t *testing.T) {
    42  	testGroups := []string{
    43  		"!docker",
    44  		"http",
    45  		"log",
    46  		"!sudo",
    47  		"users",
    48  		"wheel",
    49  	}
    50  	expectedExistingGroups := []string{
    51  		"http",
    52  		"log",
    53  		"users",
    54  		"wheel",
    55  	}
    56  	expectedNewGroups := []string{
    57  		"docker",
    58  		"sudo",
    59  	}
    60  	existingGroups, newGroups := splitGroups(&testGroups)
    61  	expectStrsEq(&expectedExistingGroups, &existingGroups, t)
    62  	expectStrsEq(&expectedNewGroups, &newGroups, t)
    63  }