Skip to content

Commit

Permalink
fix lint issues
Browse files Browse the repository at this point in the history
Signed-off-by: pxp928 <parth.psu@gmail.com>
  • Loading branch information
pxp928 committed Feb 16, 2024
1 parent 0ed0f7c commit b6047e5
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 250 deletions.
4 changes: 0 additions & 4 deletions internal/testing/cmd/pubsub_test/cmd/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
"syscall"
"time"

jsoniter "github.com/json-iterator/go"

"github.com/guacsec/guac/pkg/blob"
"github.com/guacsec/guac/pkg/emitter"
"github.com/guacsec/guac/pkg/handler/collector"
Expand All @@ -37,8 +35,6 @@ import (
"github.com/spf13/viper"
)

var json = jsoniter.ConfigCompatibleWithStandardLibrary

type options struct {
dbAddr string
user string
Expand Down
73 changes: 0 additions & 73 deletions pkg/assembler/backends/arangodb/search_test.go

This file was deleted.

28 changes: 0 additions & 28 deletions pkg/assembler/backends/ent/backend/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,21 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build integration

package backend

import (
"reflect"
"strconv"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/guacsec/guac/pkg/assembler/graphql/model"
"github.com/guacsec/guac/pkg/assembler/helpers"
)

func ptr[T any](s T) *T {
return &s
}

var ignoreID = cmp.FilterPath(func(p cmp.Path) bool {
return strings.Compare(".ID", p[len(p)-1].String()) == 0
}, cmp.Ignore())

var ignoreEmptySlices = cmp.FilterValues(func(x, y interface{}) bool {
xv, yv := reflect.ValueOf(x), reflect.ValueOf(y)
if xv.Kind() == reflect.Slice && yv.Kind() == reflect.Slice {
return xv.Len() == 0 && yv.Len() == 0
}
return false
}, cmp.Ignore())

var IngestPredicatesCmpOpts = []cmp.Option{
ignoreID,
cmpopts.EquateEmpty(),
Expand Down Expand Up @@ -133,14 +116,3 @@ func certifyLegalLess(e1, e2 *model.CertifyLegal) bool {
}
return false
}

func rewriteID(t *testing.T, queryID *string, realIDs []string) {
idIdx, err := strconv.Atoi(*queryID)
if err == nil {
if idIdx >= len(realIDs) {
t.Logf("ID index out of range, want: %d, got: %d. So ID %d will be directly used to query.", len(realIDs), idIdx, idIdx)
} else {
*queryID = realIDs[idIdx]
}
}
}
91 changes: 41 additions & 50 deletions pkg/assembler/backends/ent/backend/query_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@

package backend

import (
"context"

"github.com/guacsec/guac/pkg/assembler/backends/ent"
"github.com/guacsec/guac/pkg/assembler/backends/ent/packagename"
"github.com/guacsec/guac/pkg/assembler/backends/ent/packagenamespace"
"github.com/guacsec/guac/pkg/assembler/backends/ent/packageversion"
)

//func getArtifact(ctx context.Context, client *ent.Client, artin *model.ArtifactInputSpec) (*ent.Artifact, error) {
// return client.Artifact.Query().
// Where(artifact.Algorithm(artin.Algorithm), artifact.Digest(artin.Digest)).
Expand All @@ -34,52 +25,52 @@ import (
// rebuild the full top level tree object with just the nested objects that are
// part of the path to that node

func pkgTreeFromVersion(ctx context.Context, pv *ent.PackageVersion) (*ent.PackageType, error) {
// pv.QueryName().QueryNamespace().QueryPackage().Query
// func pkgTreeFromVersion(ctx context.Context, pv *ent.PackageVersion) (*ent.PackageType, error) {
// // pv.QueryName().QueryNamespace().QueryPackage().Query

// eagerLoadedVersion, err := pv.
// QueryName().
// WithNamespace().
// QueryNamespace().
// WithPackage().
// QueryPackage().
// WithNamespaces(func(q *ent.PackageNamespaceQuery) {
// q.WithNames(func(q *ent.PackageNameQuery) {
// q.WithVersions()
// })
// }).
// Only(ctx)
// if err != nil {
// return nil, err
// }
// // eagerLoadedVersion, err := pv.
// // QueryName().
// // WithNamespace().
// // QueryNamespace().
// // WithPackage().
// // QueryPackage().
// // WithNamespaces(func(q *ent.PackageNamespaceQuery) {
// // q.WithNames(func(q *ent.PackageNameQuery) {
// // q.WithVersions()
// // })
// // }).
// // Only(ctx)
// // if err != nil {
// // return nil, err
// // }

// return eagerLoadedVersion, nil
// // return eagerLoadedVersion, nil

n, err := pv.QueryName().Only(ctx)
if err != nil {
return nil, err
}
ns, err := n.QueryNamespace().Only(ctx)
if err != nil {
return nil, err
}
// n, err := pv.QueryName().Only(ctx)
// if err != nil {
// return nil, err
// }
// ns, err := n.QueryNamespace().Only(ctx)
// if err != nil {
// return nil, err
// }

q := ns.QueryPackage()
buildPackageTreeQuery(q, ns.Namespace, n.Name, pv)
return q.Only(ctx)
}
// q := ns.QueryPackage()
// buildPackageTreeQuery(q, ns.Namespace, n.Name, pv)
// return q.Only(ctx)
// }

func buildPackageTreeQuery(q *ent.PackageTypeQuery, ns, packageName string, pv *ent.PackageVersion) {
q.WithNamespaces(func(q *ent.PackageNamespaceQuery) {
q.Where(packagenamespace.Namespace(ns))
q.WithNames(func(q *ent.PackageNameQuery) {
q.Where(packagename.Name(packageName))
q.WithVersions(func(q *ent.PackageVersionQuery) {
q.Where(packageversion.Hash(hashPackageVersion(pv.Version, pv.Subpath, pv.Qualifiers)))
})
})
})
}
// func buildPackageTreeQuery(q *ent.PackageTypeQuery, ns, packageName string, pv *ent.PackageVersion) {
// q.WithNamespaces(func(q *ent.PackageNamespaceQuery) {
// q.Where(packagenamespace.Namespace(ns))
// q.WithNames(func(q *ent.PackageNameQuery) {
// q.Where(packagename.Name(packageName))
// q.WithVersions(func(q *ent.PackageVersionQuery) {
// q.Where(packageversion.Hash(hashPackageVersion(pv.Version, pv.Subpath, pv.Qualifiers)))
// })
// })
// })
// }

//func pkgTreeFromName(ctx context.Context, pn *ent.PackageName) (*ent.PackageType, error) {
// ns, err := pn.QueryNamespace().Only(ctx)
Expand Down
80 changes: 0 additions & 80 deletions pkg/assembler/backends/ent/backend/search_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions pkg/assembler/backends/keyvalue/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,13 @@ func (c *demoClient) returnFoundArtifact(ctx context.Context, artIDorInput *mode
if artIDorInput.ArtifactID != nil {
foundArtStruct, err := byIDkv[*artStruct](ctx, *artIDorInput.ArtifactID, c)
if err != nil {
return nil, gqlerror.Errorf("failed to return artStruct node by ID with error: %w", err)
return nil, gqlerror.Errorf("failed to return artStruct node by ID with error: %v", err)
}
return foundArtStruct, nil
} else {
foundArtStruct, err := c.artifactByInput(ctx, artIDorInput.ArtifactInput)
if err != nil {
return nil, gqlerror.Errorf("failed to artifactByInput with error: %w", err)
return nil, gqlerror.Errorf("failed to artifactByInput with error: %v", err)
}
return foundArtStruct, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/assembler/backends/keyvalue/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ func (c *demoClient) returnFoundBuilder(ctx context.Context, buildIDorInput *mod
if buildIDorInput.BuilderID != nil {
builderStruct, err := byIDkv[*builderStruct](ctx, *buildIDorInput.BuilderID, c)
if err != nil {
return nil, gqlerror.Errorf("failed to return builderStruct node by ID with error: %w", err)
return nil, gqlerror.Errorf("failed to return builderStruct node by ID with error: %v", err)
}
return builderStruct, nil
} else {
builderStruct, err := c.builderByInput(ctx, buildIDorInput.BuilderInput)
if err != nil {
return nil, gqlerror.Errorf("failed to builderByInput with error: %w", err)
return nil, gqlerror.Errorf("failed to builderByInput with error: %v", err)
}
return builderStruct, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/assembler/backends/keyvalue/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ func (c *demoClient) returnFoundLicense(ctx context.Context, licenseIDorInput *m
if licenseIDorInput.LicenseID != nil {
licStruct, err := byIDkv[*licStruct](ctx, *licenseIDorInput.LicenseID, c)
if err != nil {
return nil, gqlerror.Errorf("failed to return licStruct node by ID with error: %w", err)
return nil, gqlerror.Errorf("failed to return licStruct node by ID with error: %v", err)
}
return licStruct, nil
} else {
licStruct, err := c.licenseByInput(ctx, licenseIDorInput.LicenseInput)
if err != nil {
return nil, gqlerror.Errorf("failed to licenseByInput with error: %w", err)
return nil, gqlerror.Errorf("failed to licenseByInput with error: %v", err)
}
return licStruct, nil
}
Expand Down
Loading

0 comments on commit b6047e5

Please sign in to comment.