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

Function TestPostVMStartInitAction_run

cmd/finch/virtual_machine_test.go:80–150  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

78}
79
80func TestPostVMStartInitAction_run(t *testing.T) {
81 t.Parallel()
82
83 testCases := []struct {
84 name string
85 mockSvc func(*mocks.Logger, *mocks.NerdctlCmdCreator, *mocks.Command, *mocks.NerdctlConfigApplier)
86 wantErr error
87 }{
88 {
89 name: "config files are applied after boot",
90 mockSvc: func(logger *mocks.Logger, ncc *mocks.NerdctlCmdCreator, command *mocks.Command, nca *mocks.NerdctlConfigApplier) {
91 logger.EXPECT().Debugln("Applying guest configuration options")
92 command.EXPECT().Output().Return([]byte("80"), nil)
93 ncc.EXPECT().CreateWithoutStdio("ls", "-f", "{{.SSHLocalPort}}", limaInstanceName).Return(command)
94 if runtime.GOOS != "windows" {
95 logger.EXPECT().Warnf("Failed to start credential server: %v", gomock.Any())
96 }
97 nca.EXPECT().Apply("127.0.0.1:80").Return(nil)
98 },
99 wantErr: nil,
100 },
101 {
102 name: "should return an error if sshPortCmd has an error output",
103 mockSvc: func(logger *mocks.Logger, ncc *mocks.NerdctlCmdCreator, command *mocks.Command, _ *mocks.NerdctlConfigApplier) {
104 logger.EXPECT().Debugln("Applying guest configuration options")
105 command.EXPECT().Output().Return(nil, errors.New("ssh port error"))
106 ncc.EXPECT().CreateWithoutStdio("ls", "-f", "{{.SSHLocalPort}}", limaInstanceName).Return(command)
107 },
108 wantErr: errors.New("ssh port error"),
109 },
110 {
111 name: "should print info and return without error if port is 0",
112 mockSvc: func(logger *mocks.Logger, ncc *mocks.NerdctlCmdCreator, command *mocks.Command, _ *mocks.NerdctlConfigApplier) {
113 logger.EXPECT().Debugln("Applying guest configuration options")
114 command.EXPECT().Output().Return([]byte("0"), nil)
115 ncc.EXPECT().CreateWithoutStdio("ls", "-f", "{{.SSHLocalPort}}", limaInstanceName).Return(command)
116 logger.EXPECT().Warnln("SSH port = 0, is the instance running? Not able to apply VM configuration options")
117 },
118 wantErr: nil,
119 },
120 {
121 name: "should return error if applyNerdctlConfig has an error",
122 mockSvc: func(logger *mocks.Logger, ncc *mocks.NerdctlCmdCreator, command *mocks.Command, nca *mocks.NerdctlConfigApplier) {
123 logger.EXPECT().Debugln("Applying guest configuration options")
124 command.EXPECT().Output().Return([]byte("80"), nil)
125 ncc.EXPECT().CreateWithoutStdio("ls", "-f", "{{.SSHLocalPort}}", limaInstanceName).Return(command)
126 if runtime.GOOS != "windows" {
127 logger.EXPECT().Warnf("Failed to start credential server: %v", gomock.Any())
128 }
129 nca.EXPECT().Apply("127.0.0.1:80").Return(errors.New("applyNerdctlConfig has an error"))
130 },
131 wantErr: errors.New("applyNerdctlConfig has an error"),
132 },
133 }
134
135 for _, tc := range testCases {
136 t.Run(tc.name, func(t *testing.T) {
137 t.Parallel()

Callers

nothing calls this directly

Calls 15

EXPECTMethod · 0.95
EXPECTMethod · 0.95
EXPECTMethod · 0.95
EXPECTMethod · 0.95
NewLoggerFunction · 0.92
NewNerdctlCmdCreatorFunction · 0.92
NewCommandFunction · 0.92
NewNerdctlConfigApplierFunction · 0.92
newPostVMStartInitActionFunction · 0.85
DebuglnMethod · 0.65
OutputMethod · 0.65
CreateWithoutStdioMethod · 0.65

Tested by

no test coverage detected