Просмотр исходного кода

Updated config_test to tests configs missing each required field

Miro Kuratczyk 10 лет назад
Родитель
Сommit
1b99258b5b
1 измененных файлов с 8 добавлено и 13 удалено
  1. 8 13
      psiphon/config_test.go

+ 8 - 13
psiphon/config_test.go

@@ -86,19 +86,14 @@ func (suite *ConfigTestSuite) Test_LoadConfig_BadJson() {
 	_, err := LoadConfig([]byte(`{"f1": 11, "f2": "two"}`))
 	suite.NotNil(err, "JSON with none of our fields should fail")
 
-	// Missing a required field
-	json.Unmarshal(suite.confStubBlob, &testObj)
-	delete(testObj, suite.requiredFields[0])
-	testObjJSON, _ = json.Marshal(testObj)
-	_, err = LoadConfig(testObjJSON)
-	suite.NotNil(err, "JSON with one of our required fields missing should fail")
-
-	// Missing required SponsorId field
-	json.Unmarshal(suite.confStubBlob, &testObj)
-	delete(testObj, suite.requiredFields[1]) // will need to update if config in README changes
-	testObjJSON, _ = json.Marshal(testObj)
-	_, err = LoadConfig(testObjJSON)
-	suite.NotNil(err, "JSON with missing SponsorId field should fail")
+  // Test config missing each required field
+  for i := 0; i < len(suite.requiredFields); i++ {
+	  json.Unmarshal(suite.confStubBlob, &testObj)
+	  delete(testObj, suite.requiredFields[i])
+	  testObjJSON, _ = json.Marshal(testObj)
+	  _, err = LoadConfig(testObjJSON)
+	  suite.NotNil(err, "JSON with one of our required fields missing should fail")
+  }
 
 	// Bad type for required field
 	json.Unmarshal(suite.confStubBlob, &testObj)