Skip to content

Commit

Permalink
Use JSON for plan tests (#11430) (#11432)
Browse files Browse the repository at this point in the history
* Use JSON for plan tests

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>

* move vschemas into single directory

Signed-off-by: Andres Taylor <andres@planetscale.com>

* indentation

Signed-off-by: Andres Taylor <andres@planetscale.com>

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Co-authored-by: Andres Taylor <andres@planetscale.com>

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Co-authored-by: FlorentP <35779988+frouioui@users.noreply.github.com>
  • Loading branch information
systay and frouioui authored Oct 10, 2022
1 parent 3ec636f commit 8ef3ad0
Show file tree
Hide file tree
Showing 92 changed files with 51,651 additions and 51,927 deletions.
12 changes: 11 additions & 1 deletion go/vt/vtgate/engine/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package engine

import (
"bytes"
"encoding/json"
"sync/atomic"
"time"
Expand Down Expand Up @@ -98,5 +99,14 @@ func (p *Plan) MarshalJSON() ([]byte, error) {
Errors: atomic.LoadUint64(&p.Errors),
TablesUsed: p.TablesUsed,
}
return json.Marshal(marshalPlan)

b := new(bytes.Buffer)
enc := json.NewEncoder(b)
enc.SetEscapeHTML(false)
err := enc.Encode(marshalPlan)
if err != nil {
return nil, err
}

return b.Bytes(), nil
}
11 changes: 5 additions & 6 deletions go/vt/vtgate/engine/plan_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,11 @@ func addMap(input map[string]any, buf *bytes.Buffer) error {

func marshalAdd(prepend string, buf *bytes.Buffer, name string, obj any) error {
buf.WriteString(prepend + `"` + name + `":`)
b, err := json.Marshal(obj)
if err != nil {
return err
}
buf.Write(b)
return nil

enc := json.NewEncoder(buf)
enc.SetEscapeHTML(false)

return enc.Encode(obj)
}

// PrimitiveToPlanDescription transforms a primitive tree into a corresponding PlanDescription tree
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/collations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type collationTestCase struct {

func (tc *collationTestCase) run(t *testing.T) {
vschemaWrapper := &vschemaWrapper{
v: loadSchema(t, "schema_test.json", false),
v: loadSchema(t, "vschemas/schema.json", false),
sysVarEnabled: true,
version: Gen4,
}
Expand Down
Loading

0 comments on commit 8ef3ad0

Please sign in to comment.