@@ -3,8 +3,9 @@ package main
33import (
44 "bytes"
55 "context"
6+ "errors"
67 "fmt"
7- "log"
8+ "log/slog "
89 "strconv"
910 "testing"
1011
@@ -13,6 +14,7 @@ import (
1314 "github.com/aws/aws-sdk-go-v2/service/cloudfront/types"
1415 "github.com/stretchr/testify/assert"
1516 "github.com/stretchr/testify/require"
17+ "github.com/wjam/aws_finder/internal/log"
1618)
1719
1820func TestFindCloudFrontDistributions (t * testing.T ) {
@@ -99,8 +101,15 @@ func TestFindCloudFrontDistributions(t *testing.T) {
99101 for _ , test := range tests {
100102 t .Run (test .needle , func (t * testing.T ) {
101103 var buf bytes.Buffer
102- require .NoError (t , findCloudFrontDistributions (t .Context (), test .needle , log .New (& buf , "" , 0 ), & distributions {test .distributions }))
103- assert .Equal (t , fmt .Sprintf ("%s\n " , test .expected ), buf .String ())
104+
105+ ctx := log .ContextWithLogger (t .Context (), slog .New (log.WithAttrsFromContextHandler {
106+ Parent : slog .NewTextHandler (& buf , & slog.HandlerOptions {Level : slog .LevelDebug }),
107+ IgnoredAttributes : []string {"time" },
108+ }))
109+
110+ err := findCloudFrontDistributions (ctx , test .needle , & distributions {test .distributions })
111+ require .NoError (t , err )
112+ assert .Equal (t , fmt .Sprintf ("level=INFO msg=%s\n " , test .expected ), buf .String ())
104113 })
105114 }
106115}
@@ -111,9 +120,11 @@ type distributions struct {
111120 distributions [][]types.DistributionSummary
112121}
113122
114- func (d * distributions ) ListDistributions (ctx context.Context , _ * cloudfront.ListDistributionsInput , _ ... func (* cloudfront.Options )) (* cloudfront.ListDistributionsOutput , error ) {
123+ func (d * distributions ) ListDistributions (
124+ ctx context.Context , _ * cloudfront.ListDistributionsInput , _ ... func (* cloudfront.Options ),
125+ ) (* cloudfront.ListDistributionsOutput , error ) {
115126 if ctx == nil {
116- return nil , fmt . Errorf ("missing context" )
127+ return nil , errors . New ("missing context" )
117128 }
118129
119130 var value []types.DistributionSummary
0 commit comments