Here's a fun one...I have a static @HTTP method creating metadata as a webservice. You can test metadata deployment containers, though not the actual deployment, as shown here, but apparently only if the method containing the deployment method is an instance method. Since mine is an @HTTP method, it must be static. It also must be void, so I can't use the result of it in my test.
@HttpPost
global static void createDO(String fullName, String label, Map<String, String> FieldsWithValuesMap){
Metadata.CustomMetadata DegOff = new Metadata.CustomMetadata();
DegOff.fullName = fullName;
DegOff.label = label;
for(String Field : FieldsWithValuesMap.keySet()){
Metadata.CustomMetadataValue customField = new Metadata.CustomMetadataValue();
customField.field = Field;
customField.value = FieldsWithValuesMap.get(Field);
DegOff.values.add(customField);
}
Metadata.DeployContainer DOContainer = new Metadata.DeployContainer();
DOContainer.addMetadata(DegOff);
CreateDOService callback = new CreateDOService();
If(!Test.isRunningTest()){
Id jobId = Metadata.Operations.enqueueDeployment(DOContainer, callback);
}
}
The problem is, I can't create an instance of the static method in a test class, and if I call the method directly, there doesn't seem to be any way to query the results.
@IsTest
public static void testCreateDO(){
Map<String, String> DoFieldValues = new Map<String, String>{'Field 1' => 'Value 1', 'Field 2' => 'Value 2'};
CreateDOService.CreateDO('fullName', 'label', DOFieldValues);
Once I've done the above, how could I verify Metadata.CustomMetadata DegOff or Metadata.DeployContainer DOContainer? Since this is fairly new salesforce functionality, I could imagine that there is no recourse on this yet.
I found this similar case, but it does not appear that the person was actually testing their deployment code.
Thanks!