Skip to content

Commit 826603b

Browse files
authored
Merge pull request #8 from FuturFusion/migration-manager-tests
Add tests for migration-manager
2 parents bfce26f + 78e059f commit 826603b

File tree

18 files changed

+1441
-28
lines changed

18 files changed

+1441
-28
lines changed

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ issues:
2929
# Most of the code of internal/migratekit was copied from the excellent project
3030
# https://github.com/vexxhost/migratekit, Apache-2.0 license.
3131
- internal/migratekit
32+
# Copied from the Go standard library
33+
# https://github.com/golang/go/blob/master/src/net/http/internal/testcert/testcert.go, BSD-3-Clause license
34+
- internal/testcert
3235
linters-settings:
3336
gci:
3437
sections:

cmd/migration-manager/cmds/ask.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package cmds
2+
3+
import "github.com/lxc/incus/v6/shared/ask"
4+
5+
var askPasswordFunc = ask.AskPassword

cmd/migration-manager/cmds/asker_mock_gen_test.go

Lines changed: 260 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/migration-manager/cmds/global.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,23 @@ import (
1212
"path"
1313

1414
"github.com/lxc/incus/v6/shared/api"
15-
"github.com/lxc/incus/v6/shared/ask"
1615
"github.com/lxc/incus/v6/shared/util"
1716
"github.com/spf13/cobra"
1817

1918
"github.com/FuturFusion/migration-manager/cmd/migration-manager/config"
2019
)
2120

21+
//go:generate go run github.com/matryer/moq -fmt goimports -out asker_mock_gen_test.go -rm . Asker
22+
23+
type Asker interface {
24+
AskBool(question string, defaultAnswer string) (bool, error)
25+
AskChoice(question string, choices []string, defaultAnswer string) (string, error)
26+
AskInt(question string, minValue int64, maxValue int64, defaultAnswer string, validate func(int64) error) (int64, error)
27+
AskString(question string, defaultAnswer string, validate func(string) error) (string, error)
28+
}
29+
2230
type CmdGlobal struct {
23-
Asker ask.Asker
31+
Asker Asker
2432

2533
config *config.Config
2634
Cmd *cobra.Command

cmd/migration-manager/cmds/source.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmds
22

33
import (
44
"context"
5+
"crypto/tls"
56
"encoding/json"
67
"errors"
78
"fmt"
@@ -10,7 +11,6 @@ import (
1011
"strconv"
1112
"strings"
1213

13-
"github.com/lxc/incus/v6/shared/ask"
1414
"github.com/spf13/cobra"
1515

1616
"github.com/FuturFusion/migration-manager/internal/source"
@@ -63,6 +63,8 @@ type cmdSourceAdd struct {
6363

6464
flagInsecure bool
6565
flagNoTestConnection bool
66+
67+
additionalRootCertificate *tls.Certificate
6668
}
6769

6870
func (c *cmdSourceAdd) Command() *cobra.Command {
@@ -119,7 +121,7 @@ func (c *cmdSourceAdd) Run(cmd *cobra.Command, args []string) error {
119121
return err
120122
}
121123

122-
sourcePassword := ask.AskPassword("Please enter password for endpoint '" + sourceEndpoint + "': ")
124+
sourcePassword := askPasswordFunc("Please enter password for endpoint '" + sourceEndpoint + "': ")
123125

124126
s := api.VMwareSource{
125127
CommonSource: api.CommonSource{
@@ -147,6 +149,10 @@ func (c *cmdSourceAdd) Run(cmd *cobra.Command, args []string) error {
147149
return err
148150
}
149151

152+
if c.additionalRootCertificate != nil {
153+
internalSource.WithAdditionalRootCertificate(c.additionalRootCertificate)
154+
}
155+
150156
if !c.flagNoTestConnection {
151157
err = internalSource.Connect(ctx)
152158
if err != nil {
@@ -366,7 +372,7 @@ func (c *cmdSourceUpdate) Run(cmd *cobra.Command, args []string) error {
366372
return err
367373
}
368374

369-
specificSource.Password = ask.AskPassword("Password: ")
375+
specificSource.Password = askPasswordFunc("Password: ")
370376

371377
isInsecure := "no"
372378
if specificSource.Insecure {

0 commit comments

Comments
 (0)