Skip to content

Commit da040fa

Browse files
committed
add tests
1 parent 397d5cf commit da040fa

File tree

12 files changed

+11434
-52
lines changed

12 files changed

+11434
-52
lines changed

.github/workflows/release.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ jobs:
1111
- name: Checkout
1212
uses: actions/checkout@v1
1313

14-
- name: Set up Go 1.13
14+
- name: Set up Go 1.14
1515
uses: actions/setup-go@v1
1616
with:
17-
go-version: 1.13
17+
go-version: 1.14
18+
run: make
1819

1920
- name: Run GoReleaser
2021
uses: goreleaser/goreleaser-action@v1

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
# goreleaser binaries
1818
dist
1919

20+
# vendor
21+
vendor
22+
2023
# temporary
2124
**/.DS_Store
2225
**/debug

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export CGO_ENABLED=0
1919
export GOPROXY=https://proxy.golang.org
2020

2121
.PHONY: all
22-
all: fmt lint | $(BIN) ; $(info $(M) building executable…) @ ## Build program binary
22+
all: fmt lint test | $(BIN) ; $(info $(M) building executable…) @ ## Build program binary
2323
$Q $(GO) build \
2424
-tags release \
2525
-ldflags '-X main.Version=$(VERSION) -X main.BuildDate=$(DATE)' \
@@ -47,6 +47,9 @@ $(BIN)/gocov-xml: PACKAGE=github.com/AlekSi/gocov-xml
4747
GO2XUNIT = $(BIN)/go2xunit
4848
$(BIN)/go2xunit: PACKAGE=github.com/tebeka/go2xunit
4949

50+
GOMOCK = $(BIN)/mockery
51+
$(BIN)/mockery: PACKAGE=github.com/vektra/mockery/.../
52+
5053
# Tests
5154

5255
TEST_TARGETS := test-default test-bench test-short test-verbose test-race
@@ -91,6 +94,13 @@ lint: | $(GOLINT) ; $(info $(M) running golint…) @ ## Run golint
9194
fmt: ; $(info $(M) running gofmt…) @ ## Run gofmt on all source files
9295
$Q $(GO) fmt $(PKGS)
9396

97+
.PHONY: mock
98+
mock: | $(GOMOCK) ; $(info $(M) generating mocks…) @ ## Run mockery
99+
$Q $(GO) mod vendor -v
100+
$Q $(GOMOCK) -name SecretsManagerAPI -dir vendor/github.com/aws/aws-sdk-go/service/secretsmanager/secretsmanageriface
101+
$Q $(GOMOCK) -name SSMAPI -dir vendor/github.com/aws/aws-sdk-go/service/ssm/ssmiface
102+
$Q rm -rf vendor
103+
94104
# Misc
95105

96106
.PHONY: clean

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
module secrets-init
22

3-
go 1.13
3+
go 1.14
44

55
require (
66
cloud.google.com/go v0.50.0
77
github.com/aws/aws-sdk-go v1.24.1
8+
github.com/pkg/errors v0.9.1
89
github.com/sirupsen/logrus v1.4.2
9-
github.com/stretchr/testify v1.4.0 // indirect
10+
github.com/stretchr/testify v1.4.0
1011
github.com/urfave/cli/v2 v2.0.0
11-
golang.org/x/net v0.0.0-20190918130420-a8b05e9114ab // indirect
12+
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b // indirect
1213
google.golang.org/api v0.15.0 // indirect
1314
google.golang.org/genproto v0.0.0-20191220175831-5c49e3ecc1c1
1415
)

go.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
5959
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
6060
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
6161
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
62+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
63+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
6264
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6365
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
6466
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
@@ -69,6 +71,7 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
6971
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
7072
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
7173
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
74+
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
7275
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
7376
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
7477
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
@@ -112,8 +115,8 @@ golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn
112115
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
113116
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
114117
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
115-
golang.org/x/net v0.0.0-20190918130420-a8b05e9114ab h1:h5tBRKZ1aY/bo6GNqe/4zWC8GkaLOFQ5wPKIOQ0i2sA=
116-
golang.org/x/net v0.0.0-20190918130420-a8b05e9114ab/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
118+
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8=
119+
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
117120
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
118121
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
119122
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0=
@@ -157,6 +160,7 @@ golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtn
157160
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
158161
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
159162
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
163+
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361 h1:RIIXAeV6GvDBuADKumTODatUqANFZ+5BPMnzsy4hulY=
160164
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
161165
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
162166
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

main.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,18 @@ func mainCmd(c *cli.Context) error {
6666

6767
// get provider
6868
var provider secrets.Provider
69+
var err error
6970
if c.String("provider") == "aws" {
70-
provider = new(aws.SecretsProvider)
71+
provider, err = aws.NewAwsSecretsProvider()
7172
} else if c.String("provider") == "google" {
72-
provider = new(google.SecretsProvider)
73+
provider, err = google.NewGoogleSecretsProvider()
74+
}
75+
if err != nil {
76+
log.WithField("provider", c.String("provider")).WithError(err).Error("failed to initialize secrets provider")
7377
}
7478
// Launch main command
7579
var mainRC int
76-
err := run(ctx, provider, c.Args().Slice())
80+
err = run(ctx, provider, c.Args().Slice())
7781
if err != nil {
7882
log.WithError(err).Error("failed to run")
7983
mainRC = 1
@@ -136,7 +140,11 @@ func run(ctx context.Context, provider secrets.Provider, commandSlice []string)
136140
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
137141

138142
// set environment variables
139-
cmd.Env = provider.ResolveSecrets(ctx, os.Environ())
143+
var err error
144+
cmd.Env, err = provider.ResolveSecrets(ctx, os.Environ())
145+
if err != nil {
146+
log.WithError(err).Error("failed to resolve secrets")
147+
}
140148

141149
// Goroutine for signals forwarding
142150
go func() {
@@ -150,14 +158,21 @@ func run(ctx context.Context, provider secrets.Provider, commandSlice []string)
150158
}()
151159

152160
// start the specified command
153-
err := cmd.Start()
161+
log.WithFields(log.Fields{
162+
"command": commandStr,
163+
"args": argsSlice,
164+
"env": cmd.Env,
165+
}).Debug("starting command")
166+
err = cmd.Start()
154167
if err != nil {
168+
log.WithError(err).Error("failed to start command")
155169
return err
156170
}
157171

158172
// wait for the command to exit
159173
err = cmd.Wait()
160174
if err != nil {
175+
log.WithError(err).Error("failed to wait for command to complete")
161176
return err
162177
}
163178

0 commit comments

Comments
 (0)