44 "context"
55 "fmt"
66 "io"
7+ "path/filepath"
78 "strings"
89
910 "github.com/canonical/microk8s-cluster-agent/pkg/snap"
@@ -23,8 +24,20 @@ 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+
38+ RunCommandCalledWith []RunCommandCall
39+ RunCommandErr error
40+
2841 GroupName string
2942
3043 EnableAddonCalledWith []string
@@ -88,6 +101,27 @@ type Snap struct {
88101 EtcdCA , EtcdCert , EtcdKey string
89102}
90103
104+ // GetSnapPath is a mock implementation for the snap.Snap interface.
105+ func (s * Snap ) GetSnapPath (parts ... string ) string {
106+ return filepath .Join (append ([]string {s .SnapDir }, parts ... )... )
107+ }
108+
109+ // GetSnapDataPath is a mock implementation for the snap.Snap interface.
110+ func (s * Snap ) GetSnapDataPath (parts ... string ) string {
111+ return filepath .Join (append ([]string {s .SnapDataDir }, parts ... )... )
112+ }
113+
114+ // GetSnapCommonPath is a mock implementation for the snap.Snap interface.
115+ func (s * Snap ) GetSnapCommonPath (parts ... string ) string {
116+ return filepath .Join (append ([]string {s .SnapCommonDir }, parts ... )... )
117+ }
118+
119+ // RunCommand is a mock implementation for the snap.Snap interface.
120+ func (s * Snap ) RunCommand (_ context.Context , commands ... string ) error {
121+ s .RunCommandCalledWith = append (s .RunCommandCalledWith , RunCommandCall {Commands : commands })
122+ return s .RunCommandErr
123+ }
124+
91125// GetGroupName is a mock implementation for the snap.Snap interface.
92126func (s * Snap ) GetGroupName () string {
93127 return s .GroupName
0 commit comments