Skip to content

Commit 76906f7

Browse files
authored
Merge pull request #531 from DefangLabs/edw-better-diff
Use a better diff to show change in loaded compose file in tests
2 parents aad3bdb + 4c6a6e7 commit 76906f7

File tree

4 files changed

+43
-15
lines changed

4 files changed

+43
-15
lines changed

pkgs/defang/cli.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildGoModule {
66
pname = "defang-cli";
77
version = "git";
88
src = ../../src;
9-
vendorHash = "sha256-a5Vqd+ZxxcPEgE8bC/yIcO3zq0xKHoj9HyT9mHj6XVw=";
9+
vendorHash = "sha256-wljhUGPO/gCA6hsl2dMVhaVVtTFbo6A9dKs0Km4YhL0=";
1010

1111
subPackages = [ "cmd/cli" ];
1212

src/go.mod

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.21
44

55
require (
66
github.com/AlecAivazis/survey/v2 v2.3.7
7+
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883
78
github.com/aws/aws-sdk-go-v2 v1.27.0
89
github.com/aws/aws-sdk-go-v2/config v1.26.6
910
github.com/aws/aws-sdk-go-v2/service/cloudformation v1.42.6
@@ -46,8 +47,12 @@ require (
4647
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
4748
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
4849
github.com/mattn/go-runewidth v0.0.14 // indirect
50+
github.com/mitchellh/copystructure v1.2.0 // indirect
51+
github.com/mitchellh/mapstructure v1.5.0 // indirect
52+
github.com/mitchellh/reflectwalk v1.0.2 // indirect
4953
github.com/rivo/uniseg v0.2.0 // indirect
5054
github.com/russross/blackfriday/v2 v2.1.0 // indirect
55+
github.com/sergi/go-diff v1.3.1 // indirect
5156
golang.org/x/net v0.22.0 // indirect
5257
)
5358

@@ -83,9 +88,6 @@ require (
8388
github.com/mattn/go-isatty v0.0.20 // indirect
8489
github.com/mattn/go-shellwords v1.0.12 // indirect
8590
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
86-
github.com/mitchellh/copystructure v1.2.0 // indirect
87-
github.com/mitchellh/mapstructure v1.5.0 // indirect
88-
github.com/mitchellh/reflectwalk v1.0.2 // indirect
8991
github.com/moby/term v0.5.0 // indirect
9092
github.com/morikuni/aec v1.0.0 // indirect
9193
github.com/opencontainers/go-digest v1.0.0 // indirect

src/go.sum

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
66
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
77
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
88
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
9+
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
10+
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
911
github.com/aws/aws-sdk-go-v2 v1.27.0 h1:7bZWKoXhzI+mMR/HjdMx8ZCC5+6fY0lS5tr0bbgiLlo=
1012
github.com/aws/aws-sdk-go-v2 v1.27.0/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM=
1113
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 h1:x6xsQXGSmW6frevwDA+vi/wqhp1ct18mVXYN08/93to=
@@ -129,6 +131,7 @@ github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNU
129131
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
130132
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
131133
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
134+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
132135
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
133136
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
134137
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
@@ -192,6 +195,8 @@ github.com/ross96D/cancelreader v0.2.6 h1:XLPWassoMWRTlHvEoVKS3z0N0a7jHcIupGU0U1
192195
github.com/ross96D/cancelreader v0.2.6/go.mod h1:sSs12d88ds2FFb9aOsKYyhTJCJDQDOll6gpyILZwIzc=
193196
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
194197
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
198+
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
199+
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
195200
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
196201
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
197202
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
@@ -200,6 +205,7 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
200205
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
201206
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
202207
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
208+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
203209
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
204210
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
205211
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
@@ -303,10 +309,13 @@ google.golang.org/grpc v1.60.1/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz
303309
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
304310
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
305311
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
312+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
306313
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
307314
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
308-
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
315+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
309316
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
317+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
318+
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
310319
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
311320
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
312321
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

src/pkg/cli/compose/loader_test.go

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"regexp"
1010
"strings"
1111
"testing"
12+
13+
linediff "github.com/andreyvit/diff"
1214
)
1315

1416
func TestLoader(t *testing.T) {
@@ -47,20 +49,35 @@ func compare(actual []byte, goldenFile string) error {
4749
}
4850

4951
func diff(actualRaw, goldenRaw string) error {
50-
linesActual := strings.Split(actualRaw, "\n")
51-
linesGolden := strings.Split(goldenRaw, "\n")
52-
for i, actual := range linesActual {
53-
if i >= len(linesGolden) {
54-
return fmt.Errorf("+ expected - actual\n+EOF\n-%s", actual)
52+
53+
if actualRaw == goldenRaw {
54+
return nil
55+
}
56+
57+
var buf strings.Builder
58+
const contextSize = 3
59+
60+
diffs := linediff.LineDiffAsLines(goldenRaw, actualRaw)
61+
show := make([]bool, len(diffs))
62+
63+
for i, diff := range diffs {
64+
if diff[0] == ' ' {
65+
continue
5566
}
56-
if actual != linesGolden[i] {
57-
return fmt.Errorf("+ expected - actual\n+%s\n-%s", linesGolden[i], actual)
67+
for j := i - contextSize; j < i+contextSize; j++ {
68+
if j >= 0 && j < len(diffs) {
69+
show[j] = true
70+
}
5871
}
5972
}
60-
if len(linesActual) < len(linesGolden) {
61-
return fmt.Errorf("+ expected - actual\n+%s\n-EOF", linesGolden[len(linesActual)])
73+
74+
w := len(fmt.Sprint(len(diffs)))
75+
for i, s := range show {
76+
if s {
77+
fmt.Fprintf(&buf, "%*v: %s\n", w, i, diffs[i])
78+
}
6279
}
63-
return nil
80+
return fmt.Errorf("diff:\n%s", buf.String())
6481
}
6582

6683
func testRunCompose(t *testing.T, f func(t *testing.T, path string)) {

0 commit comments

Comments
 (0)