@@ -20,6 +20,7 @@ import (
2020 "testing"
2121
2222 "github.com/google/go-cmp/cmp"
23+ "github.com/google/go-cmp/cmp/cmpopts"
2324)
2425
2526func TestProject (t * testing.T ) {
@@ -784,3 +785,92 @@ func TestInterpolate(t *testing.T) {
784785 t .Errorf ("interpolate:\n (-got, +want):\n %s" , diff )
785786 }
786787}
788+
789+ func TestInterpolateRepositories (t * testing.T ) {
790+ proj := Project {
791+ ProjectKey : ProjectKey {
792+ GroupID : "com.example" ,
793+ ArtifactID : "basic" ,
794+ Version : "1.2.3" ,
795+ },
796+ Properties : Properties {
797+ Properties : []Property {
798+ {Name : "repo.id" , Value : "my-repo" },
799+ {Name : "repo.url" , Value : "https://www.my-repo.example.com" },
800+ {Name : "repo.layout" , Value : "default" },
801+ {Name : "dep.version" , Value : "1.0.0" },
802+ },
803+ },
804+ Repositories : []Repository {{
805+ ID : "${repo.id}" ,
806+ URL : "${repo.url}" ,
807+ Layout : "${repo.layout}" ,
808+ Releases : RepositoryPolicy {
809+ Enabled : "true" ,
810+ },
811+ Snapshots : RepositoryPolicy {
812+ Enabled : "false" ,
813+ },
814+ }, {
815+ ID : "another-repo" ,
816+ URL : "https://www.another-repo.example.com" ,
817+ }},
818+ Dependencies : []Dependency {{
819+ GroupID : "org.example" ,
820+ ArtifactID : "dep" ,
821+ Version : "${dep.version}" ,
822+ }},
823+ }
824+ want := Project {
825+ ProjectKey : ProjectKey {
826+ GroupID : "com.example" ,
827+ ArtifactID : "basic" ,
828+ Version : "1.2.3" ,
829+ },
830+ Properties : Properties {
831+ Properties : []Property {
832+ {Name : "repo.id" , Value : "my-repo" },
833+ {Name : "repo.url" , Value : "https://www.my-repo.example.com" },
834+ {Name : "repo.layout" , Value : "default" },
835+ {Name : "dep.version" , Value : "1.0.0" },
836+ },
837+ },
838+ Repositories : []Repository {{
839+ ID : "my-repo" ,
840+ URL : "https://www.my-repo.example.com" ,
841+ Layout : "default" ,
842+ Releases : RepositoryPolicy {
843+ Enabled : "true" ,
844+ },
845+ Snapshots : RepositoryPolicy {
846+ Enabled : "false" ,
847+ },
848+ }, {
849+ ID : "another-repo" ,
850+ URL : "https://www.another-repo.example.com" ,
851+ }},
852+ Dependencies : []Dependency {{
853+ GroupID : "org.example" ,
854+ ArtifactID : "dep" ,
855+ Version : "${dep.version}" ,
856+ }},
857+ }
858+ if err := proj .InterpolateRepositories (); err != nil {
859+ t .Fatalf ("InterpolateRepositories() err = %v, want nil" , err )
860+ }
861+ if diff := cmp .Diff (proj , want , cmpopts .EquateEmpty ()); diff != "" {
862+ t .Errorf ("interpolate repositories:\n (-got, +want):\n %s" , diff )
863+ }
864+
865+ want .Dependencies = []Dependency {{
866+ GroupID : "org.example" ,
867+ ArtifactID : "dep" ,
868+ Version : "1.0.0" ,
869+ }}
870+ if err := proj .Interpolate (); err != nil {
871+ t .Fatalf ("Interpolate() err = %v, want nil" , err )
872+ }
873+ if diff := cmp .Diff (proj , want , cmpopts .EquateEmpty ()); diff != "" {
874+ t .Errorf ("interpolate repositories then interpolate:\n (-got, +want):\n %s" , diff )
875+ }
876+ }
0 commit comments