1515package dart
1616
1717import (
18+ "maps"
1819 "testing"
1920
2021 "github.com/google/go-cmp/cmp"
2122 "github.com/googleapis/librarian/internal/sidekick/internal/api"
2223 "github.com/googleapis/librarian/internal/sidekick/internal/sample"
2324)
2425
26+ var (
27+ requiredConfig = map [string ]string {
28+ "package:google_cloud_gax" : "^1.2.3" ,
29+ "package:http" : "^4.5.6" }
30+ )
31+
2532func TestAnnotateModel (t * testing.T ) {
2633 model := api .NewTestAPI ([]* api.Message {}, []* api.Enum {}, []* api.Service {})
2734 model .PackageName = "test"
2835 annotate := newAnnotateModel (model )
29- err := annotate .annotateModel (map [string ]string {})
36+ err := annotate .annotateModel (map [string ]string {"package:google_cloud_gax" : "^1.2.3" })
3037 if err != nil {
3138 t .Fatal (err )
3239 }
@@ -103,9 +110,9 @@ func TestAnnotateModel_Options(t *testing.T) {
103110 },
104111 },
105112 {
106- map [string ]string {"package:http" : "1.2.0" },
113+ map [string ]string {"google_cloud_gax" : "^1.2.3" , " package:http" : "1.2.0" },
107114 func (t * testing.T , am * annotateModel ) {
108- if diff := cmp .Diff (map [string ]string {"http" : "1.2.0" }, am .dependencyConstraints ); diff != "" {
115+ if diff := cmp .Diff (map [string ]string {"google_cloud_gax" : "^1.2.3" , " http" : "1.2.0" }, am .dependencyConstraints ); diff != "" {
109116 t .Errorf ("mismatch in annotateModel.dependencyConstraints (-want, +got)\n :%s" , diff )
110117 }
111118 },
@@ -114,7 +121,9 @@ func TestAnnotateModel_Options(t *testing.T) {
114121
115122 for _ , tt := range tests {
116123 annotate := newAnnotateModel (model )
117- err := annotate .annotateModel (tt .options )
124+ options := maps .Clone (requiredConfig )
125+ maps .Copy (options , tt .options )
126+ err := annotate .annotateModel (maps .Clone (options ))
118127 if err != nil {
119128 t .Fatal (err )
120129 }
@@ -140,7 +149,7 @@ func TestAnnotateMethod(t *testing.T) {
140149 )
141150 api .Validate (model )
142151 annotate := newAnnotateModel (model )
143- err := annotate .annotateModel (map [ string ] string {} )
152+ err := annotate .annotateModel (requiredConfig )
144153 if err != nil {
145154 t .Fatal (err )
146155 }
@@ -180,14 +189,17 @@ func TestCalculateDependencies(t *testing.T) {
180189 {name : "package imports" , imports : []string {
181190 httpImport ,
182191 "package:google_cloud_foo/foo.dart" ,
183- }, want : []packageDependency {{Name : "google_cloud_foo" , Constraint : "any " }, {Name : "http" , Constraint : "^1.3.0" }}},
192+ }, want : []packageDependency {{Name : "google_cloud_foo" , Constraint : "^1.2.3 " }, {Name : "http" , Constraint : "^1.3.0" }}},
184193 } {
185194 t .Run (test .name , func (t * testing.T ) {
186195 deps := map [string ]bool {}
187196 for _ , imp := range test .imports {
188197 deps [imp ] = true
189198 }
190- got := calculateDependencies (deps , map [string ]string {"http" : "^1.3.0" })
199+ got , err := calculateDependencies (deps , map [string ]string {"google_cloud_foo" : "^1.2.3" , "http" : "^1.3.0" })
200+ if err != nil {
201+ t .Fatal (err )
202+ }
191203
192204 if diff := cmp .Diff (test .want , got ); diff != "" {
193205 t .Errorf ("mismatch in calculateDependencies (-want, +got)\n :%s" , diff )
0 commit comments