-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more thorough check on auth vars, and tests for the check
- Loading branch information
1 parent
99b6055
commit f572d5b
Showing
2 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package target | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var cfg = EventHubConfig{ | ||
EventHubNamespace: "test", | ||
EventHubName: "test", | ||
} | ||
|
||
func unsetEverything() { | ||
os.Unsetenv("EVENTHUB_KEY_NAME") | ||
os.Unsetenv("EVENTHUB_KEY_VALUE") | ||
|
||
os.Unsetenv("EVENTHUB_CONNECTION_STRING") | ||
|
||
os.Unsetenv("AZURE_TENANT_ID") | ||
os.Unsetenv("AZURE_CLIENT_ID") | ||
|
||
os.Unsetenv("AZURE_CLIENT_SECRET") | ||
|
||
os.Unsetenv("AZURE_CERTIFICATE_PATH") | ||
os.Unsetenv("AZURE_CERTIFICATE_PASSWORD") | ||
} | ||
|
||
func TestNewEventHubTarget_KeyValue(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
unsetEverything() | ||
|
||
// Test that we can initialise a client with Key and Value | ||
defer os.Unsetenv("EVENTHUB_KEY_NAME") | ||
defer os.Unsetenv("EVENTHUB_KEY_VALUE") | ||
|
||
os.Setenv("EVENTHUB_KEY_NAME", "fake") | ||
os.Setenv("EVENTHUB_KEY_VALUE", "fake") | ||
|
||
tgt, err := NewEventHubTarget(&cfg) | ||
assert.Nil(err) | ||
assert.NotNil(tgt) | ||
} | ||
|
||
func TestNewEventHubTarget_ConnString(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
unsetEverything() | ||
|
||
// Test that we can initialise a client with Connection String | ||
defer os.Unsetenv("EVENTHUB_CONNECTION_STRING") | ||
|
||
os.Setenv("EVENTHUB_CONNECTION_STRING", "Endpoint=sb://test.servicebus.windows.net/;SharedAccessKeyName=fake;SharedAccessKey=fake") | ||
|
||
tgt, err := NewEventHubTarget(&cfg) | ||
assert.Nil(err) | ||
assert.NotNil(tgt) | ||
} | ||
|
||
func TestNewEventHubTarget_Failure(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
unsetEverything() | ||
|
||
tgt, err := NewEventHubTarget(&cfg) | ||
assert.Equal("Error initialising EventHub client: No valid combination of authentication Env vars found. https://pkg.go.dev/github.com/Azure/azure-event-hubs-go#NewHubWithNamespaceNameAndEnvironment", err.Error()) | ||
assert.Nil(tgt) | ||
} |