Skip to content

Commit

Permalink
Add test func for boolean pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhung committed Apr 18, 2024
1 parent 0ae3c54 commit 450136f
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion path_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (e *accTestEnv) PathConfigUpdateExpiringTokens(t *testing.T) {
}

func (e *accTestEnv) PathConfigForceRevocableTokens(t *testing.T) {
e.pathConfigUpdateBooleanField(t, "force_revocable")
e.pathConfigUpdateBooleanPtrField(t, "force_revocable")
}

func (e *accTestEnv) PathConfigUpdateBypassArtifactoryTLSVerification(t *testing.T) {
Expand Down Expand Up @@ -91,6 +91,42 @@ func (e *accTestEnv) pathConfigUpdateBooleanField(t *testing.T, fieldName string
assert.Nil(t, err)
}

func (e *accTestEnv) pathConfigUpdateBooleanPtrField(t *testing.T, fieldName string) {
// Boolean
e.UpdateConfigAdmin(t, testData{
fieldName: true,
})
data := e.ReadConfigAdmin(t)
assert.Equal(t, true, *data[fieldName].(*bool))

e.UpdateConfigAdmin(t, testData{
fieldName: false,
})
data = e.ReadConfigAdmin(t)
assert.Equal(t, false, *data[fieldName].(*bool))

// String
e.UpdateConfigAdmin(t, testData{
fieldName: "true",
})
data = e.ReadConfigAdmin(t)
assert.Equal(t, true, *data[fieldName].(*bool))

e.UpdateConfigAdmin(t, testData{
fieldName: "false",
})
data = e.ReadConfigAdmin(t)
assert.Equal(t, false, *data[fieldName].(*bool))

// Fail Tests
resp, err := e.update(configAdminPath, testData{
fieldName: "Sure, why not",
})
assert.NotNil(t, resp)
assert.Regexp(t, regexp.MustCompile("Field validation failed: error converting input .* strconv.ParseBool: parsing .*: invalid syntax"), resp.Data["error"])
assert.Nil(t, err)
}

func (e *accTestEnv) PathConfigUpdateUsernameTemplate(t *testing.T) {
usernameTemplate := "v_{{.DisplayName}}_{{.RoleName}}_{{random 10}}_{{unix_time}}"
e.UpdateConfigAdmin(t, testData{
Expand Down

0 comments on commit 450136f

Please sign in to comment.