@@ -43,22 +43,64 @@ func TestAnnotateModel(t *testing.T) {
43
43
44
44
func TestAnnotateModel_Options (t * testing.T ) {
45
45
model := api .NewTestAPI ([]* api.Message {}, []* api.Enum {}, []* api.Service {})
46
- annotate := newAnnotateModel (model )
47
- err := annotate .annotateModel (map [string ]string {
48
- "version" : "1.0.0" ,
49
- "part-file" : "src/test.p.dart" ,
50
- })
51
- if err != nil {
52
- t .Fatal (err )
53
- }
54
46
55
- codec := model .Codec .(* modelAnnotations )
56
-
57
- if diff := cmp .Diff ("1.0.0" , codec .PackageVersion ); diff != "" {
58
- t .Errorf ("mismatch in Codec.PackageVersion (-want, +got)\n :%s" , diff )
47
+ var foo = []struct {
48
+ options map [string ]string
49
+ verify func (* testing.T , * annotateModel )
50
+ }{
51
+ {
52
+ map [string ]string {"package-name-override" : "google-cloud-type" },
53
+ func (t * testing.T , am * annotateModel ) {
54
+ codec := model .Codec .(* modelAnnotations )
55
+ if diff := cmp .Diff ("google-cloud-type" , codec .PackageName ); diff != "" {
56
+ t .Errorf ("mismatch in Codec.PackageName (-want, +got)\n :%s" , diff )
57
+ }
58
+ },
59
+ },
60
+ {
61
+ map [string ]string {"dev-dependencies" : "test,mockito" },
62
+ func (t * testing.T , am * annotateModel ) {
63
+ codec := model .Codec .(* modelAnnotations )
64
+ if diff := cmp .Diff ([]string {"test" , "mockito" , "lints" }, codec .DevDependencies ); diff != "" {
65
+ t .Errorf ("mismatch in Codec.PackageName (-want, +got)\n :%s" , diff )
66
+ }
67
+ },
68
+ },
69
+ {
70
+ map [string ]string {"version" : "1.2.3" },
71
+ func (t * testing.T , am * annotateModel ) {
72
+ codec := model .Codec .(* modelAnnotations )
73
+ if diff := cmp .Diff ("1.2.3" , codec .PackageVersion ); diff != "" {
74
+ t .Errorf ("mismatch in Codec.PackageVersion (-want, +got)\n :%s" , diff )
75
+ }
76
+ },
77
+ },
78
+ {
79
+ map [string ]string {"part-file" : "src/test.p.dart" },
80
+ func (t * testing.T , am * annotateModel ) {
81
+ codec := model .Codec .(* modelAnnotations )
82
+ if diff := cmp .Diff ("src/test.p.dart" , codec .PartFileReference ); diff != "" {
83
+ t .Errorf ("mismatch in Codec.PartFileReference (-want, +got)\n :%s" , diff )
84
+ }
85
+ },
86
+ },
87
+ {
88
+ map [string ]string {"package:http" : "1.2.0" },
89
+ func (t * testing.T , am * annotateModel ) {
90
+ if diff := cmp .Diff (map [string ]string {"http" : "1.2.0" }, am .dependencyConstraints ); diff != "" {
91
+ t .Errorf ("mismatch in annotateModel.dependencyConstraints (-want, +got)\n :%s" , diff )
92
+ }
93
+ },
94
+ },
59
95
}
60
- if diff := cmp .Diff ("src/test.p.dart" , codec .PartFileReference ); diff != "" {
61
- t .Errorf ("mismatch in Codec.PartFileReference (-want, +got)\n :%s" , diff )
96
+
97
+ for _ , tt := range foo {
98
+ annotate := newAnnotateModel (model )
99
+ err := annotate .annotateModel (tt .options )
100
+ if err != nil {
101
+ t .Fatal (err )
102
+ }
103
+ tt .verify (t , annotate )
62
104
}
63
105
}
64
106
@@ -111,28 +153,23 @@ func TestCalculateDependencies(t *testing.T) {
111
153
for _ , test := range []struct {
112
154
name string
113
155
imports []string
114
- want []string
156
+ want []packageDependency
115
157
}{
116
- {name : "empty" , imports : []string {}, want : []string {}},
117
- {name : "dart import" , imports : []string {typedDataImport }, want : []string {}},
118
- {name : "package import" , imports : []string {httpImport }, want : []string { "http" }},
119
- {name : "dart and package imports" , imports : []string {typedDataImport , httpImport }, want : []string { "http" }},
158
+ {name : "empty" , imports : []string {}, want : []packageDependency {}},
159
+ {name : "dart import" , imports : []string {typedDataImport }, want : []packageDependency {}},
160
+ {name : "package import" , imports : []string {httpImport }, want : []packageDependency {{ Name : "http" , Constraint : "^1.3.0" } }},
161
+ {name : "dart and package imports" , imports : []string {typedDataImport , httpImport }, want : []packageDependency {{ Name : "http" , Constraint : "^1.3.0" } }},
120
162
{name : "package imports" , imports : []string {
121
163
httpImport ,
122
164
"package:google_cloud_foo/foo.dart" ,
123
- }, want : []string { "google_cloud_foo" , " http" }},
165
+ }, want : []packageDependency {{ Name : "google_cloud_foo" , Constraint : "any" }, { Name : " http", Constraint : "^1.3.0" } }},
124
166
} {
125
167
t .Run (test .name , func (t * testing.T ) {
126
168
deps := map [string ]string {}
127
169
for _ , imp := range test .imports {
128
170
deps [imp ] = imp
129
171
}
130
- gotFull := calculateDependencies (deps )
131
-
132
- got := []string {}
133
- for _ , dep := range gotFull {
134
- got = append (got , dep .Name )
135
- }
172
+ got := calculateDependencies (deps , map [string ]string {"http" : "^1.3.0" })
136
173
137
174
if diff := cmp .Diff (test .want , got ); diff != "" {
138
175
t .Errorf ("mismatch in calculateDependencies (-want, +got)\n :%s" , diff )
0 commit comments