Skip to content

Commit

Permalink
SNOW-723810: Add coverage for RestRequest (#784)
Browse files Browse the repository at this point in the history
### Description
Regarding issue 113

The PR adds tests for RestRequest to increase code coverage

### Checklist
- [x] Code compiles correctly
- [x] Code is formatted according to [Coding
Conventions](../CodingConventions.md)
- [x] Created tests which fail without the change (if possible)
- [x] All tests passing (`dotnet test`)
- [x] Extended the README / documentation, if necessary
- [x] Provide JIRA issue id (if possible) or GitHub issue id in PR name
  • Loading branch information
sfc-gh-ext-simba-lf authored Oct 18, 2023
1 parent 7ff70e4 commit e954f95
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
57 changes: 57 additions & 0 deletions Snowflake.Data.Tests/UnitTests/SFOktaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,62 @@ public void TestWrongPostbackUrl()
Assert.AreEqual(SFError.IDP_SAML_POSTBACK_INVALID.GetAttribute<SFErrorAttr>().errorCode, e.ErrorCode);
}
}

[Test]
public void TestLoginRequestToString()
{
// Arrange
string expectedOktaAccount = "mockOktaAccount";
string expectedOktaUser = "mockOktaUser";
string expectedOktaUrl = "mockOktaUrl";

LoginRequestClientEnv loginRequestClientEnv = new LoginRequestClientEnv();

// Act
LoginRequest loginRequest = new LoginRequest()
{
data = new LoginRequestData()
{
loginName = expectedOktaUser,
accountName = expectedOktaAccount,
clientAppVersion = SFEnvironment.DriverVersion,
clientEnv = loginRequestClientEnv,
Authenticator = expectedOktaUrl,
}
};

// Assert
Assert.AreEqual($"LoginRequest {{data: LoginRequestData {{ClientAppVersion: {SFEnvironment.DriverVersion},\n " +
$"AccountName: {expectedOktaAccount},\n " +
$"loginName: {expectedOktaUser},\n " +
$"ClientEnv: {{ " +
$"APPLICATION: , " +
$"OS_VERSION: , " +
$"NET_RUNTIME: , " +
$"NET_VERSION: , " +
$"INSECURE_MODE: }},\n " +
$"authenticator: {expectedOktaUrl} }} }}",
loginRequest.ToString());
}

[Test]
public void TestAuthenticatorRequestToString()
{
// Arrange
string expectedOktaAccount = "mockOktaAccount";

// Act
AuthenticatorRequest authenticatorRequest = new AuthenticatorRequest()
{
Data = new AuthenticatorRequestData()
{
AccountName = expectedOktaAccount,
}
};

// Assert
Assert.AreEqual($"AuthenticatorRequest {{data: AuthenticatorRequestData {{ACCOUNT_NAME: {expectedOktaAccount} }} }}",
authenticatorRequest.ToString());
}
}
}
2 changes: 1 addition & 1 deletion Snowflake.Data/Core/RestRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class AuthenticatorRequestData

public override string ToString()
{
return String.Format("AuthenticatorRequestData {{ACCOUNT_NANM: {0} }}",
return String.Format("AuthenticatorRequestData {{ACCOUNT_NAME: {0} }}",
AccountName.ToString());
}
}
Expand Down

0 comments on commit e954f95

Please sign in to comment.