@@ -7,6 +7,7 @@ package workapplier
77
88import (
99 "context"
10+ "fmt"
1011 "testing"
1112
1213 "github.com/google/go-cmp/cmp"
@@ -1001,6 +1002,7 @@ func TestServiceExportAvailability(t *testing.T) {
10011002 weight string
10021003 status fleetnetworkingv1alpha1.ServiceExportStatus
10031004 wantManifestProcessingAvailabilityResultType ManifestProcessingAvailabilityResultType
1005+ err error
10041006 }{
10051007 {
10061008 name : "available svcExport (annotation weight is 0)" ,
@@ -1016,6 +1018,7 @@ func TestServiceExportAvailability(t *testing.T) {
10161018 },
10171019 },
10181020 wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeAvailable ,
1021+ err : nil ,
10191022 },
10201023 {
10211024 name : "unavailable svcExport (ServiceExportValid is false)" ,
@@ -1031,6 +1034,7 @@ func TestServiceExportAvailability(t *testing.T) {
10311034 },
10321035 },
10331036 wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1037+ err : nil ,
10341038 },
10351039 {
10361040 name : "unavailable svcExport (different generation, annotation weight is 0)" ,
@@ -1046,6 +1050,7 @@ func TestServiceExportAvailability(t *testing.T) {
10461050 },
10471051 },
10481052 wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1053+ err : nil ,
10491054 },
10501055 {
10511056 name : "available svcExport with no conflict (annotation weight is 1)" ,
@@ -1067,6 +1072,7 @@ func TestServiceExportAvailability(t *testing.T) {
10671072 },
10681073 },
10691074 wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeAvailable ,
1075+ err : nil ,
10701076 },
10711077 {
10721078 name : "unavailable svcExport with conflict (annotation weight is 1)" ,
@@ -1088,6 +1094,7 @@ func TestServiceExportAvailability(t *testing.T) {
10881094 },
10891095 },
10901096 wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1097+ err : nil ,
10911098 },
10921099 {
10931100 name : "unavailable invalid svcExport (annotation weight is 1)" ,
@@ -1103,6 +1110,7 @@ func TestServiceExportAvailability(t *testing.T) {
11031110 },
11041111 },
11051112 wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1113+ err : nil ,
11061114 },
11071115 {
11081116 name : "unavailable svcExport (different generation, annotation weight is 1)" ,
@@ -1124,6 +1132,7 @@ func TestServiceExportAvailability(t *testing.T) {
11241132 },
11251133 },
11261134 wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1135+ err : nil ,
11271136 },
11281137 {
11291138 name : "unavailable svcExport (no annotation weight, no conflict condition)" ,
@@ -1139,6 +1148,7 @@ func TestServiceExportAvailability(t *testing.T) {
11391148 },
11401149 },
11411150 wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1151+ err : nil ,
11421152 },
11431153 {
11441154 name : "available svcExport (no annotation weight)" ,
@@ -1160,6 +1170,7 @@ func TestServiceExportAvailability(t *testing.T) {
11601170 },
11611171 },
11621172 wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeAvailable ,
1173+ err : nil ,
11631174 },
11641175 {
11651176 name : "unavailable svcExport (no annotation weight with conflict)" ,
@@ -1181,6 +1192,7 @@ func TestServiceExportAvailability(t *testing.T) {
11811192 },
11821193 },
11831194 wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1195+ err : nil ,
11841196 },
11851197 {
11861198 name : "unavailable svcExport (no annotation weight, different generation)" ,
@@ -1202,6 +1214,7 @@ func TestServiceExportAvailability(t *testing.T) {
12021214 },
12031215 },
12041216 wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1217+ err : nil ,
12051218 },
12061219 {
12071220 name : "unavailable svcExport (no annotation weight, invalid service export)" ,
@@ -1217,6 +1230,7 @@ func TestServiceExportAvailability(t *testing.T) {
12171230 },
12181231 },
12191232 wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1233+ err : nil ,
12201234 },
12211235 {
12221236 name : "unavailable svcExport (invalid weight)" ,
@@ -1232,6 +1246,7 @@ func TestServiceExportAvailability(t *testing.T) {
12321246 },
12331247 },
12341248 wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1249+ err : fmt .Errorf ("the weight annotation is not a valid integer: a" ),
12351250 },
12361251 {
12371252 name : "unavailable svcExport (out of range weight)" ,
@@ -1247,6 +1262,7 @@ func TestServiceExportAvailability(t *testing.T) {
12471262 },
12481263 },
12491264 wantManifestProcessingAvailabilityResultType : ManifestProcessingAvailabilityResultTypeNotYetAvailable ,
1265+ err : fmt .Errorf ("the weight annotation is not in the range [0, 1000]: 1002" ),
12501266 },
12511267 }
12521268
@@ -1258,8 +1274,14 @@ func TestServiceExportAvailability(t *testing.T) {
12581274 }
12591275 svcExport .Status = tc .status
12601276 gotResTyp , err := trackServiceExportAvailability (toUnstructured (t , svcExport ))
1277+
1278+ // Check for errors
12611279 if err != nil {
1262- t .Fatalf ("trackServiceExportAvailability() = %v, want no error" , err )
1280+ if tc .err == nil || err .Error () != tc .err .Error () {
1281+ t .Fatalf ("trackServiceExportAvailability() = %v, want %v" , err , tc .err )
1282+ }
1283+ } else if tc .err != nil {
1284+ t .Fatalf ("trackServiceExportAvailability() = nil, want error: %v" , tc .err )
12631285 }
12641286
12651287 // Check the result type
0 commit comments