forked from cloudquery/cq-provider-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added resource set validation cloudquery#7
Added TableValidation to enforce column/table name longer than 63 char cloudquery#9
- Loading branch information
1 parent
a143680
commit 7ca9ac8
Showing
5 changed files
with
116 additions
and
3 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
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,51 @@ | ||
package provider | ||
|
||
import ( | ||
"github.com/cloudquery/cq-provider-sdk/logging" | ||
"github.com/cloudquery/cq-provider-sdk/provider/schema" | ||
"github.com/hashicorp/go-hclog" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
var testTable = schema.Table{ | ||
Name: "test_table_validator", | ||
Columns: []schema.Column{ | ||
{ | ||
Name: "zero_bool", | ||
Type: schema.TypeBool, | ||
}, | ||
{ | ||
Name: "zero_int", | ||
Type: schema.TypeBigInt, | ||
}, | ||
{ | ||
Name: "not_zero_bool", | ||
Type: schema.TypeBool, | ||
}, | ||
}, | ||
} | ||
|
||
func TestMigratorTableValidators(t *testing.T) { | ||
logger := logging.New(&hclog.LoggerOptions{ | ||
Level: hclog.Trace, | ||
JSONFormat: true, | ||
}) | ||
m := NewMigrator(nil, logger) | ||
|
||
// table has passed all validators | ||
err := m.ValidateTable(&testTable) | ||
assert.Nil(t, err) | ||
|
||
// table name is too long | ||
tableWithLongName := testTable | ||
tableWithLongName.Name = "WithLongNametableWithLongNametableWithLongNametableWithLongNamet" | ||
err = m.ValidateTable(&tableWithLongName) | ||
assert.Error(t, err) | ||
|
||
// column name is too long | ||
tableWithLongColumnName := testTable | ||
tableWithLongName.Columns[0].Name = "tableWithLongColumnNametableWithLongColumnNametableWithLongColumnName" | ||
err = m.ValidateTable(&tableWithLongColumnName) | ||
assert.Error(t, err) | ||
} |
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
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
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