44 "context"
55 "fmt"
66 "io"
7+ "path/filepath"
78 "strings"
89
910 "github.com/canonical/microk8s-cluster-agent/pkg/snap"
@@ -23,8 +24,21 @@ type JoinClusterCall struct {
2324 Worker bool
2425}
2526
27+ // RunCommandCall contains the arguments passed to a specific call of the RunCommand method.
28+ type RunCommandCall struct {
29+ Commands []string
30+ }
31+
2632// Snap is a generic mock for the snap.Snap interface.
2733type Snap struct {
34+ SnapDir string
35+ SnapDataDir string
36+ SnapCommonDir string
37+ CAPIDir string
38+
39+ RunCommandCalledWith []RunCommandCall
40+ RunCommandErr error
41+
2842 GroupName string
2943
3044 EnableAddonCalledWith []string
@@ -72,6 +86,9 @@ type Snap struct {
7286 KubeletTokens map [string ]string // map hostname to token
7387 KnownTokens map [string ]string // map username to token
7488
89+ CAPIAuthTokenValid bool
90+ CAPIAuthTokenError error
91+
7592 SignCertificateCalledWith []string // string(csrPEM)
7693 SignedCertificate string
7794
@@ -86,6 +103,32 @@ type Snap struct {
86103 JoinClusterCalledWith []JoinClusterCall
87104}
88105
106+ // GetSnapPath is a mock implementation for the snap.Snap interface.
107+ func (s * Snap ) GetSnapPath (parts ... string ) string {
108+ return filepath .Join (append ([]string {s .SnapDir }, parts ... )... )
109+ }
110+
111+ // GetSnapDataPath is a mock implementation for the snap.Snap interface.
112+ func (s * Snap ) GetSnapDataPath (parts ... string ) string {
113+ return filepath .Join (append ([]string {s .SnapDataDir }, parts ... )... )
114+ }
115+
116+ // GetSnapCommonPath is a mock implementation for the snap.Snap interface.
117+ func (s * Snap ) GetSnapCommonPath (parts ... string ) string {
118+ return filepath .Join (append ([]string {s .SnapCommonDir }, parts ... )... )
119+ }
120+
121+ // GetCAPIPath is a mock implementation for the snap.Snap interface.
122+ func (s * Snap ) GetCAPIPath (parts ... string ) string {
123+ return filepath .Join (append ([]string {s .CAPIDir }, parts ... )... )
124+ }
125+
126+ // RunCommand is a mock implementation for the snap.Snap interface.
127+ func (s * Snap ) RunCommand (_ context.Context , commands ... string ) error {
128+ s .RunCommandCalledWith = append (s .RunCommandCalledWith , RunCommandCall {Commands : commands })
129+ return s .RunCommandErr
130+ }
131+
89132// GetGroupName is a mock implementation for the snap.Snap interface.
90133func (s * Snap ) GetGroupName () string {
91134 return s .GroupName
@@ -284,6 +327,11 @@ func (s *Snap) GetKnownToken(username string) (string, error) {
284327 return "" , fmt .Errorf ("no known token for user %s" , username )
285328}
286329
330+ // IsCAPIAuthTokenValid is a mock implementation for the snap.Snap interface.
331+ func (s * Snap ) IsCAPIAuthTokenValid (token string ) (bool , error ) {
332+ return s .CAPIAuthTokenValid , s .CAPIAuthTokenError
333+ }
334+
287335// RunUpgrade is a mock implementation for the snap.Snap interface.
288336func (s * Snap ) RunUpgrade (ctx context.Context , upgrade string , phase string ) error {
289337 s .RunUpgradeCalledWith = append (s .RunUpgradeCalledWith , fmt .Sprintf ("%s %s" , upgrade , phase ))
0 commit comments