-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
510fd60
commit c3e3359
Showing
1 changed file
with
92 additions
and
0 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
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") | ||
} |