2020-10-16 08:43:02 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
type dotnetArgs struct {
|
|
|
|
enabled bool
|
|
|
|
version string
|
2021-06-16 09:52:42 -07:00
|
|
|
exitCode int
|
2020-10-16 08:43:02 -07:00
|
|
|
unsupportedIcon string
|
|
|
|
displayVersion bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func bootStrapDotnetTest(args *dotnetArgs) *dotnet {
|
|
|
|
env := new(MockedEnvironment)
|
2021-01-05 04:05:37 -08:00
|
|
|
env.On("hasCommand", "dotnet").Return(args.enabled)
|
2021-06-16 09:52:42 -07:00
|
|
|
if args.exitCode != 0 {
|
|
|
|
err := &commandError{exitCode: args.exitCode}
|
2020-10-16 08:43:02 -07:00
|
|
|
env.On("runCommand", "dotnet", []string{"--version"}).Return("", err)
|
|
|
|
} else {
|
|
|
|
env.On("runCommand", "dotnet", []string{"--version"}).Return(args.version, nil)
|
|
|
|
}
|
2020-12-27 23:33:58 -08:00
|
|
|
|
|
|
|
env.On("hasFiles", "*.cs").Return(true)
|
|
|
|
env.On("getPathSeperator", nil).Return("")
|
2021-03-22 11:19:08 -07:00
|
|
|
env.On("getcwd", nil).Return("/usr/home/project")
|
|
|
|
env.On("homeDir", nil).Return("/usr/home")
|
2021-11-26 01:37:33 -08:00
|
|
|
var props properties = map[Property]interface{}{
|
|
|
|
DisplayVersion: args.displayVersion,
|
|
|
|
UnsupportedDotnetVersionIcon: args.unsupportedIcon,
|
2020-10-16 08:43:02 -07:00
|
|
|
}
|
2020-12-27 23:33:58 -08:00
|
|
|
dotnet := &dotnet{}
|
|
|
|
dotnet.init(props, env)
|
|
|
|
return dotnet
|
2020-10-16 08:43:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEnabledDotnetNotFound(t *testing.T) {
|
|
|
|
args := &dotnetArgs{
|
|
|
|
enabled: false,
|
|
|
|
}
|
|
|
|
dotnet := bootStrapDotnetTest(args)
|
2020-12-27 23:33:58 -08:00
|
|
|
assert.True(t, dotnet.enabled())
|
2020-10-16 08:43:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDotnetVersionNotDisplayed(t *testing.T) {
|
|
|
|
args := &dotnetArgs{
|
|
|
|
enabled: true,
|
|
|
|
displayVersion: false,
|
|
|
|
version: "3.1.402",
|
|
|
|
}
|
|
|
|
dotnet := bootStrapDotnetTest(args)
|
|
|
|
assert.True(t, dotnet.enabled())
|
|
|
|
assert.Equal(t, "", dotnet.string())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDotnetVersionDisplayed(t *testing.T) {
|
|
|
|
expected := "3.1.402"
|
|
|
|
args := &dotnetArgs{
|
|
|
|
enabled: true,
|
|
|
|
displayVersion: true,
|
|
|
|
version: expected,
|
|
|
|
}
|
|
|
|
dotnet := bootStrapDotnetTest(args)
|
|
|
|
assert.True(t, dotnet.enabled())
|
|
|
|
assert.Equal(t, expected, dotnet.string())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDotnetVersionUnsupported(t *testing.T) {
|
|
|
|
args := &dotnetArgs{
|
|
|
|
enabled: true,
|
|
|
|
displayVersion: true,
|
2021-06-23 13:19:43 -07:00
|
|
|
exitCode: dotnetExitCode,
|
2020-10-16 08:43:02 -07:00
|
|
|
unsupportedIcon: expected,
|
|
|
|
}
|
|
|
|
dotnet := bootStrapDotnetTest(args)
|
|
|
|
assert.True(t, dotnet.enabled())
|
|
|
|
assert.Equal(t, expected, dotnet.string())
|
|
|
|
}
|