github.com/ericwq/aprilsh@v0.0.0-20240517091432-958bc568daa0/util/shell_darwin_test.go (about)

     1  // Copyright 2022 wangqi. All rights reserved.
     2  // Use of this source code is governed by a MIT-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build darwin
     6  
     7  package util
     8  
     9  import (
    10  	"os/user"
    11  	"testing"
    12  )
    13  
    14  // two test case for getShell()
    15  //
    16  // % dscl localhost -read Local/Default/Users/
    17  // name: dsRecTypeStandard:Users
    18  //
    19  // % dscl localhost -read Local/Default/Users/doesnotexist
    20  // <dscl_cmd> DS Error: -14136 (eDSRecordNotFound)
    21  func TestGetShellDarwin(t *testing.T) {
    22  
    23  	// get current user
    24  	s, e := GetShell()
    25  	if e != nil {
    26  		t.Errorf("#test GetShell() darwin expect no error, got %q, error %q\n", s, e)
    27  	}
    28  
    29  	// normal user
    30  	u, err := user.Current()
    31  	if err != nil {
    32  		t.Errorf("#test darwin expect no error, got %s, error %q\n", u, e)
    33  	}
    34  
    35  	// get shell for this user
    36  	s, e = GetShell4(u)
    37  	if e != nil {
    38  		t.Errorf("#test GetShell4() darwin expect no error, got %s, error %q\n", s, e)
    39  	}
    40  }