@@ -12,10 +12,19 @@ import (
1212 "daml.com/x/assistant/pkg/resolution"
1313 "daml.com/x/assistant/pkg/testutil"
1414 "github.com/goccy/go-yaml"
15+ "github.com/samber/lo"
1516 "github.com/stretchr/testify/assert"
1617 "github.com/stretchr/testify/require"
1718)
1819
20+ func get (t * testing.T , lock * packagelock.PackageLock , s string ) * packagelock.Dar {
21+ d , ok := lo .Find (lock .Dars , func (d * packagelock.Dar ) bool {
22+ return d .URI .String () == s
23+ })
24+ require .Truef (t , ok , "expected %q dar is missing in lockfile" , s )
25+ return d
26+ }
27+
1928func (suite * MainSuite ) TestLockfileUpdate () {
2029 t := suite .T ()
2130 ctx := t .Context ()
@@ -29,6 +38,13 @@ func (suite *MainSuite) TestLockfileUpdate() {
2938 multiPackageDir := testutil .TestdataPath (t , "simple-multi-package" )
3039 t .Setenv (assistantconfig .DamlMultiPackageEnvVar , multiPackageDir )
3140
41+ cleanup := func () {
42+ _ = os .Remove (filepath .Join (multiPackageDir , "a" , assistantconfig .DamlLocalFilename ))
43+ _ = os .Remove (filepath .Join (multiPackageDir , "b" , assistantconfig .DamlLocalFilename ))
44+ }
45+ cleanup ()
46+ t .Cleanup (cleanup )
47+
3248 // TODO: using a PushComponent() for lack of a PushDar() for now
3349 testutil .PushComponent (t , ctx , reg , "meep" , "1.2.3" , testutil .TestdataPath (t , "some-dar" ), "latest" )
3450 testutil .PushComponent (t , ctx , reg , "sheep" , "4.5.6" , testutil .TestdataPath (t , "some-dar" ), "latest" )
@@ -38,17 +54,22 @@ func (suite *MainSuite) TestLockfileUpdate() {
3854
3955 aLock , err := packagelock .ReadPackageLock (filepath .Join (multiPackageDir , "a" , assistantconfig .DpmLockFileName ))
4056 require .NoError (t , err )
41- assert .Len (t , aLock .Dars , 1 )
42- assert .Equal (t , fmt .Sprintf ("oci://%s/components/meep:1.2.3" , os .Getenv (assistantconfig .OciRegistryEnvVar )), aLock .Dars [0 ].URI )
43- assert .NotEmpty (t , aLock .Dars [0 ].Digest )
57+ assert .Len (t , aLock .Dars , 2 )
58+ d := get (t , aLock , fmt .Sprintf ("oci://%s/components/meep:1.2.3" , os .Getenv (assistantconfig .OciRegistryEnvVar )))
59+ assert .NotEmpty (t , d .Digest )
60+
61+ d = get (t , aLock , "builtin://daml-script" )
62+ assert .Empty (t , d .Digest )
4463
4564 bLock , err := packagelock .ReadPackageLock (filepath .Join (multiPackageDir , "b" , assistantconfig .DpmLockFileName ))
4665 require .NoError (t , err )
4766 assert .Len (t , bLock .Dars , 2 )
48- assert .Equal (t , fmt .Sprintf ("oci://%s/components/meep:1.2.3" , os .Getenv (assistantconfig .OciRegistryEnvVar )), bLock .Dars [0 ].URI )
49- assert .NotEmpty (t , bLock .Dars [0 ].Digest )
50- assert .Equal (t , fmt .Sprintf ("oci://%s/components/sheep:4.5.6" , os .Getenv (assistantconfig .OciRegistryEnvVar )), bLock .Dars [1 ].URI )
51- assert .NotEmpty (t , bLock .Dars [1 ].Digest )
67+
68+ d = get (t , bLock , fmt .Sprintf ("oci://%s/components/meep:1.2.3" , os .Getenv (assistantconfig .OciRegistryEnvVar )))
69+ assert .NotEmpty (t , d .Digest )
70+
71+ d = get (t , bLock , fmt .Sprintf ("oci://%s/components/sheep:4.5.6" , os .Getenv (assistantconfig .OciRegistryEnvVar )))
72+ assert .NotEmpty (t , d .Digest )
5273
5374 t .Run ("bump versions" , func (t * testing.T ) {
5475 testutil .PushComponent (t , ctx , reg , "meep" , "2.0.0" , testutil .TestdataPath (t , "some-dar" ), "latest" )
@@ -62,20 +83,20 @@ func (suite *MainSuite) TestLockfileUpdate() {
6283 bLock , err = packagelock .ReadPackageLock (filepath .Join (multiPackageDir , "b" , assistantconfig .DpmLockFileName ))
6384 require .NoError (t , err )
6485
65- assert .Len (t , aLock .Dars , 1 )
86+ assert .Len (t , aLock .Dars , 2 )
6687 assert .Len (t , bLock .Dars , 2 )
6788
6889 t .Run ("pinned stay pinned" , func (t * testing.T ) {
69- assert . Equal (t , fmt .Sprintf ("oci://%s/components/meep:1.2.3" , os .Getenv (assistantconfig .OciRegistryEnvVar )), aLock . Dars [ 0 ]. URI )
70- assert .NotEmpty (t , aLock . Dars [ 0 ] .Digest )
90+ d = get (t , aLock , fmt .Sprintf ("oci://%s/components/meep:1.2.3" , os .Getenv (assistantconfig .OciRegistryEnvVar )))
91+ assert .NotEmpty (t , d .Digest )
7192
72- assert . Equal (t , fmt .Sprintf ("oci://%s/components/sheep:4.5.6" , os .Getenv (assistantconfig .OciRegistryEnvVar )), bLock . Dars [ 1 ]. URI )
73- assert .NotEmpty (t , bLock . Dars [ 1 ] .Digest )
93+ d = get (t , bLock , fmt .Sprintf ("oci://%s/components/sheep:4.5.6" , os .Getenv (assistantconfig .OciRegistryEnvVar )))
94+ assert .NotEmpty (t , d .Digest )
7495 })
7596
7697 t .Run ("floaty get bumped" , func (t * testing.T ) {
77- assert . Equal (t , fmt .Sprintf ("oci://%s/components/meep:2.0.0" , os .Getenv (assistantconfig .OciRegistryEnvVar )), bLock . Dars [ 0 ]. URI )
78- assert .NotEmpty (t , bLock . Dars [ 0 ] .Digest )
98+ d = get (t , bLock , fmt .Sprintf ("oci://%s/components/meep:2.0.0" , os .Getenv (assistantconfig .OciRegistryEnvVar )))
99+ assert .NotEmpty (t , d .Digest )
79100 })
80101 })
81102
@@ -90,16 +111,16 @@ func (suite *MainSuite) TestLockfileUpdate() {
90111 deepResolution := resolution.Resolution {}
91112 require .NoError (t , yaml .Unmarshal (output , & deepResolution ))
92113
93- assert .Len (t ,
94- deepResolution .Packages [filepath .Join (multiPackageDir , "a" )].Imports [resolution .DarImportsFields ],
95- 1 ,
96- )
114+ aRes := deepResolution .Packages [filepath .Join (multiPackageDir , "a" )].Imports [resolution .DarImportsFields ]
115+ assert .Len (t , aRes , 2 )
97116 assert .Len (t ,
98117 deepResolution .Packages [filepath .Join (multiPackageDir , "b" )].Imports [resolution .DarImportsFields ],
99118 2 ,
100119 )
101120
102- dar , err := os .ReadFile (deepResolution .Packages [filepath .Join (multiPackageDir , "a" )].Imports [resolution .DarImportsFields ][0 ])
121+ assert .Contains (t , aRes , "daml-script" )
122+
123+ dar , err := os .ReadFile (aRes [1 ])
103124 require .NoError (t , err )
104125 assert .Contains (t , string (dar ), "haha not a real dar" )
105126 })
0 commit comments