Skip to content

Commit

Permalink
test: get schema type from folder example (#371)
Browse files Browse the repository at this point in the history
* test: get schema type from folder example

Signed-off-by: peefy <[email protected]>

* test: get schema type from folder example

Signed-off-by: peefy <[email protected]>

---------

Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy authored Aug 19, 2024
1 parent 1460c5c commit 5664cd0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions kcl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/google/go-cmp/cmp"

kcl "kcl-lang.io/kcl-go"
api "kcl-lang.io/kcl-go/pkg/kcl"
"kcl-lang.io/kcl-go/pkg/spec/gpyrpc"
)

Expand Down Expand Up @@ -432,6 +433,22 @@ func TestGetSchemaTypeMapping(t *testing.T) {
},
}, result)
}

func TestGetSchemaTypeFromFolder(t *testing.T) {
result, err := api.GetFullSchemaTypeMapping([]string{"testdata/get_schema_type"}, "")
if err != nil {
t.Fatal(err)
}
assert2.Equal(t, result["Base"].SchemaName, "Base")
assert2.Equal(t, len(result["Base"].Properties), 1)
assert2.Equal(t, result["Base"].Properties["name"].Type, "str")
assert2.Equal(t, result["Schema"].SchemaName, "Schema")
assert2.Equal(t, result["Schema"].BaseSchema.SchemaName, "Base")
assert2.Equal(t, len(result["Schema"].Properties), 2)
assert2.Equal(t, result["Schema"].Properties["name"].Type, "str")
assert2.Equal(t, result["Schema"].Properties["info"].Type, "str")
}

func TestListUpStreamFiles(t *testing.T) {
files, err := kcl.ListUpStreamFiles("./testdata/", &kcl.ListDepsOptions{Files: []string{"main.k", "app0/before/base.k", "app0/main.k"}})
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions testdata/get_schema_type/base.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema Base:
name: str
2 changes: 2 additions & 0 deletions testdata/get_schema_type/schema.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema Schema(Base):
info?: str

0 comments on commit 5664cd0

Please sign in to comment.