MCPcopy
hub / github.com/runfinch/finch / TestGetVMType

Function TestGetVMType

pkg/lima/lima_test.go:95–181  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

93}
94
95func TestGetVMType(t *testing.T) {
96 t.Parallel()
97
98 instanceName := "finch"
99 mockArgs := []string{"ls", "-f", "{{.VMType}}", instanceName}
100 testCases := []struct {
101 name string
102 want lima.VMType
103 wantErr error
104 mockSvc func(*mocks.NerdctlCmdCreator, *mocks.Logger, *mocks.Command)
105 }{
106 {
107 name: "qemu VM",
108 want: lima.QEMU,
109 wantErr: nil,
110 mockSvc: func(creator *mocks.NerdctlCmdCreator, logger *mocks.Logger, cmd *mocks.Command) {
111 creator.EXPECT().CreateWithoutStdio(mockArgs).Return(cmd)
112 cmd.EXPECT().Output().Return([]byte("qemu"), nil)
113 logger.EXPECT().Debugf("VMType of virtual machine: %s", "qemu")
114 },
115 },
116 {
117 name: "vz VM",
118 want: lima.VZ,
119 wantErr: nil,
120 mockSvc: func(creator *mocks.NerdctlCmdCreator, logger *mocks.Logger, cmd *mocks.Command) {
121 creator.EXPECT().CreateWithoutStdio(mockArgs).Return(cmd)
122 cmd.EXPECT().Output().Return([]byte("vz"), nil)
123 logger.EXPECT().Debugf("VMType of virtual machine: %s", "vz")
124 },
125 },
126 {
127 name: "wsl VM",
128 want: lima.WSL,
129 wantErr: nil,
130 mockSvc: func(creator *mocks.NerdctlCmdCreator, logger *mocks.Logger, cmd *mocks.Command) {
131 creator.EXPECT().CreateWithoutStdio(mockArgs).Return(cmd)
132 cmd.EXPECT().Output().Return([]byte("wsl2"), nil)
133 logger.EXPECT().Debugf("VMType of virtual machine: %s", "wsl2")
134 },
135 },
136 {
137 name: "nonexistent VM",
138 want: lima.NonexistentVMType,
139 wantErr: nil,
140 mockSvc: func(creator *mocks.NerdctlCmdCreator, logger *mocks.Logger, cmd *mocks.Command) {
141 creator.EXPECT().CreateWithoutStdio(mockArgs).Return(cmd)
142 cmd.EXPECT().Output().Return([]byte(" "), nil)
143 logger.EXPECT().Debugf("VMType of virtual machine: %s", "")
144 },
145 },
146 {
147 name: "unknown VM type",
148 want: lima.UnknownVMType,
149 wantErr: errors.New("unrecognized VMType"),
150 mockSvc: func(creator *mocks.NerdctlCmdCreator, logger *mocks.Logger, cmd *mocks.Command) {
151 creator.EXPECT().CreateWithoutStdio(mockArgs).Return(cmd)
152 cmd.EXPECT().Output().Return([]byte("Broken "), nil)

Callers

nothing calls this directly

Calls 10

EXPECTMethod · 0.95
EXPECTMethod · 0.95
NewNerdctlCmdCreatorFunction · 0.92
NewCommandFunction · 0.92
NewLoggerFunction · 0.92
GetVMTypeFunction · 0.92
CreateWithoutStdioMethod · 0.65
OutputMethod · 0.65
DebugfMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected