(t *testing.T)
| 78 | } |
| 79 | |
| 80 | func 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() |
nothing calls this directly
no test coverage detected