From 450136fb057ca6bc7393a256764e82720020e0fa Mon Sep 17 00:00:00 2001 From: Alex Hung Date: Thu, 18 Apr 2024 15:14:56 -0700 Subject: [PATCH] Add test func for boolean pointer --- path_config_test.go | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/path_config_test.go b/path_config_test.go index 984937d..76c3324 100644 --- a/path_config_test.go +++ b/path_config_test.go @@ -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) { @@ -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{