Skip to content

Commit

Permalink
document view bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fredcarle committed Feb 5, 2025
1 parent 7ade7f3 commit 58bce58
Showing 1 changed file with 98 additions and 7 deletions.
105 changes: 98 additions & 7 deletions tests/integration/view/simple/with_contraints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,60 @@ import (
"testing"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
"github.com/sourcenetwork/immutable"
)

func TestView_SimpleWithSizeConstraint_DoesNotErrorOnSizeViolation(t *testing.T) {
func TestView_SimpleWithSizeConstraint_CacheLessView_DoesNotErrorOnSizeViolation(t *testing.T) {
test := testUtils.TestCase{
SupportedViewTypes: immutable.Some([]testUtils.ViewType{
testUtils.CachelessViewType,
}),
Description: "Simple view with size constraint",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type User {
name: String
pointsList: [Int!]
pointsListInt: [Int!]
pointsListFloat32: [Float32!]
pointsListFloat64: [Float64!]
}
`,
},
testUtils.CreateView{
Query: `
User {
name
pointsList
pointsListInt
pointsListFloat32
pointsListFloat64
}
`,
SDL: `
type UserView @materialized(if: false) {
name: String
pointsList: [Int!] @constraints(size: 2)
pointsListInt: [Int!] @constraints(size: 2)
pointsListFloat32: [Float32!] @constraints(size: 2)
pointsListFloat64: [Float64!] @constraints(size: 2)
}
`,
},
testUtils.CreateDoc{
Doc: `{
"name": "Alice",
"pointsList": [1, 2, 3]
"pointsListInt": [1, 2, 3],
"pointsListFloat32": [1, 2, 3],
"pointsListFloat64": [1, 2, 3]
}`,
},
testUtils.Request{
Request: `
query {
UserView {
name
pointsList
pointsListInt
pointsListFloat32
pointsListFloat64
}
}
`,
Expand All @@ -62,7 +76,84 @@ func TestView_SimpleWithSizeConstraint_DoesNotErrorOnSizeViolation(t *testing.T)
{
"name": "Alice",
// notice the size constraint is not enforced on views
"pointsList": []int64{1, 2, 3},
"pointsListInt": []int64{1, 2, 3},
"pointsListFloat32": []float32{1, 2, 3},
"pointsListFloat64": []float64{1, 2, 3},
},
},
},
},
},
}

testUtils.ExecuteTestCase(t, test)
}

// This test documents a potential bug with the materialized view where the return type for arrays is
// an interface with float64 values instead of the expected int64, float32 or float64 array types
// TODO: https://github.com/sourcenetwork/defradb/issues/3428
func TestView_SimpleWithSizeConstraint_MaterializedView_DoesNotErrorOnSizeViolation(t *testing.T) {
test := testUtils.TestCase{
SupportedViewTypes: immutable.Some([]testUtils.ViewType{
testUtils.MaterializedViewType,
}),
Description: "Simple view with size constraint",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type User {
name: String
pointsListInt: [Int!]
pointsListFloat32: [Float32!]
pointsListFloat64: [Float64!]
}
`,
},
testUtils.CreateView{
Query: `
User {
name
pointsListInt
pointsListFloat32
pointsListFloat64
}
`,
SDL: `
type UserView @materialized(if: false) {
name: String
pointsListInt: [Int!] @constraints(size: 2)
pointsListFloat32: [Float32!] @constraints(size: 2)
pointsListFloat64: [Float64!] @constraints(size: 2)
}
`,
},
testUtils.CreateDoc{
Doc: `{
"name": "Alice",
"pointsListInt": [1, 2, 3],
"pointsListFloat32": [1, 2, 3],
"pointsListFloat64": [1, 2, 3]
}`,
},
testUtils.Request{
Request: `
query {
UserView {
name
pointsListInt
pointsListFloat32
pointsListFloat64
}
}
`,
Results: map[string]any{
"UserView": []map[string]any{
{
"name": "Alice",
// notice the size constraint is not enforced on views
"pointsListInt": []any{float64(1), float64(2), float64(3)},
"pointsListFloat32": []any{float64(1), float64(2), float64(3)},
"pointsListFloat64": []any{float64(1), float64(2), float64(3)},
},
},
},
Expand Down

0 comments on commit 58bce58

Please sign in to comment.