Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardfeng-db committed Jan 31, 2024
1 parent 510fd60 commit c3e3359
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions common/customizable_schema_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package common

import (
"testing"

"github.com/stretchr/testify/assert"
)

var testCustomizableSchemaScm = StructToSchema(testStruct{}, nil)

func TestCustomizableSchemaSetOptional(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetOptional()
assert.Truef(t, testCustomizableSchemaScm["non_optional"].Optional, "optional should be overriden to true in field: non-optional")
}

func TestCustomizableSchemaSetRequired(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "float").SetRequired()
assert.Truef(t, testCustomizableSchemaScm["float"].Required, "required should be overriden to true in field: float")
}

func TestCustomizableSchemaSetReadOnly(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "bool").SetReadOnly()
assert.Truef(t, testCustomizableSchemaScm["bool"].Computed, "computed should be overriden to true in field: bool")
assert.Falsef(t, testCustomizableSchemaScm["bool"].Optional, "optional should be overriden to false in field: bool")
assert.Falsef(t, testCustomizableSchemaScm["bool"].Required, "required should be overriden to false in field: bool")
assert.Truef(t, testCustomizableSchemaScm["bool"].MaxItems == 0, "maxItems should be overriden to 0 in field: bool")
}

func TestCustomizableSchemaSetComputed(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "string").SetComputed()
assert.Truef(t, testCustomizableSchemaScm["string"].Computed, "computed should be overriden to true in field: string")
}

func TestCustomizableSchemaSetDefault(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetDefault("abc")
assert.Truef(t, testCustomizableSchemaScm["non_optional"].Default == "abc", "default should be overriden to abc in field: non_optional")
}

func TestCustomizableSchemaSetSuppressDiff(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetDefault("abc")
assert.Truef(t, testCustomizableSchemaScm["non_optional"].Default == "abc", "default should be overriden to abc in field: non_optional")
}

func TestCustomizableSchemaSetCustomSuppressDiff(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetDefault("abc")
assert.Truef(t, testCustomizableSchemaScm["non_optional"].Default == "abc", "default should be overriden to abc in field: non_optional")
}

func TestCustomizableSchemaSetSensitive(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetDefault("abc")
assert.Truef(t, testCustomizableSchemaScm["non_optional"].Default == "abc", "default should be overriden to abc in field: non_optional")
}

func TestCustomizableSchemaSetForceNew(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetDefault("abc")
assert.Truef(t, testCustomizableSchemaScm["non_optional"].Default == "abc", "default should be overriden to abc in field: non_optional")
}

func TestCustomizableSchemaSetMaxItems(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetDefault("abc")
assert.Truef(t, testCustomizableSchemaScm["non_optional"].Default == "abc", "default should be overriden to abc in field: non_optional")
}

func TestCustomizableSchemaSetMinItems(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetDefault("abc")
assert.Truef(t, testCustomizableSchemaScm["non_optional"].Default == "abc", "default should be overriden to abc in field: non_optional")
}

func TestCustomizableSchemaSetConflictsWith(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetDefault("abc")
assert.Truef(t, testCustomizableSchemaScm["non_optional"].Default == "abc", "default should be overriden to abc in field: non_optional")
}

func TestCustomizableSchemaSetDeprecated(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetDefault("abc")
assert.Truef(t, testCustomizableSchemaScm["non_optional"].Default == "abc", "default should be overriden to abc in field: non_optional")
}

func TestCustomizableSchemaSetValidateFunc(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetDefault("abc")
assert.Truef(t, testCustomizableSchemaScm["non_optional"].Default == "abc", "default should be overriden to abc in field: non_optional")
}

func TestCustomizableSchemaSetValidateDiagFunc(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetDefault("abc")
assert.Truef(t, testCustomizableSchemaScm["non_optional"].Default == "abc", "default should be overriden to abc in field: non_optional")
}

func TestCustomizableSchemaAddNewField(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetDefault("abc")
assert.Truef(t, testCustomizableSchemaScm["non_optional"].Default == "abc", "default should be overriden to abc in field: non_optional")
}

0 comments on commit c3e3359

Please sign in to comment.