-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1234 from okta/config_unit_tests
Config unit tests
- Loading branch information
Showing
3 changed files
with
156 additions
and
2 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,52 @@ | ||
package okta | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/go-hclog" | ||
) | ||
|
||
func TestConfigLoadAndValidate(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
accessToken string | ||
apiToken string | ||
clientID string | ||
privateKey string | ||
privateKeyID string | ||
scopes []string | ||
expectError bool | ||
}{ | ||
{"access_token = pass", "accessToken", "", "", "", "", nil, false}, | ||
// NOTE: don't test apiToken, it causes a hit to the wire with a "GET | ||
// /api/v1/users/me" and the test tokens are scrubbed for this test | ||
// {"api_token = pass", "", "apiToken", "", "", "", nil, false}, | ||
{"client_id, private_key, scopes = pass", "", "", "clientID", "privateKey", "", []string{"scope1", "scope2"}, false}, | ||
{"client_id, private_key, private_key_id, scopes = pass", "", "", "clientID", "privateKey", "privateKeyID", []string{"scope1", "scope2"}, false}, | ||
} | ||
|
||
for _, test := range tests { | ||
config := Config{ | ||
orgName: "test", | ||
domain: "okta.com", | ||
accessToken: test.accessToken, | ||
apiToken: test.apiToken, | ||
clientID: test.clientID, | ||
privateKey: test.privateKey, | ||
privateKeyId: test.privateKeyID, | ||
scopes: test.scopes, | ||
logLevel: int(hclog.Warn), | ||
} | ||
err := config.loadAndValidate(context.TODO()) | ||
|
||
if test.expectError && err == nil { | ||
t.Errorf("test %q: expected error but received none", test.name) | ||
} | ||
if !test.expectError && err != nil { | ||
t.Errorf("test %q: did not expect error but received error: %+v", test.name, err) | ||
fmt.Println() | ||
} | ||
} | ||
} |
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