chore: pkg imported more than once

Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
This commit is contained in:
guoguangwu
2023-07-18 16:37:38 +08:00
committed by Ashutosh Narkar
parent 5cd774edf2
commit 8fa5b02b53
5 changed files with 19 additions and 24 deletions
+1 -2
View File
@@ -19,7 +19,6 @@ import (
"github.com/containerd/containerd/remotes/docker"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras-go/v2"
oraslib "oras.land/oras-go/v2"
"oras.land/oras-go/v2/content/oci"
@@ -384,7 +383,7 @@ func (a *pluginAuthorizer) Authorize(ctx context.Context, req *http.Request) err
return a.authorizer.Authorize(ctx, req)
}
func manifestFromDesc(ctx context.Context, target oras.Target, desc *ocispec.Descriptor) (*ocispec.Manifest, error) {
func manifestFromDesc(ctx context.Context, target oraslib.Target, desc *ocispec.Descriptor) (*ocispec.Manifest, error) {
var manifest ocispec.Manifest
descReader, err := target.Fetch(ctx, *desc)
+1 -2
View File
@@ -14,7 +14,6 @@ import (
"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/internal/wasm/sdk/internal/wasm"
"github.com/open-policy-agent/opa/internal/wasm/sdk/opa/errors"
sdk_errors "github.com/open-policy-agent/opa/internal/wasm/sdk/opa/errors"
"github.com/open-policy-agent/opa/metrics"
"github.com/open-policy-agent/opa/topdown/builtins"
@@ -22,7 +21,7 @@ import (
"github.com/open-policy-agent/opa/topdown/print"
)
var errNotReady = errors.New(errors.NotReadyErr, "")
var errNotReady = sdk_errors.New(sdk_errors.NotReadyErr, "")
// OPA executes WebAssembly compiled Rego policies.
type OPA struct {
+11 -12
View File
@@ -21,7 +21,6 @@ import (
"time"
"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/bundle"
bundleApi "github.com/open-policy-agent/opa/bundle"
"github.com/open-policy-agent/opa/download"
"github.com/open-policy-agent/opa/logging/test"
@@ -403,7 +402,7 @@ func TestStartWithBundlePersistence(t *testing.T) {
initialBundle.Manifest.Init()
var buf bytes.Buffer
if err := bundle.NewWriter(&buf).Write(*initialBundle); err != nil {
if err := bundleApi.NewWriter(&buf).Write(*initialBundle); err != nil {
t.Fatal("unexpected error:", err)
}
@@ -521,7 +520,7 @@ func TestOneShotWithBundlePersistence(t *testing.T) {
expBndl := initialBundle.Copy()
var buf bytes.Buffer
if err := bundle.NewWriter(&buf).Write(*initialBundle); err != nil {
if err := bundleApi.NewWriter(&buf).Write(*initialBundle); err != nil {
t.Fatal("unexpected error:", err)
}
@@ -611,7 +610,7 @@ func TestLoadAndActivateBundleFromDisk(t *testing.T) {
initialBundle.Manifest.Init()
var buf bytes.Buffer
if err := bundle.NewWriter(&buf).Write(*initialBundle); err != nil {
if err := bundleApi.NewWriter(&buf).Write(*initialBundle); err != nil {
t.Fatal("unexpected error:", err)
}
@@ -672,7 +671,7 @@ func TestLoadAndActivateSignedBundleFromDisk(t *testing.T) {
ctx := context.Background()
disco.bundlePersistPath = filepath.Join(dir, ".opa")
disco.config.Signing = bundle.NewVerificationConfig(map[string]*bundle.KeyConfig{"foo": {Key: "secret", Algorithm: "HS256"}}, "foo", "", nil)
disco.config.Signing = bundleApi.NewVerificationConfig(map[string]*bundleApi.KeyConfig{"foo": {Key: "secret", Algorithm: "HS256"}}, "foo", "", nil)
ensurePluginState(t, disco, plugins.StateNotReady)
@@ -702,12 +701,12 @@ func TestLoadAndActivateSignedBundleFromDisk(t *testing.T) {
initialBundle.Manifest.Init()
if err := initialBundle.GenerateSignature(bundle.NewSigningConfig("secret", "HS256", ""), "foo", false); err != nil {
if err := initialBundle.GenerateSignature(bundleApi.NewSigningConfig("secret", "HS256", ""), "foo", false); err != nil {
t.Fatal("Unexpected error:", err)
}
var buf bytes.Buffer
if err := bundle.NewWriter(&buf).Write(*initialBundle); err != nil {
if err := bundleApi.NewWriter(&buf).Write(*initialBundle); err != nil {
t.Fatal("unexpected error:", err)
}
@@ -799,7 +798,7 @@ func TestLoadAndActivateBundleFromDiskMaxAttempts(t *testing.T) {
initialBundle.Manifest.Init()
var buf bytes.Buffer
if err := bundle.NewWriter(&buf).Write(*initialBundle); err != nil {
if err := bundleApi.NewWriter(&buf).Write(*initialBundle); err != nil {
t.Fatal("unexpected error:", err)
}
@@ -859,7 +858,7 @@ func TestSaveBundleToDiskNew(t *testing.T) {
initialBundle.Manifest.Init()
var buf bytes.Buffer
if err := bundle.NewWriter(&buf).Write(*initialBundle); err != nil {
if err := bundleApi.NewWriter(&buf).Write(*initialBundle); err != nil {
t.Fatal("unexpected error:", err)
}
@@ -917,7 +916,7 @@ func TestSaveBundleToDiskNewConfiguredPersistDir(t *testing.T) {
initialBundle.Manifest.Init()
var buf bytes.Buffer
if err := bundle.NewWriter(&buf).Write(*initialBundle); err != nil {
if err := bundleApi.NewWriter(&buf).Write(*initialBundle); err != nil {
t.Fatal("unexpected error:", err)
}
@@ -975,7 +974,7 @@ func TestReconfigure(t *testing.T) {
if disco.status == nil {
t.Fatal("Expected to find status, found nil")
} else if disco.status.Type != bundle.SnapshotBundleType {
} else if disco.status.Type != bundleApi.SnapshotBundleType {
t.Fatalf("expected snapshot bundle but got %v", disco.status.Type)
} else if disco.status.Size != snapshotBundleSize {
t.Fatalf("expected snapshot bundle size %d but got %d", snapshotBundleSize, disco.status.Size)
@@ -1026,7 +1025,7 @@ func TestReconfigure(t *testing.T) {
if disco.status == nil {
t.Fatal("Expected to find status, found nil")
} else if disco.status.Type != bundle.SnapshotBundleType {
} else if disco.status.Type != bundleApi.SnapshotBundleType {
t.Fatalf("expected snapshot bundle but got %v", disco.status.Type)
}
+5 -6
View File
@@ -16,7 +16,6 @@ import (
"time"
"github.com/prometheus/client_golang/prometheus"
prom "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/open-policy-agent/opa/metrics"
@@ -978,7 +977,7 @@ func newTestFixture(t *testing.T, m metrics.Metrics, options ...testPluginCustom
]}`, ts.server.URL))
registerMock := &prometheusRegisterMock{
Collectors: map[prom.Collector]bool{},
Collectors: map[prometheus.Collector]bool{},
}
manager, err := plugins.New(managerConfig, "test-instance-id", inmem.New(), plugins.WithPrometheusRegister(registerMock))
if err != nil {
@@ -1105,21 +1104,21 @@ func TestPluginCustomBackend(t *testing.T) {
}
type prometheusRegisterMock struct {
Collectors map[prom.Collector]bool
Collectors map[prometheus.Collector]bool
}
func (p prometheusRegisterMock) Register(collector prom.Collector) error {
func (p prometheusRegisterMock) Register(collector prometheus.Collector) error {
p.Collectors[collector] = true
return nil
}
func (p prometheusRegisterMock) MustRegister(collector ...prom.Collector) {
func (p prometheusRegisterMock) MustRegister(collector ...prometheus.Collector) {
for _, c := range collector {
p.Collectors[c] = true
}
}
func (p prometheusRegisterMock) Unregister(collector prom.Collector) bool {
func (p prometheusRegisterMock) Unregister(collector prometheus.Collector) bool {
delete(p.Collectors, collector)
return true
}
@@ -12,7 +12,6 @@ import (
"strings"
"testing"
"github.com/open-policy-agent/opa/test/authz"
testAuthz "github.com/open-policy-agent/opa/test/authz"
"github.com/open-policy-agent/opa/test/e2e"
"github.com/open-policy-agent/opa/util"
@@ -83,7 +82,7 @@ func runAuthzBenchmark(b *testing.B, mode testAuthz.InputMode, numPaths int) {
b.Fatal(err)
}
queryPath := strings.Replace(authz.AllowQuery, ".", "/", -1)
queryPath := strings.Replace(testAuthz.AllowQuery, ".", "/", -1)
url := testRuntime.URL() + "/v1/" + queryPath
input, expected := testAuthz.GenerateInput(profile, mode)