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
@@ -88,6 +105,32 @@ type Snap struct {
88105 EtcdCA , EtcdCert , EtcdKey string
89106}
90107
108+ // GetSnapPath is a mock implementation for the snap.Snap interface.
109+ func (s * Snap ) GetSnapPath (parts ... string ) string {
110+ return filepath .Join (append ([]string {s .SnapDir }, parts ... )... )
111+ }
112+
113+ // GetSnapDataPath is a mock implementation for the snap.Snap interface.
114+ func (s * Snap ) GetSnapDataPath (parts ... string ) string {
115+ return filepath .Join (append ([]string {s .SnapDataDir }, parts ... )... )
116+ }
117+
118+ // GetSnapCommonPath is a mock implementation for the snap.Snap interface.
119+ func (s * Snap ) GetSnapCommonPath (parts ... string ) string {
120+ return filepath .Join (append ([]string {s .SnapCommonDir }, parts ... )... )
121+ }
122+
123+ // GetCAPIPath is a mock implementation for the snap.Snap interface.
124+ func (s * Snap ) GetCAPIPath (parts ... string ) string {
125+ return filepath .Join (append ([]string {s .CAPIDir }, parts ... )... )
126+ }
127+
128+ // RunCommand is a mock implementation for the snap.Snap interface.
129+ func (s * Snap ) RunCommand (_ context.Context , commands ... string ) error {
130+ s .RunCommandCalledWith = append (s .RunCommandCalledWith , RunCommandCall {Commands : commands })
131+ return s .RunCommandErr
132+ }
133+
91134// GetGroupName is a mock implementation for the snap.Snap interface.
92135func (s * Snap ) GetGroupName () string {
93136 return s .GroupName
@@ -286,6 +329,11 @@ func (s *Snap) GetKnownToken(username string) (string, error) {
286329 return "" , fmt .Errorf ("no known token for user %s" , username )
287330}
288331
332+ // IsCAPIAuthTokenValid is a mock implementation for the snap.Snap interface.
333+ func (s * Snap ) IsCAPIAuthTokenValid (token string ) (bool , error ) {
334+ return s .CAPIAuthTokenValid , s .CAPIAuthTokenError
335+ }
336+
289337// RunUpgrade is a mock implementation for the snap.Snap interface.
290338func (s * Snap ) RunUpgrade (ctx context.Context , upgrade string , phase string ) error {
291339 s .RunUpgradeCalledWith = append (s .RunUpgradeCalledWith , fmt .Sprintf ("%s %s" , upgrade , phase ))
0 commit comments