mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
3be1d08b87
golint is deprecated. The author of the code no longer supports the codebase. golangci-lint is faster than golint, and is in use by other opa repositories (e.g. Gatekeeper). This commit changes tools.go to reference golangci (so it ends up in vendor) and modifies check-lint to use golangci instead. Breaking API Changes: - plugins/rest/rest.go: Fix typo "AllowInsureTLS" -> "AllowInsecureTLS" - storage/errors.go: Removed unused IndexingNotSupportedErr Signed-off-by: Will Beason <willbeason@google.com>
96 lines
2.1 KiB
Go
96 lines
2.1 KiB
Go
// Copyright 2018 The OPA Authors. All rights reserved.
|
|
// Use of this source code is governed by an Apache2
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package wasm
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/open-policy-agent/opa/ast"
|
|
"github.com/open-policy-agent/opa/internal/planner"
|
|
"github.com/open-policy-agent/opa/internal/wasm/instruction"
|
|
"github.com/open-policy-agent/opa/internal/wasm/module"
|
|
)
|
|
|
|
func TestCompilerHelloWorld(t *testing.T) {
|
|
|
|
policy, err := planner.New().
|
|
WithQueries([]planner.QuerySet{
|
|
{
|
|
Name: "test",
|
|
Queries: []ast.Body{ast.MustParseBody(`input.foo = 1`)},
|
|
},
|
|
}).Plan()
|
|
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
c := New().WithPolicy(policy)
|
|
_, err = c.Compile()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestCompilerBadDataSegment(t *testing.T) {
|
|
|
|
result, err := getLowestFreeDataSegmentOffset(&module.Module{})
|
|
if err != nil || result != 0 {
|
|
t.Fatal("expected zero but got:", result, "err:", err)
|
|
}
|
|
|
|
_, err = getLowestFreeDataSegmentOffset(&module.Module{Data: module.DataSection{
|
|
Segments: []module.DataSegment{
|
|
{
|
|
Offset: module.Expr{
|
|
Instrs: []instruction.Instruction{},
|
|
},
|
|
},
|
|
},
|
|
}})
|
|
if err == nil || err.Error() != "bad data segment offset instructions" {
|
|
t.Fatal("unexpected err:", err)
|
|
}
|
|
|
|
_, err = getLowestFreeDataSegmentOffset(&module.Module{Data: module.DataSection{
|
|
Segments: []module.DataSegment{
|
|
{
|
|
Offset: module.Expr{
|
|
Instrs: []instruction.Instruction{
|
|
instruction.I64Const{Value: 100},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}})
|
|
if err == nil || err.Error() != "bad data segment offset expr" {
|
|
t.Fatal("unexpected err:", err)
|
|
}
|
|
|
|
result, err = getLowestFreeDataSegmentOffset(&module.Module{Data: module.DataSection{
|
|
Segments: []module.DataSegment{
|
|
{
|
|
Init: []byte("foo"),
|
|
Offset: module.Expr{
|
|
Instrs: []instruction.Instruction{
|
|
instruction.I32Const{Value: 106},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
Init: []byte("bar"),
|
|
Offset: module.Expr{
|
|
Instrs: []instruction.Instruction{
|
|
instruction.I32Const{Value: 100},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}})
|
|
if err != nil || result != 109 {
|
|
t.Fatal("expected 106 but got:", result, "err:", err)
|
|
}
|
|
}
|