github.com/swaros/contxt/module/runner@v0.0.0-20240305083542-3dbd4436ac40/zshhelper_test.go (about)

     1  package runner_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/swaros/contxt/module/dirhandle"
     7  	"github.com/swaros/contxt/module/runner"
     8  	"github.com/swaros/contxt/module/systools"
     9  )
    10  
    11  func TestGetFPath(t *testing.T) {
    12  	zsh := runner.NewZshHelper()
    13  	zPath, err := zsh.GetBinPath()
    14  	if err != nil || zPath == "" {
    15  		t.Log("skipped zsh Testing, because it seems zsh not being installed.")
    16  		t.SkipNow()
    17  	} else {
    18  		if fp, ferr := zsh.GetFirstFPath(); ferr != nil {
    19  			// test also skipped if no first path is found.
    20  			// it is too much depending on the system to throw an error on this case.
    21  			t.Log("skipped zsh Testing, because we did not get any usefull path.")
    22  			t.SkipNow()
    23  		} else {
    24  			// this is close the only test we can do.
    25  			// we can not test if the fpath is correct, because it is too much depending on the system.
    26  			if fp == "" {
    27  				t.Error("FirstFPath is empty")
    28  			}
    29  
    30  			if !systools.IsDirWriteable(fp) {
    31  				t.Error("FirstFPath is not writeable")
    32  			}
    33  
    34  		}
    35  	}
    36  
    37  }
    38  
    39  func TestExistingPath(t *testing.T) {
    40  	zsh := runner.NewZshHelper()
    41  	zPath, err := zsh.GetBinPath()
    42  	if err != nil || zPath == "" {
    43  		t.Log("skipped zsh Testing, because it seems zsh not being installed.")
    44  		t.SkipNow()
    45  	} else {
    46  		firstExisting, err := zsh.GetFirstExistingPath()
    47  		if err != nil {
    48  			t.SkipNow()
    49  		}
    50  		if firstExisting == "" {
    51  			t.Error("FirstExistingPath is empty")
    52  
    53  		} else {
    54  			if exists, err := dirhandle.Exists(firstExisting); err != nil || !exists {
    55  				t.Log("FirstExistingPath is not existing")
    56  			}
    57  		}
    58  	}
    59  }