欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

golang - linux 上 which 命令的简单实现 - 单元测试

最编程 2024-04-07 06:59:14
...
import (
	"testing"
    
	"github.com/stretchr/testify/assert"
)

func TestWhich(t *testing.T) {
	filepath, _ := Which("sh")
	assert.Equal(t, filepath, "/bin/sh")

	filepath, err := Which("xxx")
	assert.Equal(t, filepath, "")
	assert.ErrorContains(t, err, "no such file or directory")
}