Skip to content

Commit

Permalink
Update packages for slices import (guacsec#1356)
Browse files Browse the repository at this point in the history
- Replace `golang.org/x/exp/slices` with `slices` import

Signed-off-by: naveensrinivasan <[email protected]>
  • Loading branch information
naveensrinivasan authored Oct 5, 2023
1 parent a9dc7af commit a3299ca
Show file tree
Hide file tree
Showing 38 changed files with 484 additions and 431 deletions.
7 changes: 3 additions & 4 deletions cmd/guacgql/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@ import (
"net/http"
"os"
"os/signal"
"slices"
"syscall"
"time"

"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/handler/debug"
"github.com/99designs/gqlgen/graphql/playground"
"github.com/spf13/cobra"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"

"github.com/guacsec/guac/pkg/assembler/backends"
"github.com/guacsec/guac/pkg/assembler/backends/arangodb"
_ "github.com/guacsec/guac/pkg/assembler/backends/inmem"
Expand All @@ -39,6 +36,8 @@ import (
"github.com/guacsec/guac/pkg/assembler/graphql/generated"
"github.com/guacsec/guac/pkg/assembler/graphql/resolvers"
"github.com/guacsec/guac/pkg/logging"
"github.com/spf13/cobra"
"golang.org/x/exp/maps"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/assembler/backends/arangodb/artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ package arangodb

import (
"context"
"slices"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/guacsec/guac/internal/testing/ptrfrom"
"github.com/guacsec/guac/pkg/assembler/graphql/model"
"golang.org/x/exp/slices"
)

// TODO (pxp928): add tests back in when implemented
Expand Down
8 changes: 5 additions & 3 deletions pkg/assembler/backends/arangodb/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ package arangodb

import (
"context"
"slices"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/guacsec/guac/internal/testing/ptrfrom"
"github.com/guacsec/guac/pkg/assembler/graphql/model"
"golang.org/x/exp/slices"
)

// TODO (pxp928): add tests back in when implemented
Expand Down Expand Up @@ -144,14 +144,16 @@ func Test_IngestBuilders(t *testing.T) {
},
{
URI: "https://tekton.dev/chains/v2",
}},
},
},
want: []*model.Builder{
{
URI: "https://github.com/CreateFork/HubHostedActions@v1",
},
{
URI: "https://tekton.dev/chains/v2",
}},
},
},
wantErr: false,
}}

Expand Down
2 changes: 1 addition & 1 deletion pkg/assembler/backends/arangodb/hashEqual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ package arangodb

import (
"context"
"slices"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/guacsec/guac/internal/testing/ptrfrom"
"github.com/guacsec/guac/internal/testing/testdata"
"github.com/guacsec/guac/pkg/assembler/graphql/model"
"golang.org/x/exp/slices"
)

func TestHashEqual(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/assembler/backends/arangodb/pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ package arangodb

import (
"context"
"slices"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/guacsec/guac/internal/testing/ptrfrom"
"github.com/guacsec/guac/internal/testing/testdata"
"github.com/guacsec/guac/pkg/assembler/graphql/model"
"golang.org/x/exp/slices"
)

// func Test_pkgNamespaceStruct_Neighbors(t *testing.T) {
Expand Down
8 changes: 5 additions & 3 deletions pkg/assembler/backends/arangodb/src_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ package arangodb

import (
"context"
"slices"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/guacsec/guac/internal/testing/ptrfrom"
"github.com/guacsec/guac/internal/testing/testdata"
"github.com/guacsec/guac/pkg/assembler/graphql/model"
"golang.org/x/exp/slices"
)

func lessSource(a, b *model.Source) int {
Expand Down Expand Up @@ -215,7 +215,8 @@ func Test_SourceTypes(t *testing.T) {
}, {
Type: "svn",
Namespaces: []*model.SourceNamespace{},
}},
},
},
wantErr: false,
}, {
name: "bobsrepo with commit, type search",
Expand Down Expand Up @@ -321,7 +322,8 @@ func Test_SourceNamespaces(t *testing.T) {
Namespace: "github.com/bob",
Names: []*model.SourceName{},
}},
}},
},
},
wantErr: false,
}, {
name: "bobsrepo with commit, type search",
Expand Down
3 changes: 1 addition & 2 deletions pkg/assembler/backends/arangodb/vulnerability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ package arangodb

import (
"context"
"slices"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/guacsec/guac/internal/testing/ptrfrom"
"github.com/guacsec/guac/internal/testing/testdata"
"github.com/guacsec/guac/pkg/assembler/graphql/model"
"golang.org/x/exp/slices"
)

func lessCve(a, b *model.Vulnerability) int {
Expand Down Expand Up @@ -419,7 +419,6 @@ func TestIngestVulnerabilities(t *testing.T) {
name: "Multiple",
ingests: []*model.VulnerabilityInputSpec{testdata.C1, testdata.O1, testdata.G1},
exp: []*model.Vulnerability{

{
Type: "osv",
VulnerabilityIDs: []*model.VulnerabilityID{testdata.O1out},
Expand Down
2 changes: 1 addition & 1 deletion pkg/assembler/backends/ent/backend/hashequal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
package backend

import (
"slices"
"strconv"
"strings"

"github.com/google/go-cmp/cmp"
"github.com/guacsec/guac/internal/testing/ptrfrom"
"github.com/guacsec/guac/pkg/assembler/graphql/model"
"golang.org/x/exp/slices"
)

func (s *Suite) TestHashEqual() {
Expand Down
8 changes: 7 additions & 1 deletion pkg/assembler/backends/ent/backend/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,40 @@
package backend

import (
"slices"
"strconv"
"strings"

"github.com/google/go-cmp/cmp"
"github.com/guacsec/guac/internal/testing/ptrfrom"
"github.com/guacsec/guac/pkg/assembler/graphql/model"
"golang.org/x/exp/slices"
)

var l1 = &model.LicenseInputSpec{
Name: "BSD-3-Clause",
ListVersion: ptrfrom.String("3.21 2023-06-18"),
}

var l1out = &model.License{
Name: "BSD-3-Clause",
ListVersion: ptrfrom.String("3.21 2023-06-18"),
}

var l2 = &model.LicenseInputSpec{
Name: "GPL-2.0-or-later",
ListVersion: ptrfrom.String("3.21 2023-06-18"),
}

var l2out = &model.License{
Name: "GPL-2.0-or-later",
ListVersion: ptrfrom.String("3.21 2023-06-18"),
}

var l3 = &model.LicenseInputSpec{
Name: "MPL-2.0",
ListVersion: ptrfrom.String("1.23 2020"),
}

var l3out = &model.License{
Name: "MPL-2.0",
ListVersion: ptrfrom.String("1.23 2020"),
Expand All @@ -64,6 +69,7 @@ var l4 = &model.LicenseInputSpec{
Name: "LicenseRef-d58b4101",
Inline: &inlineLicense,
}

var l4out = &model.License{
Name: "LicenseRef-d58b4101",
Inline: &inlineLicense,
Expand Down
3 changes: 1 addition & 2 deletions pkg/assembler/backends/ent/backend/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"crypto/sha1"
stdsql "database/sql"
"fmt"
"slices"
"sort"

"entgo.io/ent/dialect/sql"
Expand All @@ -33,7 +34,6 @@ import (
"github.com/guacsec/guac/pkg/assembler/backends/helper"
"github.com/guacsec/guac/pkg/assembler/graphql/model"
"github.com/pkg/errors"
"golang.org/x/exp/slices"
)

func (b *EntBackend) Packages(ctx context.Context, pkgSpec *model.PkgSpec) ([]*model.Package, error) {
Expand Down Expand Up @@ -131,7 +131,6 @@ func (b *EntBackend) IngestPackage(ctx context.Context, pkg model.PkgInputSpec)
// upsertPackage is a helper function to create or update a package node and its associated edges.
// It is used in multiple places, so we extract it to a function.
func upsertPackage(ctx context.Context, client *ent.Tx, pkg model.PkgInputSpec) (*ent.PackageVersion, error) {

pkgID, err := client.PackageType.Create().
SetType(pkg.Type).
OnConflict(sql.ConflictColumns(packagetype.FieldType)).
Expand Down
18 changes: 9 additions & 9 deletions pkg/assembler/backends/ent/backend/pkgequal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
package backend

import (
"slices"
"strconv"

"github.com/google/go-cmp/cmp"
"github.com/guacsec/guac/internal/testing/ptrfrom"
"github.com/guacsec/guac/pkg/assembler/graphql/model"
jsoniter "github.com/json-iterator/go"
"golang.org/x/exp/slices"
)

var json = jsoniter.ConfigCompatibleWithStandardLibrary
Expand Down Expand Up @@ -776,9 +776,9 @@ func (s *Suite) TestPkgEqualNeighbors() {
},
},
ExpNeighbors: map[string][]string{
"5": []string{"2", "7"}, // p1
"6": []string{"2", "7"}, // p2
"7": []string{"2", "2"}, // pkgequal
"5": {"2", "7"}, // p1
"6": {"2", "7"}, // p2
"7": {"2", "2"}, // pkgequal
},
},
{
Expand All @@ -801,11 +801,11 @@ func (s *Suite) TestPkgEqualNeighbors() {
},
},
ExpNeighbors: map[string][]string{
"5": []string{"2", "8", "9"}, // p1
"6": []string{"2", "8"}, // p2
"7": []string{"2", "9"}, // p3
"8": []string{"2", "2"}, // pkgequal 1
"9": []string{"2", "2"}, // pkgequal 2
"5": {"2", "8", "9"}, // p1
"6": {"2", "8"}, // p2
"7": {"2", "9"}, // p3
"8": {"2", "2"}, // pkgequal 1
"9": {"2", "2"}, // pkgequal 2
},
},
}
Expand Down
Loading

0 comments on commit a3299ca

Please sign in to comment.