I found this question/answer when I ran into the same problem. I made a smaller repro, starting from batter.cord's, above. Salesforce support have confirmed that it is a bug and will be fixed, but there is no ETA for the fix. It's not currently on Known Issues, but I'll update if they add it. We have a bug number W-4947848
FYI, my repro follows. The insertContact()
test passes, the insertContentVersion()
test fails.
@IsTest
private class ContentVersionBugRepro {
public class MyQueueable implements Queueable, Database.AllowsCallouts {
public void execute(QueueableContext param1) {
Http connection = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(System.Url.getOrgDomainUrl().toExternalForm());
connection.send(request);
}
}
public class MyMock implements HttpCalloutMock {
public HttpResponse respond(HttpRequest param1) {
return new HttpResponse();
}
}
@IsTest static void insertContact() {
insert new Contact(LastName = 'Test');
Test.setMock(HttpCalloutMock.class, new MyMock());
Test.startTest();
System.enqueueJob(new MyQueueable());
Test.stopTest();
}
@IsTest static void insertContentVersion() {
insert new ContentVersion(
VersionData = Blob.valueOf('someData'),
PathOnClient = 'someData.txt'
);
Test.setMock(HttpCalloutMock.class, new MyMock());
Test.startTest();
System.enqueueJob(new MyQueueable());
Test.stopTest();
}
}