Skip to content

Commit 71b2464

Browse files
committed
feat: Added new mockery package config. Added shell command action.
1 parent 0d05999 commit 71b2464

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+678
-2612
lines changed

.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf

.mockery.yaml

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
recursive: true
22
all: true
3+
dir: "pkg/mocks/{{.PackageName}}mocks"
34
filename: "mock_{{.InterfaceNameSnake}}.go"
45
mockname: "{{.InterfaceName}}"
5-
outpkg: "{{base .PackageName}}mocks"
6+
outpkg: "{{.PackageName}}mocks"
67
with-expecter: true
7-
dir: "pkg/mocks/{{.PackageName}}mocks"
88
packages:
9-
"github.com/hostfactor/diazo/pkg/userfiles":
10-
config:
11-
recursive: false
9+
github.com/hostfactor/diazo/pkg/userfiles:
10+
config: { }
11+
github.com/hostfactor/diazo/pkg/actions:
12+
config: { }

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/hostfactor/diazo
22

3-
go 1.20
3+
go 1.21
44

55
require (
66
github.com/bxcodec/faker/v3 v3.8.0
@@ -11,7 +11,7 @@ require (
1111
github.com/fsnotify/fsnotify v1.5.4
1212
github.com/golang/protobuf v1.5.2
1313
github.com/google/go-cmp v0.5.6
14-
github.com/hostfactor/api/go v0.0.0-20230924204613-3eb5c78315d1
14+
github.com/hostfactor/api/go v0.0.0-20231105200036-e2dbc3bafb8b
1515
github.com/json-iterator/go v1.1.12
1616
github.com/mattn/go-zglob v0.0.3
1717
github.com/mholt/archiver/v3 v3.5.1

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,10 @@ github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKEN
578578
github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4=
579579
github.com/hostfactor/api/go v0.0.0-20230924204613-3eb5c78315d1 h1:um6z8aaa6wKe1JNelbNQRR/e5Q6nGMVyWL/NFHFb+NA=
580580
github.com/hostfactor/api/go v0.0.0-20230924204613-3eb5c78315d1/go.mod h1:BPl1fWTa0458aaL3TqjwbU7lgKgewJtUhoxfTMARMKM=
581+
github.com/hostfactor/api/go v0.0.0-20231104050646-334b46352923 h1:nGAG3LQct5u7gKZFSiwYCSk3sKL8l8xVOaQ7PmednPM=
582+
github.com/hostfactor/api/go v0.0.0-20231104050646-334b46352923/go.mod h1:BPl1fWTa0458aaL3TqjwbU7lgKgewJtUhoxfTMARMKM=
583+
github.com/hostfactor/api/go v0.0.0-20231105200036-e2dbc3bafb8b h1:Mov/utmfZxmQ3yNIrAoNbTkSs2nnLgYHCJtWjfBQ6rQ=
584+
github.com/hostfactor/api/go v0.0.0-20231105200036-e2dbc3bafb8b/go.mod h1:BPl1fWTa0458aaL3TqjwbU7lgKgewJtUhoxfTMARMKM=
581585
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
582586
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
583587
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=

pkg/actions/fileactions/client.go pkg/actions/client.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package fileactions
1+
package actions
22

33
import (
44
"archive/zip"
5+
"context"
56
"fmt"
67
"github.com/hostfactor/api/go/blueprint/actions"
78
"github.com/hostfactor/api/go/blueprint/filesystem"
@@ -12,6 +13,7 @@ import (
1213
"io"
1314
"io/fs"
1415
"os"
16+
"os/exec"
1517
"path"
1618
"path/filepath"
1719
)
@@ -26,6 +28,7 @@ type Client interface {
2628
Upload(root string, u *actions.UploadFile, opts UploadOpts) error
2729
Zip(z *actions.ZipFile) error
2830
MoveFile(a *actions.MoveFile) error
31+
Shell(ctx context.Context, a *actions.Shell) ([]byte, error)
2932
}
3033

3134
type OnError func(err error)
@@ -84,12 +87,21 @@ type OnDownloadFuncParams struct {
8487

8588
type OnDownloadFunc func(params OnDownloadFuncParams)
8689

90+
func New(c userfiles.Client) Client {
91+
return &client{UserfilesClient: c}
92+
}
93+
8794
type client struct {
8895
UserfilesClient userfiles.Client
8996
}
9097

91-
func New(c userfiles.Client) Client {
92-
return &client{UserfilesClient: c}
98+
func (i *client) Shell(ctx context.Context, a *actions.Shell) ([]byte, error) {
99+
cmd := exec.CommandContext(ctx, "/bin/sh", "-c", a.GetCommand())
100+
if cmd.Err != nil {
101+
return nil, cmd.Err
102+
}
103+
104+
return cmd.CombinedOutput()
93105
}
94106

95107
func (i *client) MoveFile(a *actions.MoveFile) error {
@@ -183,6 +195,10 @@ func Move(file *actions.MoveFile) error {
183195
return Default.MoveFile(file)
184196
}
185197

198+
func Shell(ctx context.Context, a *actions.Shell) ([]byte, error) {
199+
return Default.Shell(ctx, a)
200+
}
201+
186202
func move(fp fs.FS, f *actions.MoveFile) error {
187203
found, err := Find(fp, f.GetFrom().GetMatches())
188204
if err != nil {

pkg/actions/fileactions/client_test.go pkg/actions/client_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package fileactions
1+
package actions
22

33
import (
44
"bytes"
@@ -7,9 +7,9 @@ import (
77
"github.com/hostfactor/api/go/blueprint/actions"
88
"github.com/hostfactor/api/go/blueprint/filesystem"
99
"github.com/hostfactor/diazo/pkg/fileutils"
10+
"github.com/hostfactor/diazo/pkg/mocks/userfilesmocks"
1011
"github.com/hostfactor/diazo/pkg/testutils"
1112
"github.com/hostfactor/diazo/pkg/userfiles"
12-
"github.com/hostfactor/diazo/pkg/userfiles/mocks"
1313
"github.com/stretchr/testify/suite"
1414
"io"
1515
"io/fs"
@@ -24,12 +24,12 @@ import (
2424
type ClientTestSuite struct {
2525
suite.Suite
2626

27-
UserfilesClient *mocks.Client
27+
UserfilesClient *userfilesmocks.Client
2828
Svc *client
2929
}
3030

3131
func (p *ClientTestSuite) BeforeTest(_, _ string) {
32-
p.UserfilesClient = new(mocks.Client)
32+
p.UserfilesClient = new(userfilesmocks.Client)
3333
p.Svc = &client{UserfilesClient: p.UserfilesClient}
3434
fileutils.IsTest = true
3535
Default = p.Svc
@@ -536,7 +536,7 @@ func (p *ClientTestSuite) TestDownload() {
536536
v.After(dir)
537537
p.Equal(v.ExpectedError, err, "test %d", i)
538538
p.UserfilesClient.AssertExpectations(p.T())
539-
p.UserfilesClient = new(mocks.Client)
539+
p.UserfilesClient = new(userfilesmocks.Client)
540540
p.Svc.UserfilesClient = p.UserfilesClient
541541
}
542542
}
@@ -603,7 +603,7 @@ func (p *ClientTestSuite) TestUpload() {
603603
v.After(b)
604604
p.Equal(err, v.ExpectedError, "test %d", i)
605605
p.UserfilesClient.AssertExpectations(p.T())
606-
p.UserfilesClient = new(mocks.Client)
606+
p.UserfilesClient = new(userfilesmocks.Client)
607607
p.Svc.UserfilesClient = p.UserfilesClient
608608
}
609609
}

pkg/actions/fileactions/mocks/client.go

-128
This file was deleted.

pkg/actions/fileactions/mocks/on_download_func.go

-33
This file was deleted.

pkg/actions/fileactions/mocks/on_error.go

-30
This file was deleted.

pkg/actions/fileactions/mocks/on_upload_func.go

-33
This file was deleted.

pkg/actions/fileactions/match.go pkg/actions/match.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package fileactions
1+
package actions
22

33
import (
44
"github.com/hostfactor/api/go/blueprint/filesystem"

0 commit comments

Comments
 (0)