I am trying to create integration tests for a Go application that sends reads configurations, reads a file, and uploads this file to Azure Cloud Storage. The code for the application is written, but I'm not entirely sure how I would create integration tests for it, or if I my idea of integration tests is even appropriate for the problem.
I've been trying to create tests that mock away the Connection to the datastore, but I'm having trouble understanding how I would even go about doing that.
main.go:
main (){
//reads in azureConnectionDetails
upload, err := azure.NewUpload(azureConnectionDetails, inChannel, outChannel)
upload.SendFileWhenMessageRecieved()
inChannel <- file
}
azure.go:
NewUpload (azureConnectionDetails, inChannel, outChannel){
ds, err := datastore.ConnectToDataStore(azureConnectionDetails)
return upload{ds}
}
SendFileWhenMessageReceived(){
//Sends the file to outChannel when the file is sent to inChannel
}
datastore.go
ConnectToDataStore(){
//connects to azure
//returns ds
}
I can run "main" when I run "go test", but when the program gets to the part where it tries to connect to Azure it throws an error, because I don't provide credentials to connect to a real instance of Azure. That makes sense of course, however I don't want to connect to a real instance.
Is there a way I can mock away this connection to Azure with how my code is set up already? What would I have to change?