mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 15:12:02 +00:00
[chore] Refactored to use common pointers helper functions (#53441)
Originally I started working on this because of [comment on another PR](https://github.com/sourcegraph/sourcegraph/pull/53373#discussion_r1228058455). I quickly wrote an implementation of Ptr and NonZeroPtr. Then I started refactoring existing code only to find out that @efritz already beat me to it. But Erics implementation was hidden in internal/codeintel/resolvers/utils.go Moved all of the Ptr functions to `pointers` package instead and refactored all existing code that I could find to use it instead of redefining the same functions all the time. Usage is mostly in tests, so hopefully the impact is not as huge as the diff size might suggest. ## Test plan A whole lot of unit tests.
This commit is contained in:
parent
306b29b2d8
commit
c31e079b5b
1
cmd/frontend/auth/BUILD.bazel
generated
1
cmd/frontend/auth/BUILD.bazel
generated
@ -59,6 +59,7 @@ go_test(
|
||||
"//internal/search/job/jobutil",
|
||||
"//internal/types",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"//schema",
|
||||
"@com_github_derision_test_go_mockgen//testutil/require",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
|
||||
@ -15,6 +15,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/conf"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/search/job/jobutil"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
"github.com/sourcegraph/sourcegraph/schema"
|
||||
)
|
||||
|
||||
@ -71,8 +72,6 @@ func TestAllowAnonymousRequestWithAdditionalConfig(t *testing.T) {
|
||||
return r
|
||||
}
|
||||
|
||||
boolPtr := func(b bool) *bool { return &b }
|
||||
|
||||
tests := []struct {
|
||||
req *http.Request
|
||||
confAuthPublic bool
|
||||
@ -81,25 +80,25 @@ func TestAllowAnonymousRequestWithAdditionalConfig(t *testing.T) {
|
||||
}{
|
||||
{req: req("GET", "/"), confAuthPublic: false, allowAnonymousContextKey: nil, want: false},
|
||||
{req: req("GET", "/"), confAuthPublic: true, allowAnonymousContextKey: nil, want: false},
|
||||
{req: req("GET", "/"), confAuthPublic: false, allowAnonymousContextKey: boolPtr(false), want: false},
|
||||
{req: req("GET", "/"), confAuthPublic: true, allowAnonymousContextKey: boolPtr(false), want: false},
|
||||
{req: req("GET", "/"), confAuthPublic: false, allowAnonymousContextKey: boolPtr(true), want: false},
|
||||
{req: req("GET", "/"), confAuthPublic: true, allowAnonymousContextKey: boolPtr(true), want: true},
|
||||
{req: req("GET", "/"), confAuthPublic: false, allowAnonymousContextKey: pointers.Ptr(false), want: false},
|
||||
{req: req("GET", "/"), confAuthPublic: true, allowAnonymousContextKey: pointers.Ptr(false), want: false},
|
||||
{req: req("GET", "/"), confAuthPublic: false, allowAnonymousContextKey: pointers.Ptr(true), want: false},
|
||||
{req: req("GET", "/"), confAuthPublic: true, allowAnonymousContextKey: pointers.Ptr(true), want: true},
|
||||
{req: req("POST", "/"), confAuthPublic: false, allowAnonymousContextKey: nil, want: false},
|
||||
{req: req("POST", "/"), confAuthPublic: true, allowAnonymousContextKey: nil, want: false},
|
||||
{req: req("POST", "/"), confAuthPublic: false, allowAnonymousContextKey: boolPtr(false), want: false},
|
||||
{req: req("POST", "/"), confAuthPublic: true, allowAnonymousContextKey: boolPtr(false), want: false},
|
||||
{req: req("POST", "/"), confAuthPublic: false, allowAnonymousContextKey: boolPtr(true), want: false},
|
||||
{req: req("POST", "/"), confAuthPublic: true, allowAnonymousContextKey: boolPtr(true), want: true},
|
||||
{req: req("POST", "/"), confAuthPublic: false, allowAnonymousContextKey: pointers.Ptr(false), want: false},
|
||||
{req: req("POST", "/"), confAuthPublic: true, allowAnonymousContextKey: pointers.Ptr(false), want: false},
|
||||
{req: req("POST", "/"), confAuthPublic: false, allowAnonymousContextKey: pointers.Ptr(true), want: false},
|
||||
{req: req("POST", "/"), confAuthPublic: true, allowAnonymousContextKey: pointers.Ptr(true), want: true},
|
||||
|
||||
{req: req("POST", "/-/sign-in"), confAuthPublic: false, allowAnonymousContextKey: nil, want: true},
|
||||
{req: req("POST", "/-/sign-in"), confAuthPublic: true, allowAnonymousContextKey: nil, want: true},
|
||||
{req: req("POST", "/-/sign-in"), confAuthPublic: false, allowAnonymousContextKey: boolPtr(true), want: true},
|
||||
{req: req("POST", "/-/sign-in"), confAuthPublic: true, allowAnonymousContextKey: boolPtr(true), want: true},
|
||||
{req: req("POST", "/-/sign-in"), confAuthPublic: false, allowAnonymousContextKey: pointers.Ptr(true), want: true},
|
||||
{req: req("POST", "/-/sign-in"), confAuthPublic: true, allowAnonymousContextKey: pointers.Ptr(true), want: true},
|
||||
{req: req("GET", "/sign-in"), confAuthPublic: false, allowAnonymousContextKey: nil, want: true},
|
||||
{req: req("GET", "/sign-in"), confAuthPublic: true, allowAnonymousContextKey: nil, want: true},
|
||||
{req: req("GET", "/sign-in"), confAuthPublic: false, allowAnonymousContextKey: boolPtr(true), want: true},
|
||||
{req: req("GET", "/sign-in"), confAuthPublic: true, allowAnonymousContextKey: boolPtr(true), want: true},
|
||||
{req: req("GET", "/sign-in"), confAuthPublic: false, allowAnonymousContextKey: pointers.Ptr(true), want: true},
|
||||
{req: req("GET", "/sign-in"), confAuthPublic: true, allowAnonymousContextKey: pointers.Ptr(true), want: true},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(fmt.Sprintf("%s %s + auth.public=%v, allowAnonymousContext=%v", test.req.Method, test.req.URL, test.confAuthPublic, test.allowAnonymousContextKey), func(t *testing.T) {
|
||||
|
||||
1
cmd/frontend/graphqlbackend/BUILD.bazel
generated
1
cmd/frontend/graphqlbackend/BUILD.bazel
generated
@ -504,6 +504,7 @@ go_test(
|
||||
"//internal/version",
|
||||
"//internal/webhooks/outbound",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"//schema",
|
||||
"@com_github_davecgh_go_spew//spew",
|
||||
"@com_github_derision_test_go_mockgen//testutil/assert",
|
||||
|
||||
@ -17,6 +17,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbtest"
|
||||
"github.com/sourcegraph/sourcegraph/internal/encryption"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestSchemaResolver_CreateExecutorSecret(t *testing.T) {
|
||||
@ -33,8 +34,6 @@ func TestSchemaResolver_CreateExecutorSecret(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
gqlIDPtr := func(id graphql.ID) *graphql.ID { return &id }
|
||||
|
||||
tts := []struct {
|
||||
name string
|
||||
args CreateExecutorSecretArgs
|
||||
@ -86,7 +85,7 @@ func TestSchemaResolver_CreateExecutorSecret(t *testing.T) {
|
||||
Key: "GITHUB_TOKEN",
|
||||
Value: "1234",
|
||||
Scope: ExecutorSecretScopeBatches,
|
||||
Namespace: gqlIDPtr(MarshalUserID(user.ID)),
|
||||
Namespace: pointers.Ptr(MarshalUserID(user.ID)),
|
||||
},
|
||||
actor: actor.FromUser(user.ID),
|
||||
},
|
||||
|
||||
@ -22,6 +22,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/txemail"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
stderrors "github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
"github.com/sourcegraph/sourcegraph/schema"
|
||||
)
|
||||
|
||||
@ -106,7 +107,7 @@ func TestOrgInvitationURL(t *testing.T) {
|
||||
OrgID: 1,
|
||||
ID: 2,
|
||||
SenderUserID: 3,
|
||||
ExpiresAt: timePtr(timeNow().Add(DefaultExpiryDuration)),
|
||||
ExpiresAt: pointers.Ptr(timeNow().Add(DefaultExpiryDuration)),
|
||||
}
|
||||
|
||||
t.Run("Fails if site config is not defined", func(t *testing.T) {
|
||||
@ -186,7 +187,7 @@ func TestInviteUserToOrganization(t *testing.T) {
|
||||
orgs.GetByIDFunc.SetDefaultReturn(&mockedOrg, nil)
|
||||
|
||||
orgInvitations := database.NewMockOrgInvitationStore()
|
||||
orgInvitations.CreateFunc.SetDefaultReturn(&database.OrgInvitation{ID: 1, ExpiresAt: timePtr(timeNow().Add(DefaultExpiryDuration))}, nil)
|
||||
orgInvitations.CreateFunc.SetDefaultReturn(&database.OrgInvitation{ID: 1, ExpiresAt: pointers.Ptr(timeNow().Add(DefaultExpiryDuration))}, nil)
|
||||
|
||||
featureFlags := database.NewMockFeatureFlagStore()
|
||||
featureFlags.GetOrgFeatureFlagFunc.SetDefaultReturn(false, nil)
|
||||
|
||||
@ -16,6 +16,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/rbac"
|
||||
"github.com/sourcegraph/sourcegraph/internal/search/job/jobutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
|
||||
"github.com/sourcegraph/log/logtest"
|
||||
|
||||
@ -51,8 +52,6 @@ func TestRepositoryMetadata(t *testing.T) {
|
||||
schema := newSchemaResolver(db, gitserver.NewClient(), jobutil.NewUnimplementedEnterpriseJobs())
|
||||
gqlID := MarshalRepositoryID(repo.ID)
|
||||
|
||||
strPtr := func(s string) *string { return &s }
|
||||
|
||||
t.Run("add", func(t *testing.T) {
|
||||
_, err = schema.AddRepoMetadata(ctx, struct {
|
||||
Repo graphql.ID
|
||||
@ -61,7 +60,7 @@ func TestRepositoryMetadata(t *testing.T) {
|
||||
}{
|
||||
Repo: gqlID,
|
||||
Key: "key1",
|
||||
Value: strPtr("val1"),
|
||||
Value: pointers.Ptr("val1"),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -72,7 +71,7 @@ func TestRepositoryMetadata(t *testing.T) {
|
||||
}{
|
||||
Repo: gqlID,
|
||||
Key: "tag1",
|
||||
Value: strPtr(" "),
|
||||
Value: pointers.Ptr(" "),
|
||||
})
|
||||
require.Error(t, err)
|
||||
require.Equal(t, emptyNonNilValueError{value: " "}, err)
|
||||
@ -98,7 +97,7 @@ func TestRepositoryMetadata(t *testing.T) {
|
||||
})
|
||||
require.Equal(t, []KeyValuePair{{
|
||||
key: "key1",
|
||||
value: strPtr("val1"),
|
||||
value: pointers.Ptr("val1"),
|
||||
}, {
|
||||
key: "tag1",
|
||||
value: nil,
|
||||
@ -113,7 +112,7 @@ func TestRepositoryMetadata(t *testing.T) {
|
||||
}{
|
||||
Repo: gqlID,
|
||||
Key: "key1",
|
||||
Value: strPtr("val2"),
|
||||
Value: pointers.Ptr("val2"),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -124,7 +123,7 @@ func TestRepositoryMetadata(t *testing.T) {
|
||||
}{
|
||||
Repo: gqlID,
|
||||
Key: "tag1",
|
||||
Value: strPtr("val3"),
|
||||
Value: pointers.Ptr("val3"),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -135,7 +134,7 @@ func TestRepositoryMetadata(t *testing.T) {
|
||||
}{
|
||||
Repo: gqlID,
|
||||
Key: "tag1",
|
||||
Value: strPtr(" "),
|
||||
Value: pointers.Ptr(" "),
|
||||
})
|
||||
require.Error(t, err)
|
||||
require.Equal(t, emptyNonNilValueError{value: " "}, err)
|
||||
@ -150,10 +149,10 @@ func TestRepositoryMetadata(t *testing.T) {
|
||||
})
|
||||
require.Equal(t, []KeyValuePair{{
|
||||
key: "key1",
|
||||
value: strPtr("val2"),
|
||||
value: pointers.Ptr("val2"),
|
||||
}, {
|
||||
key: "tag1",
|
||||
value: strPtr("val3"),
|
||||
value: pointers.Ptr("val3"),
|
||||
}}, kvps)
|
||||
})
|
||||
|
||||
@ -197,7 +196,7 @@ func TestRepositoryMetadata(t *testing.T) {
|
||||
}{
|
||||
Repo: gqlID,
|
||||
Key: "key1",
|
||||
Value: strPtr("val1"),
|
||||
Value: pointers.Ptr("val1"),
|
||||
})
|
||||
require.Error(t, err)
|
||||
require.Equal(t, featureDisabledError, err)
|
||||
@ -209,7 +208,7 @@ func TestRepositoryMetadata(t *testing.T) {
|
||||
}{
|
||||
Repo: gqlID,
|
||||
Key: "key1",
|
||||
Value: strPtr("val2"),
|
||||
Value: pointers.Ptr("val2"),
|
||||
})
|
||||
require.Error(t, err)
|
||||
require.Equal(t, featureDisabledError, err)
|
||||
@ -236,7 +235,7 @@ func TestRepositoryMetadata(t *testing.T) {
|
||||
}{
|
||||
Repo: gqlID,
|
||||
Key: "key1",
|
||||
Value: strPtr("val1"),
|
||||
Value: pointers.Ptr("val1"),
|
||||
})
|
||||
require.Error(t, err)
|
||||
require.Equal(t, err, &rbac.ErrNotAuthorized{Permission: string(rbac.RepoMetadataWritePermission)})
|
||||
@ -249,7 +248,7 @@ func TestRepositoryMetadata(t *testing.T) {
|
||||
}{
|
||||
Repo: gqlID,
|
||||
Key: "key1",
|
||||
Value: strPtr("val2"),
|
||||
Value: pointers.Ptr("val2"),
|
||||
})
|
||||
require.Error(t, err)
|
||||
require.Equal(t, err, &rbac.ErrNotAuthorized{Permission: string(rbac.RepoMetadataWritePermission)})
|
||||
|
||||
@ -8,10 +8,12 @@ import (
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/sourcegraph/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbtest"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
type siteConfigStubs struct {
|
||||
@ -102,7 +104,7 @@ func setupSiteConfigStubs(t *testing.T) *siteConfigStubs {
|
||||
// This will create 5 entries, because the first time conf.SiteCreateIfupToDate is called it
|
||||
// will create two entries in the DB.
|
||||
for _, input := range siteConfigsToCreate {
|
||||
siteConfig, err := conf.SiteCreateIfUpToDate(ctx, int32Ptr(lastID), input.AuthorUserID, input.Contents, false)
|
||||
siteConfig, err := conf.SiteCreateIfUpToDate(ctx, pointers.Ptr(lastID), input.AuthorUserID, input.Contents, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -529,7 +531,7 @@ func TestSiteConfigurationChangeConnectionStoreComputeNodes(t *testing.T) {
|
||||
{
|
||||
name: "first: 2",
|
||||
paginationArgs: &database.PaginationArgs{
|
||||
First: intPtr(2),
|
||||
First: pointers.Ptr(2),
|
||||
},
|
||||
// 5 is skipped because it is the same as 4.
|
||||
expectedSiteConfigIDs: []int32{6, 4},
|
||||
@ -538,7 +540,7 @@ func TestSiteConfigurationChangeConnectionStoreComputeNodes(t *testing.T) {
|
||||
{
|
||||
name: "first: 6 (exact number of items that exist in the database)",
|
||||
paginationArgs: &database.PaginationArgs{
|
||||
First: intPtr(6),
|
||||
First: pointers.Ptr(6),
|
||||
},
|
||||
expectedSiteConfigIDs: []int32{6, 4, 3, 2, 1},
|
||||
expectedPreviousSiteConfigIDs: []int32{4, 3, 2, 1, 0},
|
||||
@ -546,7 +548,7 @@ func TestSiteConfigurationChangeConnectionStoreComputeNodes(t *testing.T) {
|
||||
{
|
||||
name: "first: 20 (more items than what exists in the database)",
|
||||
paginationArgs: &database.PaginationArgs{
|
||||
First: intPtr(20),
|
||||
First: pointers.Ptr(20),
|
||||
},
|
||||
expectedSiteConfigIDs: []int32{6, 4, 3, 2, 1},
|
||||
expectedPreviousSiteConfigIDs: []int32{4, 3, 2, 1, 0},
|
||||
@ -554,7 +556,7 @@ func TestSiteConfigurationChangeConnectionStoreComputeNodes(t *testing.T) {
|
||||
{
|
||||
name: "last: 2",
|
||||
paginationArgs: &database.PaginationArgs{
|
||||
Last: intPtr(2),
|
||||
Last: pointers.Ptr(2),
|
||||
},
|
||||
expectedSiteConfigIDs: []int32{1, 2},
|
||||
expectedPreviousSiteConfigIDs: []int32{0, 1},
|
||||
@ -562,7 +564,7 @@ func TestSiteConfigurationChangeConnectionStoreComputeNodes(t *testing.T) {
|
||||
{
|
||||
name: "last: 6 (exact number of items that exist in the database)",
|
||||
paginationArgs: &database.PaginationArgs{
|
||||
Last: intPtr(6),
|
||||
Last: pointers.Ptr(6),
|
||||
},
|
||||
expectedSiteConfigIDs: []int32{1, 2, 3, 4, 6},
|
||||
expectedPreviousSiteConfigIDs: []int32{0, 1, 2, 3, 4},
|
||||
@ -570,7 +572,7 @@ func TestSiteConfigurationChangeConnectionStoreComputeNodes(t *testing.T) {
|
||||
{
|
||||
name: "last: 20 (more items than what exists in the database)",
|
||||
paginationArgs: &database.PaginationArgs{
|
||||
Last: intPtr(20),
|
||||
Last: pointers.Ptr(20),
|
||||
},
|
||||
expectedSiteConfigIDs: []int32{1, 2, 3, 4, 6},
|
||||
expectedPreviousSiteConfigIDs: []int32{0, 1, 2, 3, 4},
|
||||
@ -578,7 +580,7 @@ func TestSiteConfigurationChangeConnectionStoreComputeNodes(t *testing.T) {
|
||||
{
|
||||
name: "first: 2, after: 6",
|
||||
paginationArgs: &database.PaginationArgs{
|
||||
First: intPtr(2),
|
||||
First: pointers.Ptr(2),
|
||||
After: toStringPtr(6),
|
||||
},
|
||||
expectedSiteConfigIDs: []int32{4, 3},
|
||||
@ -587,7 +589,7 @@ func TestSiteConfigurationChangeConnectionStoreComputeNodes(t *testing.T) {
|
||||
{
|
||||
name: "first: 10, after: 6",
|
||||
paginationArgs: &database.PaginationArgs{
|
||||
First: intPtr(10),
|
||||
First: pointers.Ptr(10),
|
||||
After: toStringPtr(6),
|
||||
},
|
||||
expectedSiteConfigIDs: []int32{4, 3, 2, 1},
|
||||
@ -596,7 +598,7 @@ func TestSiteConfigurationChangeConnectionStoreComputeNodes(t *testing.T) {
|
||||
{
|
||||
name: "first: 2, after: 1",
|
||||
paginationArgs: &database.PaginationArgs{
|
||||
First: intPtr(2),
|
||||
First: pointers.Ptr(2),
|
||||
After: toStringPtr(1),
|
||||
},
|
||||
expectedSiteConfigIDs: []int32{},
|
||||
@ -605,7 +607,7 @@ func TestSiteConfigurationChangeConnectionStoreComputeNodes(t *testing.T) {
|
||||
{
|
||||
name: "last: 2, before: 2",
|
||||
paginationArgs: &database.PaginationArgs{
|
||||
Last: intPtr(2),
|
||||
Last: pointers.Ptr(2),
|
||||
Before: toStringPtr(2),
|
||||
},
|
||||
expectedSiteConfigIDs: []int32{3, 4},
|
||||
@ -614,7 +616,7 @@ func TestSiteConfigurationChangeConnectionStoreComputeNodes(t *testing.T) {
|
||||
{
|
||||
name: "last: 10, before: 2",
|
||||
paginationArgs: &database.PaginationArgs{
|
||||
Last: intPtr(10),
|
||||
Last: pointers.Ptr(10),
|
||||
Before: toStringPtr(2),
|
||||
},
|
||||
expectedSiteConfigIDs: []int32{3, 4, 6},
|
||||
@ -623,7 +625,7 @@ func TestSiteConfigurationChangeConnectionStoreComputeNodes(t *testing.T) {
|
||||
{
|
||||
name: "last: 2, before: 6",
|
||||
paginationArgs: &database.PaginationArgs{
|
||||
Last: intPtr(2),
|
||||
Last: pointers.Ptr(2),
|
||||
Before: toStringPtr(6),
|
||||
},
|
||||
expectedSiteConfigIDs: []int32{},
|
||||
@ -682,38 +684,38 @@ func TestModifyArgs(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "first: 5 (first page)",
|
||||
args: &database.PaginationArgs{First: intPtr(5)},
|
||||
expectedArgs: &database.PaginationArgs{First: intPtr(6)},
|
||||
args: &database.PaginationArgs{First: pointers.Ptr(5)},
|
||||
expectedArgs: &database.PaginationArgs{First: pointers.Ptr(6)},
|
||||
expectedModified: true,
|
||||
},
|
||||
{
|
||||
name: "first: 5, after: 10 (next page)",
|
||||
args: &database.PaginationArgs{First: intPtr(5), After: toStringPtr(10)},
|
||||
expectedArgs: &database.PaginationArgs{First: intPtr(6), After: toStringPtr(10)},
|
||||
args: &database.PaginationArgs{First: pointers.Ptr(5), After: toStringPtr(10)},
|
||||
expectedArgs: &database.PaginationArgs{First: pointers.Ptr(6), After: toStringPtr(10)},
|
||||
expectedModified: true,
|
||||
},
|
||||
{
|
||||
name: "last: 5 (last page)",
|
||||
args: &database.PaginationArgs{Last: intPtr(5)},
|
||||
expectedArgs: &database.PaginationArgs{Last: intPtr(5)},
|
||||
args: &database.PaginationArgs{Last: pointers.Ptr(5)},
|
||||
expectedArgs: &database.PaginationArgs{Last: pointers.Ptr(5)},
|
||||
expectedModified: false,
|
||||
},
|
||||
{
|
||||
name: "last: 5, before: 10 (previous page)",
|
||||
args: &database.PaginationArgs{Last: intPtr(5), Before: toStringPtr(10)},
|
||||
expectedArgs: &database.PaginationArgs{Last: intPtr(6), Before: toStringPtr(9)},
|
||||
args: &database.PaginationArgs{Last: pointers.Ptr(5), Before: toStringPtr(10)},
|
||||
expectedArgs: &database.PaginationArgs{Last: pointers.Ptr(6), Before: toStringPtr(9)},
|
||||
expectedModified: true,
|
||||
},
|
||||
{
|
||||
name: "last: 5, before: 1 (edge case)",
|
||||
args: &database.PaginationArgs{Last: intPtr(5), Before: toStringPtr(1)},
|
||||
expectedArgs: &database.PaginationArgs{Last: intPtr(6), Before: toStringPtr(0)},
|
||||
args: &database.PaginationArgs{Last: pointers.Ptr(5), Before: toStringPtr(1)},
|
||||
expectedArgs: &database.PaginationArgs{Last: pointers.Ptr(6), Before: toStringPtr(0)},
|
||||
expectedModified: true,
|
||||
},
|
||||
{
|
||||
name: "last: 5, before: 0 (same as last page but a mathematical edge case)",
|
||||
args: &database.PaginationArgs{Last: intPtr(5), Before: toStringPtr(0)},
|
||||
expectedArgs: &database.PaginationArgs{Last: intPtr(5), Before: toStringPtr(0)},
|
||||
args: &database.PaginationArgs{Last: pointers.Ptr(5), Before: toStringPtr(0)},
|
||||
expectedArgs: &database.PaginationArgs{Last: pointers.Ptr(5), Before: toStringPtr(0)},
|
||||
expectedModified: false,
|
||||
},
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/search/job/jobutil"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestSiteConfigurationDiff(t *testing.T) {
|
||||
@ -63,11 +64,11 @@ func TestSiteConfigurationDiff(t *testing.T) {
|
||||
// the nodes in both the directions.
|
||||
{
|
||||
name: "first: 10",
|
||||
args: &graphqlutil.ConnectionResolverArgs{First: int32Ptr(10)},
|
||||
args: &graphqlutil.ConnectionResolverArgs{First: pointers.Ptr(int32(10))},
|
||||
},
|
||||
{
|
||||
name: "last: 10",
|
||||
args: &graphqlutil.ConnectionResolverArgs{Last: int32Ptr(10)},
|
||||
args: &graphqlutil.ConnectionResolverArgs{Last: pointers.Ptr(int32(10))},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/search/job/jobutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestSiteConfiguration(t *testing.T) {
|
||||
@ -50,95 +51,95 @@ func TestSiteConfigurationHistory(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "first: 2",
|
||||
args: &graphqlutil.ConnectionResolverArgs{First: int32Ptr(2)},
|
||||
args: &graphqlutil.ConnectionResolverArgs{First: pointers.Ptr(int32(2))},
|
||||
expectedSiteConfigIDs: []int32{6, 4},
|
||||
},
|
||||
{
|
||||
name: "first: 6 (exact number of items that exist in the database)",
|
||||
args: &graphqlutil.ConnectionResolverArgs{First: int32Ptr(6)},
|
||||
args: &graphqlutil.ConnectionResolverArgs{First: pointers.Ptr(int32(6))},
|
||||
expectedSiteConfigIDs: []int32{6, 4, 3, 2, 1},
|
||||
},
|
||||
{
|
||||
name: "first: 20 (more items than what exists in the database)",
|
||||
args: &graphqlutil.ConnectionResolverArgs{First: int32Ptr(20)},
|
||||
args: &graphqlutil.ConnectionResolverArgs{First: pointers.Ptr(int32(20))},
|
||||
expectedSiteConfigIDs: []int32{6, 4, 3, 2, 1},
|
||||
},
|
||||
{
|
||||
name: "last: 2",
|
||||
args: &graphqlutil.ConnectionResolverArgs{Last: int32Ptr(2)},
|
||||
args: &graphqlutil.ConnectionResolverArgs{Last: pointers.Ptr(int32(2))},
|
||||
expectedSiteConfigIDs: []int32{2, 1},
|
||||
},
|
||||
{
|
||||
name: "last: 6 (exact number of items that exist in the database)",
|
||||
args: &graphqlutil.ConnectionResolverArgs{Last: int32Ptr(6)},
|
||||
args: &graphqlutil.ConnectionResolverArgs{Last: pointers.Ptr(int32(6))},
|
||||
expectedSiteConfigIDs: []int32{6, 4, 3, 2, 1},
|
||||
},
|
||||
{
|
||||
name: "last: 20 (more items than what exists in the database)",
|
||||
args: &graphqlutil.ConnectionResolverArgs{Last: int32Ptr(20)},
|
||||
args: &graphqlutil.ConnectionResolverArgs{Last: pointers.Ptr(int32(20))},
|
||||
expectedSiteConfigIDs: []int32{6, 4, 3, 2, 1},
|
||||
},
|
||||
{
|
||||
name: "first: 2, after: 4",
|
||||
args: &graphqlutil.ConnectionResolverArgs{
|
||||
First: int32Ptr(2),
|
||||
After: stringPtr(string(marshalSiteConfigurationChangeID(4))),
|
||||
First: pointers.Ptr(int32(2)),
|
||||
After: pointers.Ptr(string(marshalSiteConfigurationChangeID(4))),
|
||||
},
|
||||
expectedSiteConfigIDs: []int32{3, 2},
|
||||
},
|
||||
{
|
||||
name: "first: 10, after: 4 (overflow)",
|
||||
args: &graphqlutil.ConnectionResolverArgs{
|
||||
First: int32Ptr(10),
|
||||
After: stringPtr(string(marshalSiteConfigurationChangeID(4))),
|
||||
First: pointers.Ptr(int32(10)),
|
||||
After: pointers.Ptr(string(marshalSiteConfigurationChangeID(4))),
|
||||
},
|
||||
expectedSiteConfigIDs: []int32{3, 2, 1},
|
||||
},
|
||||
{
|
||||
name: "first: 10, after: 7 (same as get all items, but latest ID in DB is 6)",
|
||||
args: &graphqlutil.ConnectionResolverArgs{
|
||||
First: int32Ptr(10),
|
||||
After: stringPtr(string(marshalSiteConfigurationChangeID(7))),
|
||||
First: pointers.Ptr(int32(10)),
|
||||
After: pointers.Ptr(string(marshalSiteConfigurationChangeID(7))),
|
||||
},
|
||||
expectedSiteConfigIDs: []int32{6, 4, 3, 2, 1},
|
||||
},
|
||||
{
|
||||
name: "first: 10, after: 1 (beyond the last cursor in DB which is 1)",
|
||||
args: &graphqlutil.ConnectionResolverArgs{
|
||||
First: int32Ptr(10),
|
||||
After: stringPtr(string(marshalSiteConfigurationChangeID(1))),
|
||||
First: pointers.Ptr(int32(10)),
|
||||
After: pointers.Ptr(string(marshalSiteConfigurationChangeID(1))),
|
||||
},
|
||||
expectedSiteConfigIDs: []int32{},
|
||||
},
|
||||
{
|
||||
name: "last: 2, before: 1",
|
||||
args: &graphqlutil.ConnectionResolverArgs{
|
||||
Last: int32Ptr(2),
|
||||
Before: stringPtr(string(marshalSiteConfigurationChangeID(1))),
|
||||
Last: pointers.Ptr(int32(2)),
|
||||
Before: pointers.Ptr(string(marshalSiteConfigurationChangeID(1))),
|
||||
},
|
||||
expectedSiteConfigIDs: []int32{3, 2},
|
||||
},
|
||||
{
|
||||
name: "last: 10, before: 1 (overflow)",
|
||||
args: &graphqlutil.ConnectionResolverArgs{
|
||||
Last: int32Ptr(10),
|
||||
Before: stringPtr(string(marshalSiteConfigurationChangeID(1))),
|
||||
Last: pointers.Ptr(int32(10)),
|
||||
Before: pointers.Ptr(string(marshalSiteConfigurationChangeID(1))),
|
||||
},
|
||||
expectedSiteConfigIDs: []int32{6, 4, 3, 2},
|
||||
},
|
||||
{
|
||||
name: "last: 10, before: 0 (same as get all items, but oldest ID in DB is 1)",
|
||||
args: &graphqlutil.ConnectionResolverArgs{
|
||||
Last: int32Ptr(10),
|
||||
Before: stringPtr(string(marshalSiteConfigurationChangeID(0))),
|
||||
Last: pointers.Ptr(int32(10)),
|
||||
Before: pointers.Ptr(string(marshalSiteConfigurationChangeID(0))),
|
||||
},
|
||||
expectedSiteConfigIDs: []int32{6, 4, 3, 2, 1},
|
||||
},
|
||||
{
|
||||
name: "last: 10, before: 7 (beyond the latest cursor in DB which is 6)",
|
||||
args: &graphqlutil.ConnectionResolverArgs{
|
||||
Last: int32Ptr(10),
|
||||
Before: stringPtr(string(marshalSiteConfigurationChangeID(7))),
|
||||
Last: pointers.Ptr(int32(10)),
|
||||
Before: pointers.Ptr(string(marshalSiteConfigurationChangeID(7))),
|
||||
},
|
||||
expectedSiteConfigIDs: []int32{},
|
||||
},
|
||||
|
||||
@ -6,10 +6,11 @@ import (
|
||||
"time"
|
||||
|
||||
mockassert "github.com/derision-test/go-mockgen/testutil/assert"
|
||||
"github.com/graph-gophers/graphql-go"
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/auth"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
@ -41,11 +42,11 @@ func TestWebhookLogsArgs(t *testing.T) {
|
||||
"OnlyErrors false": {
|
||||
id: WebhookLogsUnmatchedExternalService,
|
||||
input: WebhookLogsArgs{
|
||||
OnlyErrors: boolPtr(false),
|
||||
OnlyErrors: pointers.Ptr(false),
|
||||
},
|
||||
want: database.WebhookLogListOpts{
|
||||
Limit: 50,
|
||||
ExternalServiceID: int64Ptr(0),
|
||||
ExternalServiceID: pointers.Ptr(int64(0)),
|
||||
OnlyErrors: false,
|
||||
},
|
||||
},
|
||||
@ -53,22 +54,22 @@ func TestWebhookLogsArgs(t *testing.T) {
|
||||
id: webhookLogsExternalServiceID(1),
|
||||
input: WebhookLogsArgs{
|
||||
ConnectionArgs: graphqlutil.ConnectionArgs{
|
||||
First: int32Ptr(25),
|
||||
First: pointers.Ptr(int32(25)),
|
||||
},
|
||||
After: stringPtr("40"),
|
||||
OnlyErrors: boolPtr(true),
|
||||
Since: timePtr(now),
|
||||
Until: timePtr(later),
|
||||
WebhookID: gqlIDPtr(webhookID),
|
||||
After: pointers.Ptr("40"),
|
||||
OnlyErrors: pointers.Ptr(true),
|
||||
Since: pointers.Ptr(now),
|
||||
Until: pointers.Ptr(later),
|
||||
WebhookID: pointers.Ptr(webhookID),
|
||||
},
|
||||
want: database.WebhookLogListOpts{
|
||||
Limit: 25,
|
||||
Cursor: 40,
|
||||
ExternalServiceID: int64Ptr(1),
|
||||
ExternalServiceID: pointers.Ptr(int64(1)),
|
||||
OnlyErrors: true,
|
||||
Since: timePtr(now),
|
||||
Until: timePtr(later),
|
||||
WebhookID: int32Ptr(123),
|
||||
Since: pointers.Ptr(now),
|
||||
Until: pointers.Ptr(later),
|
||||
WebhookID: pointers.Ptr(int32(123)),
|
||||
},
|
||||
},
|
||||
} {
|
||||
@ -155,7 +156,7 @@ func TestWebhookLogConnectionResolver(t *testing.T) {
|
||||
r := &WebhookLogConnectionResolver{
|
||||
args: &WebhookLogsArgs{
|
||||
ConnectionArgs: graphqlutil.ConnectionArgs{
|
||||
First: int32Ptr(20),
|
||||
First: pointers.Ptr(int32(20)),
|
||||
},
|
||||
},
|
||||
externalServiceID: webhookLogsExternalServiceID(1),
|
||||
@ -175,7 +176,7 @@ func TestWebhookLogConnectionResolver(t *testing.T) {
|
||||
mockassert.Values(
|
||||
mockassert.Skip,
|
||||
database.WebhookLogListOpts{
|
||||
ExternalServiceID: int64Ptr(1),
|
||||
ExternalServiceID: pointers.Ptr(int64(1)),
|
||||
Limit: 20,
|
||||
},
|
||||
),
|
||||
@ -188,7 +189,7 @@ func TestWebhookLogConnectionResolver(t *testing.T) {
|
||||
r := &WebhookLogConnectionResolver{
|
||||
args: &WebhookLogsArgs{
|
||||
ConnectionArgs: graphqlutil.ConnectionArgs{
|
||||
First: int32Ptr(20),
|
||||
First: pointers.Ptr(int32(20)),
|
||||
},
|
||||
},
|
||||
externalServiceID: webhookLogsExternalServiceID(1),
|
||||
@ -210,7 +211,7 @@ func TestWebhookLogConnectionResolver(t *testing.T) {
|
||||
mockassert.Values(
|
||||
mockassert.Skip,
|
||||
database.WebhookLogListOpts{
|
||||
ExternalServiceID: int64Ptr(1),
|
||||
ExternalServiceID: pointers.Ptr(int64(1)),
|
||||
Limit: 20,
|
||||
},
|
||||
),
|
||||
@ -224,7 +225,7 @@ func TestWebhookLogConnectionResolver(t *testing.T) {
|
||||
r := &WebhookLogConnectionResolver{
|
||||
args: &WebhookLogsArgs{
|
||||
ConnectionArgs: graphqlutil.ConnectionArgs{
|
||||
First: int32Ptr(20),
|
||||
First: pointers.Ptr(int32(20)),
|
||||
},
|
||||
},
|
||||
externalServiceID: webhookLogsExternalServiceID(1),
|
||||
@ -243,7 +244,7 @@ func TestWebhookLogConnectionResolver_TotalCount(t *testing.T) {
|
||||
|
||||
r := &WebhookLogConnectionResolver{
|
||||
args: &WebhookLogsArgs{
|
||||
OnlyErrors: boolPtr(true),
|
||||
OnlyErrors: pointers.Ptr(true),
|
||||
},
|
||||
externalServiceID: webhookLogsExternalServiceID(1),
|
||||
store: store,
|
||||
@ -258,7 +259,7 @@ func TestWebhookLogConnectionResolver_TotalCount(t *testing.T) {
|
||||
mockassert.Values(
|
||||
mockassert.Skip,
|
||||
database.WebhookLogListOpts{
|
||||
ExternalServiceID: int64Ptr(1),
|
||||
ExternalServiceID: pointers.Ptr(int64(1)),
|
||||
Limit: 50,
|
||||
OnlyErrors: true,
|
||||
},
|
||||
@ -273,7 +274,7 @@ func TestWebhookLogConnectionResolver_TotalCount(t *testing.T) {
|
||||
|
||||
r := &WebhookLogConnectionResolver{
|
||||
args: &WebhookLogsArgs{
|
||||
OnlyErrors: boolPtr(true),
|
||||
OnlyErrors: pointers.Ptr(true),
|
||||
},
|
||||
externalServiceID: webhookLogsExternalServiceID(1),
|
||||
store: store,
|
||||
@ -291,14 +292,14 @@ func TestListWebhookLogs(t *testing.T) {
|
||||
ctx := actor.WithActor(context.Background(), &actor.Actor{UID: 1})
|
||||
webhookLogsStore := database.NewMockWebhookLogStore()
|
||||
webhookLogs := []*types.WebhookLog{
|
||||
{ID: 1, WebhookID: int32Ptr(1), StatusCode: 200},
|
||||
{ID: 2, WebhookID: int32Ptr(1), StatusCode: 500},
|
||||
{ID: 3, WebhookID: int32Ptr(1), StatusCode: 200},
|
||||
{ID: 4, WebhookID: int32Ptr(2), StatusCode: 200},
|
||||
{ID: 5, WebhookID: int32Ptr(2), StatusCode: 200},
|
||||
{ID: 6, WebhookID: int32Ptr(2), StatusCode: 200},
|
||||
{ID: 7, WebhookID: int32Ptr(3), StatusCode: 500},
|
||||
{ID: 8, WebhookID: int32Ptr(3), StatusCode: 500},
|
||||
{ID: 1, WebhookID: pointers.Ptr(int32(1)), StatusCode: 200},
|
||||
{ID: 2, WebhookID: pointers.Ptr(int32(1)), StatusCode: 500},
|
||||
{ID: 3, WebhookID: pointers.Ptr(int32(1)), StatusCode: 200},
|
||||
{ID: 4, WebhookID: pointers.Ptr(int32(2)), StatusCode: 200},
|
||||
{ID: 5, WebhookID: pointers.Ptr(int32(2)), StatusCode: 200},
|
||||
{ID: 6, WebhookID: pointers.Ptr(int32(2)), StatusCode: 200},
|
||||
{ID: 7, WebhookID: pointers.Ptr(int32(3)), StatusCode: 500},
|
||||
{ID: 8, WebhookID: pointers.Ptr(int32(3)), StatusCode: 500},
|
||||
}
|
||||
webhookLogsStore.ListFunc.SetDefaultHook(func(_ context.Context, options database.WebhookLogListOpts) ([]*types.WebhookLog, int64, error) {
|
||||
var logs []*types.WebhookLog
|
||||
@ -418,11 +419,3 @@ func TestListWebhookLogs(t *testing.T) {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func boolPtr(v bool) *bool { return &v }
|
||||
func intPtr(v int) *int { return &v }
|
||||
func int32Ptr(v int32) *int32 { return &v }
|
||||
func int64Ptr(v int64) *int64 { return &v }
|
||||
func stringPtr(v string) *string { return &v }
|
||||
func timePtr(v time.Time) *time.Time { return &v }
|
||||
func gqlIDPtr(v graphql.ID) *graphql.ID { return &v }
|
||||
|
||||
@ -58,6 +58,7 @@ go_test(
|
||||
deps = [
|
||||
"//internal/extsvc",
|
||||
"//internal/types",
|
||||
"//lib/pointers",
|
||||
"//schema",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
"@com_github_hexops_autogold_v2//:autogold",
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/extsvc"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestLatestDockerVersionPushed(t *testing.T) {
|
||||
@ -536,9 +537,9 @@ func TestSerializeCodeIntelUsage(t *testing.T) {
|
||||
|
||||
testUsage, err := json.Marshal(types.NewCodeIntelUsageStatistics{
|
||||
StartOfWeek: now,
|
||||
WAUs: int32Ptr(25),
|
||||
SearchBasedWAUs: int32Ptr(10),
|
||||
PreciseCrossRepositoryWAUs: int32Ptr(40),
|
||||
WAUs: pointers.Ptr(int32(25)),
|
||||
SearchBasedWAUs: pointers.Ptr(int32(10)),
|
||||
PreciseCrossRepositoryWAUs: pointers.Ptr(int32(40)),
|
||||
EventSummaries: []types.CodeIntelEventSummary{
|
||||
{
|
||||
Action: types.HoverAction,
|
||||
@ -589,28 +590,28 @@ func TestSerializeCodeIntelUsage(t *testing.T) {
|
||||
TotalActions: 3,
|
||||
},
|
||||
},
|
||||
NumRepositories: int32Ptr(50 + 85),
|
||||
NumRepositoriesWithUploadRecords: int32Ptr(50),
|
||||
NumRepositoriesWithFreshUploadRecords: int32Ptr(40),
|
||||
NumRepositoriesWithIndexRecords: int32Ptr(30),
|
||||
NumRepositoriesWithFreshIndexRecords: int32Ptr(20),
|
||||
NumRepositoriesWithAutoIndexConfigurationRecords: int32Ptr(7),
|
||||
NumRepositories: pointers.Ptr(int32(50 + 85)),
|
||||
NumRepositoriesWithUploadRecords: pointers.Ptr(int32(50)),
|
||||
NumRepositoriesWithFreshUploadRecords: pointers.Ptr(int32(40)),
|
||||
NumRepositoriesWithIndexRecords: pointers.Ptr(int32(30)),
|
||||
NumRepositoriesWithFreshIndexRecords: pointers.Ptr(int32(20)),
|
||||
NumRepositoriesWithAutoIndexConfigurationRecords: pointers.Ptr(int32(7)),
|
||||
CountsByLanguage: map[string]types.CodeIntelRepositoryCountsByLanguage{
|
||||
"go": {
|
||||
NumRepositoriesWithUploadRecords: int32Ptr(10),
|
||||
NumRepositoriesWithFreshUploadRecords: int32Ptr(20),
|
||||
NumRepositoriesWithIndexRecords: int32Ptr(30),
|
||||
NumRepositoriesWithFreshIndexRecords: int32Ptr(40),
|
||||
NumRepositoriesWithUploadRecords: pointers.Ptr(int32(10)),
|
||||
NumRepositoriesWithFreshUploadRecords: pointers.Ptr(int32(20)),
|
||||
NumRepositoriesWithIndexRecords: pointers.Ptr(int32(30)),
|
||||
NumRepositoriesWithFreshIndexRecords: pointers.Ptr(int32(40)),
|
||||
},
|
||||
"typescript": {
|
||||
NumRepositoriesWithUploadRecords: int32Ptr(15),
|
||||
NumRepositoriesWithFreshUploadRecords: int32Ptr(25),
|
||||
NumRepositoriesWithIndexRecords: int32Ptr(35),
|
||||
NumRepositoriesWithFreshIndexRecords: int32Ptr(45),
|
||||
NumRepositoriesWithUploadRecords: pointers.Ptr(int32(15)),
|
||||
NumRepositoriesWithFreshUploadRecords: pointers.Ptr(int32(25)),
|
||||
NumRepositoriesWithIndexRecords: pointers.Ptr(int32(35)),
|
||||
NumRepositoriesWithFreshIndexRecords: pointers.Ptr(int32(45)),
|
||||
},
|
||||
},
|
||||
SettingsPageViewCount: int32Ptr(1489),
|
||||
UsersWithRefPanelRedesignEnabled: int32Ptr(46),
|
||||
SettingsPageViewCount: pointers.Ptr(int32(1489)),
|
||||
UsersWithRefPanelRedesignEnabled: pointers.Ptr(int32(46)),
|
||||
LanguageRequests: []types.LanguageRequest{
|
||||
{
|
||||
LanguageID: "frob",
|
||||
@ -799,16 +800,16 @@ func TestSerializeOldCodeIntelUsage(t *testing.T) {
|
||||
testPeriod, err := json.Marshal(&types.OldCodeIntelUsagePeriod{
|
||||
StartTime: now,
|
||||
Hover: &types.OldCodeIntelEventCategoryStatistics{
|
||||
LSIF: &types.OldCodeIntelEventStatistics{UsersCount: 1, EventsCount: int32Ptr(1)},
|
||||
Search: &types.OldCodeIntelEventStatistics{UsersCount: 2, EventsCount: int32Ptr(2)},
|
||||
LSIF: &types.OldCodeIntelEventStatistics{UsersCount: 1, EventsCount: pointers.Ptr(int32(1))},
|
||||
Search: &types.OldCodeIntelEventStatistics{UsersCount: 2, EventsCount: pointers.Ptr(int32(2))},
|
||||
},
|
||||
Definitions: &types.OldCodeIntelEventCategoryStatistics{
|
||||
LSIF: &types.OldCodeIntelEventStatistics{UsersCount: 3, EventsCount: int32Ptr(3)},
|
||||
Search: &types.OldCodeIntelEventStatistics{UsersCount: 4, EventsCount: int32Ptr(4)},
|
||||
LSIF: &types.OldCodeIntelEventStatistics{UsersCount: 3, EventsCount: pointers.Ptr(int32(3))},
|
||||
Search: &types.OldCodeIntelEventStatistics{UsersCount: 4, EventsCount: pointers.Ptr(int32(4))},
|
||||
},
|
||||
References: &types.OldCodeIntelEventCategoryStatistics{
|
||||
LSIF: &types.OldCodeIntelEventStatistics{UsersCount: 5, EventsCount: int32Ptr(1)},
|
||||
Search: &types.OldCodeIntelEventStatistics{UsersCount: 6, EventsCount: int32Ptr(3)},
|
||||
LSIF: &types.OldCodeIntelEventStatistics{UsersCount: 5, EventsCount: pointers.Ptr(int32(1))},
|
||||
Search: &types.OldCodeIntelEventStatistics{UsersCount: 6, EventsCount: pointers.Ptr(int32(3))},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@ -1243,7 +1244,3 @@ func compareJSON(t *testing.T, actual []byte, expected string) {
|
||||
t.Fatalf("mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
||||
func int32Ptr(v int32) *int32 {
|
||||
return &v
|
||||
}
|
||||
|
||||
1
cmd/frontend/internal/search/BUILD.bazel
generated
1
cmd/frontend/internal/search/BUILD.bazel
generated
@ -34,6 +34,7 @@ go_library(
|
||||
"//internal/trace",
|
||||
"//internal/types",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"@com_github_inconshreveable_log15//:log15",
|
||||
"@com_github_prometheus_client_golang//prometheus",
|
||||
"@com_github_prometheus_client_golang//prometheus/promauto",
|
||||
|
||||
@ -36,6 +36,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/trace"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
// StreamHandler is an http handler which streams back search results.
|
||||
@ -101,7 +102,7 @@ func (h *streamHandler) serveHTTP(r *http.Request, tr *trace.Trace, eventWriter
|
||||
inputs, err := h.searchClient.Plan(
|
||||
ctx,
|
||||
args.Version,
|
||||
strPtr(args.PatternType),
|
||||
pointers.NonZeroPtr(args.PatternType),
|
||||
args.Query,
|
||||
search.Mode(args.SearchMode),
|
||||
search.Streaming,
|
||||
@ -257,13 +258,6 @@ func parseURLQuery(q url.Values) (*args, error) {
|
||||
return &a, nil
|
||||
}
|
||||
|
||||
func strPtr(s string) *string {
|
||||
if s == "" {
|
||||
return nil
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func fromMatch(match result.Match, repoCache map[api.RepoID]*types.SearchedRepo, enableChunkMatches bool) streamhttp.EventMatch {
|
||||
switch v := match.(type) {
|
||||
case *result.FileMatch:
|
||||
|
||||
1
cmd/frontend/webhooks/BUILD.bazel
generated
1
cmd/frontend/webhooks/BUILD.bazel
generated
@ -63,6 +63,7 @@ go_test(
|
||||
"//internal/extsvc/gitlab/webhooks",
|
||||
"//internal/types",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"//schema",
|
||||
"@com_github_derision_test_go_mockgen//testutil/assert",
|
||||
"@com_github_google_go_github_v43//github",
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/conf"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
"github.com/sourcegraph/sourcegraph/schema"
|
||||
)
|
||||
|
||||
@ -49,7 +50,7 @@ func TestLogMiddleware(t *testing.T) {
|
||||
|
||||
t.Run("logging disabled", func(t *testing.T) {
|
||||
conf.Mock(&conf.Unified{SiteConfiguration: schema.SiteConfiguration{
|
||||
WebhookLogging: &schema.WebhookLogging{Enabled: boolPtr(false)},
|
||||
WebhookLogging: &schema.WebhookLogging{Enabled: pointers.Ptr(false)},
|
||||
}})
|
||||
defer conf.Mock(nil)
|
||||
|
||||
@ -141,7 +142,7 @@ func TestLoggingEnabled(t *testing.T) {
|
||||
},
|
||||
},
|
||||
WebhookLogging: &schema.WebhookLogging{
|
||||
Enabled: boolPtr(false),
|
||||
Enabled: pointers.Ptr(false),
|
||||
},
|
||||
}},
|
||||
want: false,
|
||||
@ -156,7 +157,7 @@ func TestLoggingEnabled(t *testing.T) {
|
||||
},
|
||||
},
|
||||
WebhookLogging: &schema.WebhookLogging{
|
||||
Enabled: boolPtr(true),
|
||||
Enabled: pointers.Ptr(true),
|
||||
},
|
||||
}},
|
||||
want: true,
|
||||
@ -164,7 +165,7 @@ func TestLoggingEnabled(t *testing.T) {
|
||||
"no encryption; explicit webhook false": {
|
||||
c: &conf.Unified{SiteConfiguration: schema.SiteConfiguration{
|
||||
WebhookLogging: &schema.WebhookLogging{
|
||||
Enabled: boolPtr(false),
|
||||
Enabled: pointers.Ptr(false),
|
||||
},
|
||||
}},
|
||||
want: false,
|
||||
@ -172,7 +173,7 @@ func TestLoggingEnabled(t *testing.T) {
|
||||
"no encryption; explicit webhook true": {
|
||||
c: &conf.Unified{SiteConfiguration: schema.SiteConfiguration{
|
||||
WebhookLogging: &schema.WebhookLogging{
|
||||
Enabled: boolPtr(true),
|
||||
Enabled: pointers.Ptr(true),
|
||||
},
|
||||
}},
|
||||
want: true,
|
||||
@ -183,5 +184,3 @@ func TestLoggingEnabled(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func boolPtr(v bool) *bool { return &v }
|
||||
|
||||
1
dev/internal/cmd/search-plan/BUILD.bazel
generated
1
dev/internal/cmd/search-plan/BUILD.bazel
generated
@ -15,6 +15,7 @@ go_library(
|
||||
"//internal/search/job/jobutil",
|
||||
"//internal/search/job/printer",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"@com_github_sourcegraph_log//:log",
|
||||
],
|
||||
)
|
||||
|
||||
@ -18,6 +18,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/search/job/jobutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/search/job/printer"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func run(w io.Writer, args []string) error {
|
||||
@ -50,7 +51,7 @@ func run(w io.Writer, args []string) error {
|
||||
inputs, err := cli.Plan(
|
||||
context.Background(),
|
||||
*version,
|
||||
strPtr(*patternType),
|
||||
pointers.NonZeroPtr(*patternType),
|
||||
query,
|
||||
mode,
|
||||
search.Streaming,
|
||||
@ -81,10 +82,3 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func strPtr(s string) *string {
|
||||
if s == "" {
|
||||
return nil
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@ go_library(
|
||||
"//internal/repoupdater/protocol",
|
||||
"//internal/types",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"@com_github_graph_gophers_graphql_go//:graphql-go",
|
||||
"@com_github_graph_gophers_graphql_go//relay",
|
||||
"@com_github_sourcegraph_log//:log",
|
||||
@ -72,6 +73,7 @@ go_test(
|
||||
"//internal/timeutil",
|
||||
"//internal/types",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"//schema",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
"@com_github_graph_gophers_graphql_go//:graphql-go",
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/graph-gophers/graphql-go"
|
||||
"github.com/graph-gophers/graphql-go/relay"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
@ -13,6 +14,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
const permissionsSyncJobIDKind = "PermissionsSyncJob"
|
||||
@ -329,6 +331,5 @@ func unmarshalPermissionsSyncJobID(id graphql.ID) (jobID int, err error) {
|
||||
}
|
||||
|
||||
func intToInt32Ptr(value int) *int32 {
|
||||
int32Value := int32(value)
|
||||
return &int32Value
|
||||
return pointers.Ptr(int32(value))
|
||||
}
|
||||
|
||||
@ -37,6 +37,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/timeutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
"github.com/sourcegraph/sourcegraph/schema"
|
||||
)
|
||||
|
||||
@ -1870,16 +1871,16 @@ query {
|
||||
db.UsersFunc.SetDefaultReturn(users)
|
||||
|
||||
bbProjects := database.NewMockBitbucketProjectPermissionsStore()
|
||||
entry := executor.ExecutionLogEntry{Key: "key", Command: []string{"command"}, StartTime: mustParseTime("2020-01-06"), ExitCode: intPtr(1), Out: "out", DurationMs: intPtr(1)}
|
||||
entry := executor.ExecutionLogEntry{Key: "key", Command: []string{"command"}, StartTime: mustParseTime("2020-01-06"), ExitCode: pointers.Ptr(1), Out: "out", DurationMs: pointers.Ptr(1)}
|
||||
bbProjects.ListJobsFunc.SetDefaultReturn([]*types.BitbucketProjectPermissionJob{
|
||||
{
|
||||
ID: 1,
|
||||
State: "queued",
|
||||
FailureMessage: stringPtr("failure massage"),
|
||||
FailureMessage: pointers.Ptr("failure massage"),
|
||||
QueuedAt: mustParseTime("2020-01-01"),
|
||||
StartedAt: timePtr(mustParseTime("2020-01-01")),
|
||||
FinishedAt: timePtr(mustParseTime("2020-01-01")),
|
||||
ProcessAfter: timePtr(mustParseTime("2020-01-01")),
|
||||
StartedAt: pointers.Ptr(mustParseTime("2020-01-01")),
|
||||
FinishedAt: pointers.Ptr(mustParseTime("2020-01-01")),
|
||||
ProcessAfter: pointers.Ptr(mustParseTime("2020-01-01")),
|
||||
NumResets: 1,
|
||||
NumFailures: 2,
|
||||
LastHeartbeatAt: mustParseTime("2020-01-05"),
|
||||
@ -2598,10 +2599,6 @@ func mustParseTime(v string) time.Time {
|
||||
return t
|
||||
}
|
||||
|
||||
func intPtr(v int) *int { return &v }
|
||||
func timePtr(v time.Time) *time.Time { return &v }
|
||||
func stringPtr(v string) *string { return &v }
|
||||
|
||||
func TestResolver_PermissionsSyncingStats(t *testing.T) {
|
||||
t.Run("authenticated as non-admin", func(t *testing.T) {
|
||||
user := &types.User{ID: 42}
|
||||
|
||||
@ -164,6 +164,7 @@ go_test(
|
||||
"//lib/batches/schema",
|
||||
"//lib/batches/yaml",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"//schema",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
"@com_github_graph_gophers_graphql_go//:graphql-go",
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/internal/batches/search"
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/internal/batches/store"
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/internal/batches/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestWorkspacesListArgsToDBOpts(t *testing.T) {
|
||||
@ -33,7 +34,7 @@ func TestWorkspacesListArgsToDBOpts(t *testing.T) {
|
||||
{
|
||||
name: "after set",
|
||||
args: &graphqlbackend.ListWorkspacesArgs{
|
||||
After: strPtr("10"),
|
||||
After: pointers.Ptr("10"),
|
||||
},
|
||||
want: store.ListBatchSpecWorkspacesOpts{
|
||||
Cursor: 10,
|
||||
@ -42,7 +43,7 @@ func TestWorkspacesListArgsToDBOpts(t *testing.T) {
|
||||
{
|
||||
name: "search set",
|
||||
args: &graphqlbackend.ListWorkspacesArgs{
|
||||
Search: strPtr("sourcegraph"),
|
||||
Search: pointers.Ptr("sourcegraph"),
|
||||
},
|
||||
want: store.ListBatchSpecWorkspacesOpts{
|
||||
TextSearch: []search.TextSearchTerm{{Term: "sourcegraph"}},
|
||||
@ -51,7 +52,7 @@ func TestWorkspacesListArgsToDBOpts(t *testing.T) {
|
||||
{
|
||||
name: "state completed",
|
||||
args: &graphqlbackend.ListWorkspacesArgs{
|
||||
State: strPtr("COMPLETED"),
|
||||
State: pointers.Ptr("COMPLETED"),
|
||||
},
|
||||
want: store.ListBatchSpecWorkspacesOpts{
|
||||
OnlyCachedOrCompleted: true,
|
||||
@ -60,7 +61,7 @@ func TestWorkspacesListArgsToDBOpts(t *testing.T) {
|
||||
{
|
||||
name: "state pending",
|
||||
args: &graphqlbackend.ListWorkspacesArgs{
|
||||
State: strPtr("PENDING"),
|
||||
State: pointers.Ptr("PENDING"),
|
||||
},
|
||||
want: store.ListBatchSpecWorkspacesOpts{
|
||||
OnlyWithoutExecutionAndNotCached: true,
|
||||
@ -69,7 +70,7 @@ func TestWorkspacesListArgsToDBOpts(t *testing.T) {
|
||||
{
|
||||
name: "state queued",
|
||||
args: &graphqlbackend.ListWorkspacesArgs{
|
||||
State: strPtr("QUEUED"),
|
||||
State: pointers.Ptr("QUEUED"),
|
||||
},
|
||||
want: store.ListBatchSpecWorkspacesOpts{
|
||||
State: types.BatchSpecWorkspaceExecutionJobStateQueued,
|
||||
|
||||
@ -19,6 +19,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbtest"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/internal/timeutil"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestBulkOperationResolver(t *testing.T) {
|
||||
@ -69,7 +70,7 @@ func TestBulkOperationResolver(t *testing.T) {
|
||||
JobType: btypes.ChangesetJobTypeComment,
|
||||
Payload: btypes.ChangesetJobCommentPayload{Message: "test"},
|
||||
State: btypes.ChangesetJobStateFailed,
|
||||
FailureMessage: strPtr(errorMsg),
|
||||
FailureMessage: pointers.Ptr(errorMsg),
|
||||
StartedAt: now,
|
||||
FinishedAt: now,
|
||||
},
|
||||
@ -93,7 +94,7 @@ func TestBulkOperationResolver(t *testing.T) {
|
||||
JobType: btypes.ChangesetJobTypeComment,
|
||||
Payload: btypes.ChangesetJobCommentPayload{Message: "test"},
|
||||
State: btypes.ChangesetJobStateFailed,
|
||||
FailureMessage: strPtr(errorMsg),
|
||||
FailureMessage: pointers.Ptr(errorMsg),
|
||||
StartedAt: now,
|
||||
FinishedAt: now,
|
||||
},
|
||||
@ -116,7 +117,7 @@ func TestBulkOperationResolver(t *testing.T) {
|
||||
Errors: []*apitest.ChangesetJobError{
|
||||
{
|
||||
Changeset: &apitest.Changeset{ID: string(bgql.MarshalChangesetID(changeset1.ID))},
|
||||
Error: strPtr(errorMsg),
|
||||
Error: pointers.Ptr(errorMsg),
|
||||
},
|
||||
{
|
||||
Changeset: &apitest.Changeset{ID: string(bgql.MarshalChangesetID(changeset3.ID))},
|
||||
|
||||
@ -7,9 +7,11 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
|
||||
"github.com/sourcegraph/log/logtest"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
@ -186,9 +188,6 @@ func TestRewirerMappings(t *testing.T) {
|
||||
|
||||
rw.resolvers[mapping] = resolver
|
||||
}
|
||||
opPtr := func(op btypes.ReconcilerOperation) *btypes.ReconcilerOperation {
|
||||
return &op
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("Page", func(t *testing.T) {
|
||||
@ -296,7 +295,7 @@ func TestRewirerMappings(t *testing.T) {
|
||||
},
|
||||
"non-existent op": {
|
||||
opts: rewirerMappingPageOpts{
|
||||
Op: opPtr(btypes.ReconcilerOperationClose),
|
||||
Op: pointers.Ptr(btypes.ReconcilerOperationClose),
|
||||
},
|
||||
want: rewirerMappingPage{
|
||||
Mappings: btypes.RewirerMappings{},
|
||||
@ -305,7 +304,7 @@ func TestRewirerMappings(t *testing.T) {
|
||||
},
|
||||
"extant op, no limit": {
|
||||
opts: rewirerMappingPageOpts{
|
||||
Op: opPtr(btypes.ReconcilerOperationPublish),
|
||||
Op: pointers.Ptr(btypes.ReconcilerOperationPublish),
|
||||
},
|
||||
want: rewirerMappingPage{
|
||||
Mappings: btypes.RewirerMappings{publishA, publishB},
|
||||
@ -315,7 +314,7 @@ func TestRewirerMappings(t *testing.T) {
|
||||
"extant op, high limit": {
|
||||
opts: rewirerMappingPageOpts{
|
||||
LimitOffset: &database.LimitOffset{Limit: 5},
|
||||
Op: opPtr(btypes.ReconcilerOperationPublish),
|
||||
Op: pointers.Ptr(btypes.ReconcilerOperationPublish),
|
||||
},
|
||||
want: rewirerMappingPage{
|
||||
Mappings: btypes.RewirerMappings{publishA, publishB},
|
||||
@ -325,7 +324,7 @@ func TestRewirerMappings(t *testing.T) {
|
||||
"extant op, low limit": {
|
||||
opts: rewirerMappingPageOpts{
|
||||
LimitOffset: &database.LimitOffset{Limit: 1},
|
||||
Op: opPtr(btypes.ReconcilerOperationPublish),
|
||||
Op: pointers.Ptr(btypes.ReconcilerOperationPublish),
|
||||
},
|
||||
want: rewirerMappingPage{
|
||||
Mappings: btypes.RewirerMappings{publishA},
|
||||
@ -335,7 +334,7 @@ func TestRewirerMappings(t *testing.T) {
|
||||
"extant op, low limit and offset": {
|
||||
opts: rewirerMappingPageOpts{
|
||||
LimitOffset: &database.LimitOffset{Limit: 1, Offset: 1},
|
||||
Op: opPtr(btypes.ReconcilerOperationPublish),
|
||||
Op: pointers.Ptr(btypes.ReconcilerOperationPublish),
|
||||
},
|
||||
want: rewirerMappingPage{
|
||||
Mappings: btypes.RewirerMappings{publishB},
|
||||
@ -374,7 +373,7 @@ func TestRewirerMappings(t *testing.T) {
|
||||
})
|
||||
|
||||
if _, err := rmf.Page(ctx, rewirerMappingPageOpts{
|
||||
Op: opPtr(btypes.ReconcilerOperationClose),
|
||||
Op: pointers.Ptr(btypes.ReconcilerOperationClose),
|
||||
}); err == nil {
|
||||
t.Error("unexpected nil error")
|
||||
}
|
||||
|
||||
@ -247,7 +247,3 @@ func pruneSiteCredentials(t *testing.T, bstore *store.Store) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func strPtr(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
@ -43,6 +43,7 @@ import (
|
||||
batcheslib "github.com/sourcegraph/sourcegraph/lib/batches"
|
||||
"github.com/sourcegraph/sourcegraph/lib/batches/overridable"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestNullIDResilience(t *testing.T) {
|
||||
@ -1643,7 +1644,7 @@ func TestListChangesetOptsFromArgs(t *testing.T) {
|
||||
haveCheckStates := []string{"PENDING", "INVALID"}
|
||||
wantReviewStates := []btypes.ChangesetReviewState{"APPROVED", "INVALID"}
|
||||
wantCheckStates := []btypes.ChangesetCheckState{"PENDING", "INVALID"}
|
||||
truePtr := func() *bool { val := true; return &val }()
|
||||
truePtr := pointers.Ptr(true)
|
||||
wantSearches := []search.TextSearchTerm{{Term: "foo"}, {Term: "bar", Not: true}}
|
||||
var batchChangeID int64 = 1
|
||||
var repoID api.RepoID = 123
|
||||
@ -1674,7 +1675,7 @@ func TestListChangesetOptsFromArgs(t *testing.T) {
|
||||
// Setting state is safe and transferred to opts.
|
||||
{
|
||||
args: &graphqlbackend.ListChangesetsArgs{
|
||||
State: stringPtr(string(haveStates[0])),
|
||||
State: pointers.Ptr(string(haveStates[0])),
|
||||
},
|
||||
wantSafe: true,
|
||||
wantParsed: store.ListChangesetsOpts{
|
||||
@ -1684,7 +1685,7 @@ func TestListChangesetOptsFromArgs(t *testing.T) {
|
||||
// Setting invalid state fails.
|
||||
{
|
||||
args: &graphqlbackend.ListChangesetsArgs{
|
||||
State: stringPtr(string(haveStates[1])),
|
||||
State: pointers.Ptr(string(haveStates[1])),
|
||||
},
|
||||
wantErr: "changeset state not valid",
|
||||
},
|
||||
@ -1732,7 +1733,7 @@ func TestListChangesetOptsFromArgs(t *testing.T) {
|
||||
// Setting a positive search.
|
||||
{
|
||||
args: &graphqlbackend.ListChangesetsArgs{
|
||||
Search: stringPtr("foo"),
|
||||
Search: pointers.Ptr("foo"),
|
||||
},
|
||||
wantSafe: false,
|
||||
wantParsed: store.ListChangesetsOpts{
|
||||
@ -1742,7 +1743,7 @@ func TestListChangesetOptsFromArgs(t *testing.T) {
|
||||
// Setting a negative search.
|
||||
{
|
||||
args: &graphqlbackend.ListChangesetsArgs{
|
||||
Search: stringPtr("-bar"),
|
||||
Search: pointers.Ptr("-bar"),
|
||||
},
|
||||
wantSafe: false,
|
||||
wantParsed: store.ListChangesetsOpts{
|
||||
@ -2888,8 +2889,6 @@ query($includeLocallyExecutedSpecs: Boolean!) {
|
||||
}
|
||||
`
|
||||
|
||||
func stringPtr(s string) *string { return &s }
|
||||
|
||||
func assignBatchChangesWritePermissionToUser(ctx context.Context, t *testing.T, db database.DB, userID int32) (*types.Role, *types.Permission) {
|
||||
role := bt.CreateTestRole(ctx, t, db, "TEST-ROLE-1")
|
||||
bt.AssignRoleToUser(ctx, t, db, userID, role.ID)
|
||||
|
||||
@ -19,6 +19,7 @@ go_library(
|
||||
"//internal/httpcli",
|
||||
"//internal/search/job/jobutil",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"@com_github_graph_gophers_graphql_go//:graphql-go",
|
||||
"@com_github_graph_gophers_graphql_go//relay",
|
||||
"@com_github_sourcegraph_log//:log",
|
||||
|
||||
@ -21,6 +21,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/httpcli"
|
||||
"github.com/sourcegraph/sourcegraph/internal/search/job/jobutil"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
// NewResolver returns a new Resolver that uses the given database
|
||||
@ -71,7 +72,7 @@ func (r *Resolver) Monitors(ctx context.Context, userID int32, args *graphqlback
|
||||
|
||||
ms, err := r.db.CodeMonitors().ListMonitors(ctx, edb.ListMonitorsOpts{
|
||||
UserID: &userID,
|
||||
First: intPtr(int(newArgs.First)),
|
||||
First: pointers.Ptr(int(newArgs.First)),
|
||||
After: intPtrToInt64Ptr(after),
|
||||
})
|
||||
if err != nil {
|
||||
@ -890,7 +891,7 @@ func (q *monitorQuery) Events(ctx context.Context, args *graphqlbackend.ListEven
|
||||
}
|
||||
es, err := q.db.CodeMonitors().ListQueryTriggerJobs(ctx, edb.ListTriggerJobsOpts{
|
||||
QueryID: &q.QueryTrigger.ID,
|
||||
First: intPtr(int(args.First)),
|
||||
First: pointers.Ptr(int(args.First)),
|
||||
After: intPtrToInt64Ptr(after),
|
||||
})
|
||||
if err != nil {
|
||||
@ -1063,7 +1064,7 @@ func (m *monitorEmail) Recipients(ctx context.Context, args *graphqlbackend.List
|
||||
}
|
||||
ms, err := m.db.CodeMonitors().ListRecipients(ctx, edb.ListRecipientsOpts{
|
||||
EmailID: &m.EmailAction.ID,
|
||||
First: intPtr(int(args.First)),
|
||||
First: pointers.Ptr(int(args.First)),
|
||||
After: intPtrToInt64Ptr(after),
|
||||
})
|
||||
if err != nil {
|
||||
@ -1125,9 +1126,9 @@ func (m *monitorEmail) Events(ctx context.Context, args *graphqlbackend.ListEven
|
||||
}
|
||||
|
||||
ajs, err := m.db.CodeMonitors().ListActionJobs(ctx, edb.ListActionJobsOpts{
|
||||
EmailID: intPtr(int(m.EmailAction.ID)),
|
||||
EmailID: pointers.Ptr(int(m.EmailAction.ID)),
|
||||
TriggerEventID: m.triggerEventID,
|
||||
First: intPtr(int(args.First)),
|
||||
First: pointers.Ptr(int(args.First)),
|
||||
After: after,
|
||||
})
|
||||
if err != nil {
|
||||
@ -1135,7 +1136,7 @@ func (m *monitorEmail) Events(ctx context.Context, args *graphqlbackend.ListEven
|
||||
}
|
||||
|
||||
totalCount, err := m.db.CodeMonitors().CountActionJobs(ctx, edb.ListActionJobsOpts{
|
||||
EmailID: intPtr(int(m.EmailAction.ID)),
|
||||
EmailID: pointers.Ptr(int(m.EmailAction.ID)),
|
||||
TriggerEventID: m.triggerEventID,
|
||||
})
|
||||
if err != nil {
|
||||
@ -1181,9 +1182,9 @@ func (m *monitorWebhook) Events(ctx context.Context, args *graphqlbackend.ListEv
|
||||
}
|
||||
|
||||
ajs, err := m.db.CodeMonitors().ListActionJobs(ctx, edb.ListActionJobsOpts{
|
||||
WebhookID: intPtr(int(m.WebhookAction.ID)),
|
||||
WebhookID: pointers.Ptr(int(m.WebhookAction.ID)),
|
||||
TriggerEventID: m.triggerEventID,
|
||||
First: intPtr(int(args.First)),
|
||||
First: pointers.Ptr(int(args.First)),
|
||||
After: after,
|
||||
})
|
||||
if err != nil {
|
||||
@ -1191,7 +1192,7 @@ func (m *monitorWebhook) Events(ctx context.Context, args *graphqlbackend.ListEv
|
||||
}
|
||||
|
||||
totalCount, err := m.db.CodeMonitors().CountActionJobs(ctx, edb.ListActionJobsOpts{
|
||||
WebhookID: intPtr(int(m.WebhookAction.ID)),
|
||||
WebhookID: pointers.Ptr(int(m.WebhookAction.ID)),
|
||||
TriggerEventID: m.triggerEventID,
|
||||
})
|
||||
if err != nil {
|
||||
@ -1237,9 +1238,9 @@ func (m *monitorSlackWebhook) Events(ctx context.Context, args *graphqlbackend.L
|
||||
}
|
||||
|
||||
ajs, err := m.db.CodeMonitors().ListActionJobs(ctx, edb.ListActionJobsOpts{
|
||||
SlackWebhookID: intPtr(int(m.SlackWebhookAction.ID)),
|
||||
SlackWebhookID: pointers.Ptr(int(m.SlackWebhookAction.ID)),
|
||||
TriggerEventID: m.triggerEventID,
|
||||
First: intPtr(int(args.First)),
|
||||
First: pointers.Ptr(int(args.First)),
|
||||
After: after,
|
||||
})
|
||||
if err != nil {
|
||||
@ -1247,7 +1248,7 @@ func (m *monitorSlackWebhook) Events(ctx context.Context, args *graphqlbackend.L
|
||||
}
|
||||
|
||||
totalCount, err := m.db.CodeMonitors().CountActionJobs(ctx, edb.ListActionJobsOpts{
|
||||
SlackWebhookID: intPtr(int(m.SlackWebhookAction.ID)),
|
||||
SlackWebhookID: pointers.Ptr(int(m.SlackWebhookAction.ID)),
|
||||
TriggerEventID: m.triggerEventID,
|
||||
})
|
||||
if err != nil {
|
||||
@ -1260,7 +1261,6 @@ func (m *monitorSlackWebhook) Events(ctx context.Context, args *graphqlbackend.L
|
||||
return &monitorActionEventConnection{events: events, totalCount: int32(totalCount)}, nil
|
||||
}
|
||||
|
||||
func intPtr(i int) *int { return &i }
|
||||
func intPtrToInt64Ptr(i *int) *int64 {
|
||||
if i == nil {
|
||||
return nil
|
||||
|
||||
@ -45,6 +45,7 @@ go_library(
|
||||
"//internal/slack",
|
||||
"//internal/types",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"@com_github_derision_test_glock//:glock",
|
||||
"@com_github_gomodule_redigo//redis",
|
||||
"@com_github_google_uuid//:uuid",
|
||||
@ -99,6 +100,7 @@ go_test(
|
||||
"//internal/timeutil",
|
||||
"//internal/types",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"//schema",
|
||||
"@com_github_derision_test_glock//:glock",
|
||||
"@com_github_gomodule_redigo//redis",
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/errcode"
|
||||
dbtypes "github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
type ErrDotcomUserNotFound struct {
|
||||
@ -179,18 +180,18 @@ func getCompletionsRateLimit(ctx context.Context, db database.DB, userID int32,
|
||||
switch scope {
|
||||
case types.CompletionsFeatureChat:
|
||||
if cfg.Completions != nil && cfg.Completions.PerUserDailyLimit > 0 {
|
||||
limit = iPtr(cfg.Completions.PerUserDailyLimit)
|
||||
limit = pointers.Ptr(cfg.Completions.PerUserDailyLimit)
|
||||
}
|
||||
case types.CompletionsFeatureCode:
|
||||
if cfg.Completions != nil && cfg.Completions.PerUserCodeCompletionsDailyLimit > 0 {
|
||||
limit = iPtr(cfg.Completions.PerUserCodeCompletionsDailyLimit)
|
||||
limit = pointers.Ptr(cfg.Completions.PerUserCodeCompletionsDailyLimit)
|
||||
}
|
||||
default:
|
||||
return licensing.CodyGatewayRateLimit{}, graphqlbackend.CodyGatewayRateLimitSourcePlan, errors.Newf("unknown scope: %s", scope)
|
||||
}
|
||||
}
|
||||
if limit == nil {
|
||||
limit = iPtr(0)
|
||||
limit = pointers.Ptr(0)
|
||||
}
|
||||
return licensing.CodyGatewayRateLimit{
|
||||
AllowedModels: allowedModels(scope),
|
||||
@ -209,7 +210,3 @@ func allowedModels(scope types.CompletionsFeature) []string {
|
||||
return []string{}
|
||||
}
|
||||
}
|
||||
|
||||
func iPtr(i int) *int {
|
||||
return &i
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/featureflag"
|
||||
"github.com/sourcegraph/sourcegraph/internal/hashutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
"github.com/sourcegraph/sourcegraph/schema"
|
||||
)
|
||||
|
||||
@ -59,9 +60,9 @@ func TestCodyGatewayDotcomUserResolver(t *testing.T) {
|
||||
// User with rate limit overrides
|
||||
overrideUser, err := db.Users().Create(ctx, database.NewUser{Username: "override", EmailIsVerified: true, Email: "override@test.com"})
|
||||
require.NoError(t, err)
|
||||
err = db.Users().SetChatCompletionsQuota(context.Background(), overrideUser.ID, iPtr(chatOverrideLimit))
|
||||
err = db.Users().SetChatCompletionsQuota(context.Background(), overrideUser.ID, pointers.Ptr(chatOverrideLimit))
|
||||
require.NoError(t, err)
|
||||
err = db.Users().SetCodeCompletionsQuota(context.Background(), overrideUser.ID, iPtr(codeOverrideLimit))
|
||||
err = db.Users().SetCodeCompletionsQuota(context.Background(), overrideUser.ID, pointers.Ptr(codeOverrideLimit))
|
||||
require.NoError(t, err)
|
||||
|
||||
tests := []struct {
|
||||
@ -218,10 +219,6 @@ func TestCodyGatewayDotcomUserResolverRequestAccess(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func iPtr(i int) *int {
|
||||
return &i
|
||||
}
|
||||
|
||||
func makeGatewayToken(apiToken string) string {
|
||||
tokenBytes, _ := hex.DecodeString(strings.TrimPrefix(apiToken, "sgp_"))
|
||||
return "sgd_" + hex.EncodeToString(hashutil.ToSHA256Bytes(hashutil.ToSHA256Bytes(tokenBytes)))
|
||||
|
||||
@ -18,6 +18,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/redispool"
|
||||
"github.com/sourcegraph/sourcegraph/internal/slack"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
const licenseAnomalyCheckKey = "license_anomaly_check"
|
||||
@ -70,10 +71,6 @@ func maybeCheckAnomalies(logger log.Logger, db database.DB, client slackClient,
|
||||
}
|
||||
}
|
||||
|
||||
func boolPtr(b bool) *bool {
|
||||
return &b
|
||||
}
|
||||
|
||||
// checkAnomalies loops through all current subscriptions and triggers a check for each subscription
|
||||
func checkAnomalies(logger log.Logger, db database.DB, clock glock.Clock, client slackClient) {
|
||||
if conf.Get().Dotcom == nil || conf.Get().Dotcom.SlackLicenseAnomallyWebhook == "" {
|
||||
@ -100,8 +97,8 @@ func checkSubscriptionAnomalies(ctx context.Context, logger log.Logger, db datab
|
||||
licenses, err := dbLicenses{db: db}.List(ctx, dbLicensesListOptions{
|
||||
ProductSubscriptionID: sub.ID,
|
||||
WithSiteIDsOnly: true,
|
||||
Expired: boolPtr(false),
|
||||
Revoked: boolPtr(false),
|
||||
Expired: pointers.Ptr(false),
|
||||
Revoked: pointers.Ptr(false),
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error("error listing licenses", log.String("subscription", sub.ID), log.Error(err))
|
||||
|
||||
@ -18,13 +18,10 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbtest"
|
||||
"github.com/sourcegraph/sourcegraph/internal/redispool"
|
||||
"github.com/sourcegraph/sourcegraph/internal/slack"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
"github.com/sourcegraph/sourcegraph/schema"
|
||||
)
|
||||
|
||||
func int32Ptr(n int32) *int32 {
|
||||
return &n
|
||||
}
|
||||
|
||||
func TestMaybeCheckAnomalies(t *testing.T) {
|
||||
logger := logtest.Scoped(t)
|
||||
db := database.NewMockDB()
|
||||
@ -108,7 +105,7 @@ func TestCheckAnomalies(t *testing.T) {
|
||||
}
|
||||
mocks.licenses.List = func(ctx context.Context, opt dbLicensesListOptions) ([]*dbLicense, error) {
|
||||
if opt.ProductSubscriptionID == sub2ID {
|
||||
return []*dbLicense{{ID: licenseID, LicenseKey: "key", ProductSubscriptionID: opt.ProductSubscriptionID, SiteID: &siteID, LicenseVersion: int32Ptr(2)}}, nil
|
||||
return []*dbLicense{{ID: licenseID, LicenseKey: "key", ProductSubscriptionID: opt.ProductSubscriptionID, SiteID: &siteID, LicenseVersion: pointers.Ptr(int32(2))}}, nil
|
||||
}
|
||||
return []*dbLicense{}, nil
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/internal/licensing"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestNewLicenseCheckHandler(t *testing.T) {
|
||||
@ -23,7 +24,6 @@ func TestNewLicenseCheckHandler(t *testing.T) {
|
||||
token := licensing.GenerateHashedLicenseKeyAccessToken(licenseKey)
|
||||
return &token
|
||||
}
|
||||
strPtr := func(s string) *string { return &s }
|
||||
now := time.Now()
|
||||
hourAgo := now.Add(-1 * time.Hour)
|
||||
|
||||
@ -44,7 +44,7 @@ func TestNewLicenseCheckHandler(t *testing.T) {
|
||||
assignedLicense := dbLicense{
|
||||
LicenseKey: "assigned-license-key",
|
||||
LicenseCheckToken: makeToken("assigned-site-id-token"),
|
||||
SiteID: strPtr("C2582A60-573C-4EBC-BDD4-BC57A73CF010"), // uppercase to test case sensitivity
|
||||
SiteID: pointers.Ptr("C2582A60-573C-4EBC-BDD4-BC57A73CF010"), // uppercase to test case sensitivity
|
||||
}
|
||||
licenses := []dbLicense{
|
||||
validLicense,
|
||||
|
||||
@ -17,6 +17,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbtest"
|
||||
"github.com/sourcegraph/sourcegraph/internal/timeutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestProductLicenses_Create(t *testing.T) {
|
||||
@ -298,37 +299,37 @@ func TestProductLicenses_List(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "expired only",
|
||||
opts: dbLicensesListOptions{Expired: boolPtr(true)},
|
||||
opts: dbLicensesListOptions{Expired: pointers.Ptr(true)},
|
||||
expectedCount: 1,
|
||||
},
|
||||
{
|
||||
name: "non expired only",
|
||||
opts: dbLicensesListOptions{Expired: boolPtr(false)},
|
||||
opts: dbLicensesListOptions{Expired: pointers.Ptr(false)},
|
||||
expectedCount: len(licenses) - 1,
|
||||
},
|
||||
{
|
||||
name: "revoked only",
|
||||
opts: dbLicensesListOptions{Revoked: boolPtr(true)},
|
||||
opts: dbLicensesListOptions{Revoked: pointers.Ptr(true)},
|
||||
expectedCount: 1,
|
||||
},
|
||||
{
|
||||
name: "non revoked only",
|
||||
opts: dbLicensesListOptions{Revoked: boolPtr(false)},
|
||||
opts: dbLicensesListOptions{Revoked: pointers.Ptr(false)},
|
||||
expectedCount: len(licenses) - 1,
|
||||
},
|
||||
{
|
||||
name: "non revoked and non expired",
|
||||
opts: dbLicensesListOptions{
|
||||
Revoked: boolPtr(false),
|
||||
Expired: boolPtr(false),
|
||||
Revoked: pointers.Ptr(false),
|
||||
Expired: pointers.Ptr(false),
|
||||
},
|
||||
expectedCount: len(licenses) - 2,
|
||||
},
|
||||
{
|
||||
name: "non revoked and non expired with site ID",
|
||||
opts: dbLicensesListOptions{
|
||||
Revoked: boolPtr(false),
|
||||
Expired: boolPtr(false),
|
||||
Revoked: pointers.Ptr(false),
|
||||
Expired: pointers.Ptr(false),
|
||||
WithSiteIDsOnly: true,
|
||||
},
|
||||
expectedCount: 1,
|
||||
|
||||
@ -54,6 +54,7 @@ go_test(
|
||||
"//internal/workerutil/dbworker/store",
|
||||
"//internal/workerutil/dbworker/store/mocks",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"@com_github_gorilla_mux//:mux",
|
||||
"@com_github_prometheus_client_model//go",
|
||||
"@com_github_prometheus_common//expfmt",
|
||||
|
||||
@ -27,6 +27,7 @@ import (
|
||||
dbworkerstore "github.com/sourcegraph/sourcegraph/internal/workerutil/dbworker/store"
|
||||
dbworkerstoremocks "github.com/sourcegraph/sourcegraph/internal/workerutil/dbworker/store/mocks"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestHandler_Name(t *testing.T) {
|
||||
@ -296,9 +297,9 @@ func TestHandler_HandleAddExecutionLogEntry(t *testing.T) {
|
||||
Key: "foo",
|
||||
Command: []string{"faz", "baz"},
|
||||
StartTime: startTime,
|
||||
ExitCode: newIntPtr(0),
|
||||
ExitCode: pointers.Ptr(0),
|
||||
Out: "done",
|
||||
DurationMs: newIntPtr(100),
|
||||
DurationMs: pointers.Ptr(100),
|
||||
},
|
||||
mockStore.AddExecutionLogEntryFunc.History()[0].Arg2,
|
||||
)
|
||||
@ -405,9 +406,9 @@ func TestHandler_HandleUpdateExecutionLogEntry(t *testing.T) {
|
||||
Key: "foo",
|
||||
Command: []string{"faz", "baz"},
|
||||
StartTime: startTime,
|
||||
ExitCode: newIntPtr(0),
|
||||
ExitCode: pointers.Ptr(0),
|
||||
Out: "done",
|
||||
DurationMs: newIntPtr(100),
|
||||
DurationMs: pointers.Ptr(100),
|
||||
},
|
||||
mockStore.UpdateExecutionLogEntryFunc.History()[0].Arg3,
|
||||
)
|
||||
@ -977,7 +978,3 @@ func (r testRecord) RecordID() int { return r.id }
|
||||
func (r testRecord) RecordUID() string {
|
||||
return strconv.Itoa(r.id)
|
||||
}
|
||||
|
||||
func newIntPtr(i int) *int {
|
||||
return &i
|
||||
}
|
||||
|
||||
@ -76,6 +76,7 @@ go_test(
|
||||
"//internal/observation",
|
||||
"//internal/timeutil",
|
||||
"//internal/types",
|
||||
"//lib/pointers",
|
||||
"//schema",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
"@com_github_sourcegraph_log//:log",
|
||||
|
||||
@ -21,6 +21,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/extsvc"
|
||||
"github.com/sourcegraph/sourcegraph/internal/timeutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
"github.com/sourcegraph/sourcegraph/schema"
|
||||
)
|
||||
|
||||
@ -238,8 +239,6 @@ func clock() time.Time {
|
||||
return time.Unix(0, atomic.LoadInt64(&now))
|
||||
}
|
||||
|
||||
func toIntPtr(n int) *int { return &n }
|
||||
|
||||
func TestOldestUserPermissionsBatchSize(t *testing.T) {
|
||||
t.Cleanup(func() { conf.Mock(nil) })
|
||||
|
||||
@ -254,17 +253,17 @@ func TestOldestUserPermissionsBatchSize(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "uses number from config",
|
||||
configure: toIntPtr(5),
|
||||
configure: pointers.Ptr(5),
|
||||
want: 5,
|
||||
},
|
||||
{
|
||||
name: "can be set to 0",
|
||||
configure: toIntPtr(0),
|
||||
configure: pointers.Ptr(0),
|
||||
want: 0,
|
||||
},
|
||||
{
|
||||
name: "negative numbers result in default",
|
||||
configure: toIntPtr(-248),
|
||||
configure: pointers.Ptr(-248),
|
||||
want: 10,
|
||||
},
|
||||
}
|
||||
@ -293,17 +292,17 @@ func TestOldestRepoPermissionsBatchSize(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "uses number from config",
|
||||
configure: toIntPtr(5),
|
||||
configure: pointers.Ptr(5),
|
||||
want: 5,
|
||||
},
|
||||
{
|
||||
name: "can be set to 0",
|
||||
configure: toIntPtr(0),
|
||||
configure: pointers.Ptr(0),
|
||||
want: 0,
|
||||
},
|
||||
{
|
||||
name: "negative numbers result in default",
|
||||
configure: toIntPtr(-248),
|
||||
configure: pointers.Ptr(-248),
|
||||
want: 10,
|
||||
},
|
||||
}
|
||||
|
||||
@ -48,6 +48,7 @@ go_test(
|
||||
"//internal/observation",
|
||||
"//internal/version",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"//schema",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
"@com_github_hexops_autogold_v2//:autogold",
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/featureflag"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
|
||||
"github.com/lib/pq"
|
||||
|
||||
@ -130,25 +131,21 @@ func TestHandlerLoadsEvents(t *testing.T) {
|
||||
flags := make(map[string]bool)
|
||||
flags["testflag"] = true
|
||||
|
||||
ptr := func(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
want := []*database.Event{
|
||||
{
|
||||
Name: "event1",
|
||||
UserID: 1,
|
||||
Source: "test",
|
||||
EvaluatedFlagSet: flags,
|
||||
DeviceID: ptr("device-1"),
|
||||
InsertID: ptr("insert-1"),
|
||||
DeviceID: pointers.Ptr("device-1"),
|
||||
InsertID: pointers.Ptr("insert-1"),
|
||||
},
|
||||
{
|
||||
Name: "event2",
|
||||
UserID: 2,
|
||||
Source: "test",
|
||||
DeviceID: ptr("device-2"),
|
||||
InsertID: ptr("insert-2"),
|
||||
DeviceID: pointers.Ptr("device-2"),
|
||||
InsertID: pointers.Ptr("insert-2"),
|
||||
},
|
||||
}
|
||||
err := db.EventLogs().BulkInsert(ctx, want)
|
||||
@ -248,25 +245,21 @@ func TestHandlerLoadsEventsWithBookmarkState(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db := database.NewDB(logger, dbHandle)
|
||||
|
||||
ptr := func(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
initAllowedEvents(t, db, []string{"event1", "event2", "event4"})
|
||||
testData := []*database.Event{
|
||||
{
|
||||
Name: "event1",
|
||||
UserID: 1,
|
||||
Source: "test",
|
||||
DeviceID: ptr("device"),
|
||||
InsertID: ptr("insert"),
|
||||
DeviceID: pointers.Ptr("device"),
|
||||
InsertID: pointers.Ptr("insert"),
|
||||
},
|
||||
{
|
||||
Name: "event2",
|
||||
UserID: 2,
|
||||
Source: "test",
|
||||
DeviceID: ptr("device"),
|
||||
InsertID: ptr("insert"),
|
||||
DeviceID: pointers.Ptr("device"),
|
||||
InsertID: pointers.Ptr("insert"),
|
||||
},
|
||||
}
|
||||
err := db.EventLogs().BulkInsert(ctx, testData)
|
||||
@ -362,32 +355,28 @@ func TestHandlerLoadsEventsWithAllowlist(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db := database.NewDB(logger, dbHandle)
|
||||
|
||||
ptr := func(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
initAllowedEvents(t, db, []string{"allowed"})
|
||||
testData := []*database.Event{
|
||||
{
|
||||
Name: "allowed",
|
||||
UserID: 1,
|
||||
Source: "test",
|
||||
DeviceID: ptr("device"),
|
||||
InsertID: ptr("insert"),
|
||||
DeviceID: pointers.Ptr("device"),
|
||||
InsertID: pointers.Ptr("insert"),
|
||||
},
|
||||
{
|
||||
Name: "not-allowed",
|
||||
UserID: 2,
|
||||
Source: "test",
|
||||
DeviceID: ptr("device"),
|
||||
InsertID: ptr("insert"),
|
||||
DeviceID: pointers.Ptr("device"),
|
||||
InsertID: pointers.Ptr("insert"),
|
||||
},
|
||||
{
|
||||
Name: "allowed",
|
||||
UserID: 3,
|
||||
Source: "test",
|
||||
DeviceID: ptr("device"),
|
||||
InsertID: ptr("insert"),
|
||||
DeviceID: pointers.Ptr("device"),
|
||||
InsertID: pointers.Ptr("insert"),
|
||||
},
|
||||
}
|
||||
err := db.EventLogs().BulkInsert(ctx, testData)
|
||||
@ -492,10 +481,6 @@ func TestBuildBigQueryObject(t *testing.T) {
|
||||
flags := make(featureflag.EvaluatedFlagSet)
|
||||
flags["testflag"] = true
|
||||
|
||||
ptr := func(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
event := &database.Event{
|
||||
ID: 1,
|
||||
Name: "GREAT_EVENT",
|
||||
@ -507,12 +492,12 @@ func TestBuildBigQueryObject(t *testing.T) {
|
||||
Version: "1.1.1",
|
||||
Timestamp: atTime,
|
||||
EvaluatedFlagSet: flags,
|
||||
CohortID: ptr("cohort1"),
|
||||
FirstSourceURL: ptr("first_source_url"),
|
||||
LastSourceURL: ptr("last_source_url"),
|
||||
Referrer: ptr("reff"),
|
||||
DeviceID: ptr("devid"),
|
||||
InsertID: ptr("insertid"),
|
||||
CohortID: pointers.Ptr("cohort1"),
|
||||
FirstSourceURL: pointers.Ptr("first_source_url"),
|
||||
LastSourceURL: pointers.Ptr("last_source_url"),
|
||||
Referrer: pointers.Ptr("reff"),
|
||||
DeviceID: pointers.Ptr("devid"),
|
||||
InsertID: pointers.Ptr("insertid"),
|
||||
}
|
||||
|
||||
metadata := &instanceMetadata{
|
||||
|
||||
1
enterprise/dev/deployment-notifier/BUILD.bazel
generated
1
enterprise/dev/deployment-notifier/BUILD.bazel
generated
@ -44,6 +44,7 @@ go_test(
|
||||
deps = [
|
||||
"//internal/httptestutil",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"@com_github_dnaeon_go_vcr//cassette",
|
||||
"@com_github_google_go_github_v41//github",
|
||||
"@com_github_stretchr_testify//assert",
|
||||
|
||||
@ -7,20 +7,18 @@ import (
|
||||
"github.com/google/go-github/v41/github"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func intPtr(v int) *int {
|
||||
return &v
|
||||
}
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestGenerateDeploymentTrace(t *testing.T) {
|
||||
trace, err := GenerateDeploymentTrace(&DeploymentReport{
|
||||
Environment: "preprepod",
|
||||
DeployedAt: time.RFC822Z,
|
||||
PullRequests: []*github.PullRequest{
|
||||
{Number: intPtr(32996)},
|
||||
{Number: intPtr(32871)},
|
||||
{Number: intPtr(32767)},
|
||||
{Number: pointers.Ptr(32996)},
|
||||
{Number: pointers.Ptr(32871)},
|
||||
{Number: pointers.Ptr(32767)},
|
||||
},
|
||||
ServicesPerPullRequest: map[int][]string{
|
||||
32996: {"frontend", "gitserver", "worker"},
|
||||
|
||||
@ -75,6 +75,7 @@ go_test(
|
||||
"//lib/batches",
|
||||
"//lib/batches/git",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
"@com_github_sourcegraph_log//logtest",
|
||||
"@com_github_stretchr_testify//assert",
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
bt "github.com/sourcegraph/sourcegraph/enterprise/internal/batches/testing"
|
||||
btypes "github.com/sourcegraph/sourcegraph/enterprise/internal/batches/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/extsvc"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestDetermineReconcilerPlan(t *testing.T) {
|
||||
@ -86,7 +87,7 @@ func TestDetermineReconcilerPlan(t *testing.T) {
|
||||
currentSpec: &bt.TestSpecOpts{Published: nil},
|
||||
changeset: bt.TestChangesetOpts{
|
||||
PublicationState: btypes.ChangesetPublicationStateUnpublished,
|
||||
UiPublicationState: uiPublicationStatePtr(btypes.ChangesetUiPublicationStateUnpublished),
|
||||
UiPublicationState: pointers.Ptr(btypes.ChangesetUiPublicationStateUnpublished),
|
||||
},
|
||||
wantOperations: Operations{},
|
||||
},
|
||||
@ -95,7 +96,7 @@ func TestDetermineReconcilerPlan(t *testing.T) {
|
||||
currentSpec: &bt.TestSpecOpts{Published: nil},
|
||||
changeset: bt.TestChangesetOpts{
|
||||
PublicationState: btypes.ChangesetPublicationStateUnpublished,
|
||||
UiPublicationState: uiPublicationStatePtr(btypes.ChangesetUiPublicationStateDraft),
|
||||
UiPublicationState: pointers.Ptr(btypes.ChangesetUiPublicationStateDraft),
|
||||
},
|
||||
wantOperations: Operations{btypes.ReconcilerOperationPush, btypes.ReconcilerOperationPublishDraft},
|
||||
},
|
||||
@ -105,7 +106,7 @@ func TestDetermineReconcilerPlan(t *testing.T) {
|
||||
changeset: bt.TestChangesetOpts{
|
||||
ExternalServiceType: extsvc.TypeBitbucketServer,
|
||||
PublicationState: btypes.ChangesetPublicationStateUnpublished,
|
||||
UiPublicationState: uiPublicationStatePtr(btypes.ChangesetUiPublicationStateDraft),
|
||||
UiPublicationState: pointers.Ptr(btypes.ChangesetUiPublicationStateDraft),
|
||||
},
|
||||
// Cannot draft on an unsupported code host, so this is a no-op.
|
||||
wantOperations: Operations{},
|
||||
@ -115,7 +116,7 @@ func TestDetermineReconcilerPlan(t *testing.T) {
|
||||
currentSpec: &bt.TestSpecOpts{Published: nil},
|
||||
changeset: bt.TestChangesetOpts{
|
||||
PublicationState: btypes.ChangesetPublicationStateUnpublished,
|
||||
UiPublicationState: uiPublicationStatePtr(btypes.ChangesetUiPublicationStatePublished),
|
||||
UiPublicationState: pointers.Ptr(btypes.ChangesetUiPublicationStatePublished),
|
||||
},
|
||||
wantOperations: Operations{btypes.ReconcilerOperationPush, btypes.ReconcilerOperationPublish},
|
||||
},
|
||||
@ -125,7 +126,7 @@ func TestDetermineReconcilerPlan(t *testing.T) {
|
||||
currentSpec: &bt.TestSpecOpts{Published: nil},
|
||||
changeset: bt.TestChangesetOpts{
|
||||
PublicationState: btypes.ChangesetPublicationStatePublished,
|
||||
UiPublicationState: uiPublicationStatePtr(btypes.ChangesetUiPublicationStatePublished),
|
||||
UiPublicationState: pointers.Ptr(btypes.ChangesetUiPublicationStatePublished),
|
||||
},
|
||||
wantOperations: Operations{btypes.ReconcilerOperationUndraft},
|
||||
},
|
||||
@ -135,7 +136,7 @@ func TestDetermineReconcilerPlan(t *testing.T) {
|
||||
currentSpec: &bt.TestSpecOpts{Published: nil},
|
||||
changeset: bt.TestChangesetOpts{
|
||||
PublicationState: btypes.ChangesetPublicationStatePublished,
|
||||
UiPublicationState: uiPublicationStatePtr(btypes.ChangesetUiPublicationStateDraft),
|
||||
UiPublicationState: pointers.Ptr(btypes.ChangesetUiPublicationStateDraft),
|
||||
},
|
||||
// No change to the actual state, so this is a no-op.
|
||||
wantOperations: Operations{},
|
||||
@ -146,7 +147,7 @@ func TestDetermineReconcilerPlan(t *testing.T) {
|
||||
currentSpec: &bt.TestSpecOpts{Published: nil},
|
||||
changeset: bt.TestChangesetOpts{
|
||||
PublicationState: btypes.ChangesetPublicationStatePublished,
|
||||
UiPublicationState: uiPublicationStatePtr(btypes.ChangesetUiPublicationStateUnpublished),
|
||||
UiPublicationState: pointers.Ptr(btypes.ChangesetUiPublicationStateUnpublished),
|
||||
},
|
||||
// We can't unscramble an egg, nor can we unpublish a published
|
||||
// changeset, so this is a no-op.
|
||||
@ -459,7 +460,3 @@ func TestDetermineReconcilerPlan(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func uiPublicationStatePtr(state btypes.ChangesetUiPublicationState) *btypes.ChangesetUiPublicationState {
|
||||
return &state
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
|
||||
btypes "github.com/sourcegraph/sourcegraph/enterprise/internal/batches/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/batches"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestPublicationStateCalculator(t *testing.T) {
|
||||
@ -41,17 +42,17 @@ func TestPublicationStateCalculator(t *testing.T) {
|
||||
},
|
||||
"no published value; unpublished ui": {
|
||||
spec: batches.PublishedValue{Val: nil},
|
||||
ui: uiPublicationStatePtr(btypes.ChangesetUiPublicationStateUnpublished),
|
||||
ui: pointers.Ptr(btypes.ChangesetUiPublicationStateUnpublished),
|
||||
want: want{false, false, true},
|
||||
},
|
||||
"no published value; draft ui": {
|
||||
spec: batches.PublishedValue{Val: nil},
|
||||
ui: uiPublicationStatePtr(btypes.ChangesetUiPublicationStateDraft),
|
||||
ui: pointers.Ptr(btypes.ChangesetUiPublicationStateDraft),
|
||||
want: want{false, true, false},
|
||||
},
|
||||
"no published value; published ui": {
|
||||
spec: batches.PublishedValue{Val: nil},
|
||||
ui: uiPublicationStatePtr(btypes.ChangesetUiPublicationStatePublished),
|
||||
ui: pointers.Ptr(btypes.ChangesetUiPublicationStatePublished),
|
||||
want: want{true, false, false},
|
||||
},
|
||||
} {
|
||||
|
||||
1
enterprise/internal/batches/service/BUILD.bazel
generated
1
enterprise/internal/batches/service/BUILD.bazel
generated
@ -96,6 +96,7 @@ go_test(
|
||||
"//internal/types",
|
||||
"//lib/batches",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
"@com_github_google_go_cmp//cmp/cmpopts",
|
||||
"@com_github_graph_gophers_graphql_go//relay",
|
||||
|
||||
@ -34,6 +34,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/timeutil"
|
||||
batcheslib "github.com/sourcegraph/sourcegraph/lib/batches"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestServicePermissionLevels(t *testing.T) {
|
||||
@ -589,7 +590,7 @@ func TestService(t *testing.T) {
|
||||
NumResets: 0,
|
||||
NumFailures: 0,
|
||||
FailureMessage: nil,
|
||||
PreviousFailureMessage: strPtr(bt.FailedChangesetFailureMessage),
|
||||
PreviousFailureMessage: pointers.Ptr(bt.FailedChangesetFailureMessage),
|
||||
})
|
||||
|
||||
// rs[0] is filtered out
|
||||
@ -3411,5 +3412,3 @@ func assertNoAuthError(t *testing.T, err error) {
|
||||
t.Fatalf("got auth error")
|
||||
}
|
||||
}
|
||||
|
||||
func strPtr(s string) *string { return &s }
|
||||
|
||||
1
enterprise/internal/batches/sources/BUILD.bazel
generated
1
enterprise/internal/batches/sources/BUILD.bazel
generated
@ -90,6 +90,7 @@ go_test(
|
||||
"//internal/testutil",
|
||||
"//internal/types",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"//schema",
|
||||
"@com_github_derision_test_go_mockgen//testutil/assert",
|
||||
"@com_github_dnaeon_go_vcr//cassette",
|
||||
|
||||
@ -16,6 +16,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/extsvc/azuredevops"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -709,7 +710,7 @@ func TestAzureDevOpsSource_GetFork(t *testing.T) {
|
||||
return azuredevops.Repository{}, want
|
||||
})
|
||||
|
||||
repo, err := s.GetFork(ctx, upstreamRepo, strPtr("fork"), nil)
|
||||
repo, err := s.GetFork(ctx, upstreamRepo, pointers.Ptr("fork"), nil)
|
||||
assert.Nil(t, repo)
|
||||
assert.NotNil(t, err)
|
||||
assert.ErrorIs(t, err, want)
|
||||
@ -723,7 +724,7 @@ func TestAzureDevOpsSource_GetFork(t *testing.T) {
|
||||
return fork, nil
|
||||
})
|
||||
|
||||
forkRepo, err := s.GetFork(ctx, upstreamRepo, strPtr("fork"), nil)
|
||||
forkRepo, err := s.GetFork(ctx, upstreamRepo, pointers.Ptr("fork"), nil)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, forkRepo)
|
||||
assert.NotEqual(t, forkRepo, upstreamRepo)
|
||||
@ -745,7 +746,7 @@ func TestAzureDevOpsSource_GetFork(t *testing.T) {
|
||||
return azuredevops.Project{}, want
|
||||
})
|
||||
|
||||
repo, err := s.GetFork(ctx, upstreamRepo, strPtr("fork"), nil)
|
||||
repo, err := s.GetFork(ctx, upstreamRepo, pointers.Ptr("fork"), nil)
|
||||
assert.Nil(t, repo)
|
||||
assert.NotNil(t, err)
|
||||
assert.ErrorIs(t, err, want)
|
||||
@ -772,7 +773,7 @@ func TestAzureDevOpsSource_GetFork(t *testing.T) {
|
||||
return azuredevops.Repository{}, want
|
||||
})
|
||||
|
||||
repo, err := s.GetFork(ctx, upstreamRepo, strPtr("fork"), nil)
|
||||
repo, err := s.GetFork(ctx, upstreamRepo, pointers.Ptr("fork"), nil)
|
||||
assert.Nil(t, repo)
|
||||
assert.NotNil(t, err)
|
||||
assert.ErrorIs(t, err, want)
|
||||
@ -814,7 +815,7 @@ func TestAzureDevOpsSource_GetFork(t *testing.T) {
|
||||
return fork, nil
|
||||
})
|
||||
|
||||
forkRepo, err := s.GetFork(ctx, upstreamRepo, strPtr("fork"), nil)
|
||||
forkRepo, err := s.GetFork(ctx, upstreamRepo, pointers.Ptr("fork"), nil)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, forkRepo)
|
||||
assert.NotEqual(t, forkRepo, upstreamRepo)
|
||||
@ -846,7 +847,7 @@ func TestAzureDevOpsSource_GetFork(t *testing.T) {
|
||||
return fork, nil
|
||||
})
|
||||
|
||||
forkRepo, err := s.GetFork(ctx, upstreamRepo, strPtr("fork"), strPtr("special-fork-name"))
|
||||
forkRepo, err := s.GetFork(ctx, upstreamRepo, pointers.Ptr("fork"), pointers.Ptr("special-fork-name"))
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, forkRepo)
|
||||
assert.NotEqual(t, forkRepo, upstreamRepo)
|
||||
|
||||
@ -19,6 +19,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/extsvc/bitbucketcloud"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestNewBitbucketCloudSource(t *testing.T) {
|
||||
@ -609,7 +610,7 @@ func TestBitbucketCloudSource_GetFork(t *testing.T) {
|
||||
return nil, want
|
||||
})
|
||||
|
||||
repo, err := s.GetFork(ctx, upstreamRepo, strPtr("fork"), nil)
|
||||
repo, err := s.GetFork(ctx, upstreamRepo, pointers.Ptr("fork"), nil)
|
||||
assert.Nil(t, repo)
|
||||
assert.NotNil(t, err)
|
||||
assert.ErrorIs(t, err, want)
|
||||
@ -624,7 +625,7 @@ func TestBitbucketCloudSource_GetFork(t *testing.T) {
|
||||
return fork, nil
|
||||
})
|
||||
|
||||
forkRepo, err := s.GetFork(ctx, upstreamRepo, strPtr("fork"), nil)
|
||||
forkRepo, err := s.GetFork(ctx, upstreamRepo, pointers.Ptr("fork"), nil)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, forkRepo)
|
||||
assert.NotEqual(t, forkRepo, upstreamRepo)
|
||||
@ -649,7 +650,7 @@ func TestBitbucketCloudSource_GetFork(t *testing.T) {
|
||||
return nil, want
|
||||
})
|
||||
|
||||
repo, err := s.GetFork(ctx, upstreamRepo, strPtr("fork"), nil)
|
||||
repo, err := s.GetFork(ctx, upstreamRepo, pointers.Ptr("fork"), nil)
|
||||
assert.Nil(t, repo)
|
||||
assert.NotNil(t, err)
|
||||
assert.ErrorIs(t, err, want)
|
||||
@ -742,7 +743,7 @@ func TestBitbucketCloudSource_GetFork(t *testing.T) {
|
||||
return fork, nil
|
||||
})
|
||||
|
||||
forkRepo, err := s.GetFork(ctx, upstreamRepo, strPtr("fork"), nil)
|
||||
forkRepo, err := s.GetFork(ctx, upstreamRepo, pointers.Ptr("fork"), nil)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, forkRepo)
|
||||
assert.NotEqual(t, forkRepo, upstreamRepo)
|
||||
@ -766,7 +767,7 @@ func TestBitbucketCloudSource_GetFork(t *testing.T) {
|
||||
return fork, nil
|
||||
})
|
||||
|
||||
forkRepo, err := s.GetFork(ctx, upstreamRepo, strPtr("fork"), strPtr("special-fork-name"))
|
||||
forkRepo, err := s.GetFork(ctx, upstreamRepo, pointers.Ptr("fork"), pointers.Ptr("special-fork-name"))
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, forkRepo)
|
||||
assert.NotEqual(t, forkRepo, upstreamRepo)
|
||||
|
||||
@ -18,6 +18,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/testutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
"github.com/sourcegraph/sourcegraph/schema"
|
||||
)
|
||||
|
||||
@ -830,7 +831,7 @@ func TestBitbucketServerSource_GetFork(t *testing.T) {
|
||||
cf, save := newClientFactory(t, testName(t))
|
||||
defer save(t)
|
||||
|
||||
svc := newExternalService(t, strPtr("invalid"))
|
||||
svc := newExternalService(t, pointers.Ptr("invalid"))
|
||||
|
||||
ctx := context.Background()
|
||||
bbsSrc, err := NewBitbucketServerSource(ctx, svc, cf)
|
||||
@ -861,7 +862,7 @@ func TestBitbucketServerSource_GetFork(t *testing.T) {
|
||||
bbsSrc, err := NewBitbucketServerSource(ctx, svc, cf)
|
||||
assert.Nil(t, err)
|
||||
|
||||
fork, err := bbsSrc.GetFork(ctx, target, strPtr("~milton"), strPtr("vcr-fork-test-repo"))
|
||||
fork, err := bbsSrc.GetFork(ctx, target, pointers.Ptr("~milton"), pointers.Ptr("vcr-fork-test-repo"))
|
||||
assert.Nil(t, fork)
|
||||
assert.ErrorContains(t, err, "repo is not a fork")
|
||||
})
|
||||
@ -887,7 +888,7 @@ func TestBitbucketServerSource_GetFork(t *testing.T) {
|
||||
bbsSrc, err := NewBitbucketServerSource(ctx, svc, cf)
|
||||
assert.Nil(t, err)
|
||||
|
||||
fork, err := bbsSrc.GetFork(ctx, target, strPtr("~milton"), strPtr("BAT-vcr-fork-test-repo-already-forked"))
|
||||
fork, err := bbsSrc.GetFork(ctx, target, pointers.Ptr("~milton"), pointers.Ptr("BAT-vcr-fork-test-repo-already-forked"))
|
||||
assert.Nil(t, fork)
|
||||
assert.ErrorContains(t, err, "repo was not forked from the given parent")
|
||||
})
|
||||
@ -995,7 +996,7 @@ func TestBitbucketServerSource_GetFork(t *testing.T) {
|
||||
username, err := bbsSrc.client.AuthenticatedUsername(ctx)
|
||||
assert.Nil(t, err)
|
||||
|
||||
fork, err := bbsSrc.GetFork(ctx, target, strPtr("~milton"), strPtr("BAT-vcr-fork-test-repo-already-forked"))
|
||||
fork, err := bbsSrc.GetFork(ctx, target, pointers.Ptr("~milton"), pointers.Ptr("BAT-vcr-fork-test-repo-already-forked"))
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, fork)
|
||||
assert.NotEqual(t, fork, target)
|
||||
@ -1036,7 +1037,7 @@ func TestBitbucketServerSource_GetFork(t *testing.T) {
|
||||
username, err := bbsSrc.client.AuthenticatedUsername(ctx)
|
||||
assert.Nil(t, err)
|
||||
|
||||
fork, err := bbsSrc.GetFork(ctx, target, strPtr("~milton"), strPtr("BAT-vcr-fork-test-repo-not-forked"))
|
||||
fork, err := bbsSrc.GetFork(ctx, target, pointers.Ptr("~milton"), pointers.Ptr("BAT-vcr-fork-test-repo-not-forked"))
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, fork)
|
||||
assert.NotEqual(t, fork, target)
|
||||
@ -1046,5 +1047,3 @@ func TestBitbucketServerSource_GetFork(t *testing.T) {
|
||||
testutil.AssertGolden(t, "testdata/golden/"+name, update(name), fork)
|
||||
})
|
||||
}
|
||||
|
||||
func strPtr(s string) *string { return &s }
|
||||
|
||||
@ -25,6 +25,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/testutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
"github.com/sourcegraph/sourcegraph/schema"
|
||||
)
|
||||
|
||||
@ -558,7 +559,7 @@ func TestGithubSource_GetFork(t *testing.T) {
|
||||
defer save(t)
|
||||
target := newGitHubRepo(urn, tc.target.namespace+"/"+tc.target.name, "123")
|
||||
|
||||
fork, err := src.GetFork(ctx, target, strPtr(tc.fork.namespace), strPtr(tc.fork.name))
|
||||
fork, err := src.GetFork(ctx, target, pointers.Ptr(tc.fork.namespace), pointers.Ptr(tc.fork.name))
|
||||
|
||||
assert.Nil(t, fork)
|
||||
assert.ErrorContains(t, err, tc.err)
|
||||
@ -664,7 +665,7 @@ func TestGithubSource_GetFork(t *testing.T) {
|
||||
var fork *types.Repo
|
||||
var err error
|
||||
if tc.externalNameAndNamespace {
|
||||
fork, err = src.GetFork(ctx, target, strPtr(tc.fork.namespace), strPtr(tc.fork.name))
|
||||
fork, err = src.GetFork(ctx, target, pointers.Ptr(tc.fork.namespace), pointers.Ptr(tc.fork.name))
|
||||
} else {
|
||||
fork, err = src.GetFork(ctx, target, nil, nil)
|
||||
}
|
||||
@ -778,7 +779,7 @@ func TestGithubSource_GetFork(t *testing.T) {
|
||||
forkRepo: &github.Repository{NameWithOwner: org + "/custom-bar", IsFork: true},
|
||||
namespace: &org,
|
||||
wantNamespace: org,
|
||||
name: strPtr("custom-bar"),
|
||||
name: pointers.Ptr("custom-bar"),
|
||||
wantName: "custom-bar",
|
||||
client: &mockGithubClientFork{
|
||||
fork: &github.Repository{NameWithOwner: org + "/custom-bar", IsFork: true},
|
||||
|
||||
@ -23,6 +23,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/testutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
"github.com/sourcegraph/sourcegraph/schema"
|
||||
)
|
||||
|
||||
@ -1507,7 +1508,7 @@ func TestGitlabSource_GetFork(t *testing.T) {
|
||||
ProjectCommon: gitlab.ProjectCommon{ID: 2, PathWithNamespace: org + "/custom-bar"}},
|
||||
namespace: &org,
|
||||
wantNamespace: org,
|
||||
name: strPtr("custom-bar"),
|
||||
name: pointers.Ptr("custom-bar"),
|
||||
wantName: "custom-bar",
|
||||
client: &mockGitlabClientFork{
|
||||
fork: &gitlab.Project{
|
||||
|
||||
1
enterprise/internal/batches/store/BUILD.bazel
generated
1
enterprise/internal/batches/store/BUILD.bazel
generated
@ -124,6 +124,7 @@ go_test(
|
||||
"//lib/batches/execution",
|
||||
"//lib/batches/overridable",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"//schema",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
"@com_github_keegancsmith_sqlf//:sqlf",
|
||||
|
||||
@ -25,6 +25,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types/typestest"
|
||||
batcheslib "github.com/sourcegraph/sourcegraph/lib/batches"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
// Comparing the IDs is good enough, no need to bloat the tests here.
|
||||
@ -1151,10 +1152,6 @@ func testStoreChangesetSpecsCurrentStateAndTextSearch(t *testing.T, ctx context.
|
||||
},
|
||||
})
|
||||
|
||||
statePtr := func(state btypes.ChangesetState) *btypes.ChangesetState {
|
||||
return &state
|
||||
}
|
||||
|
||||
for name, tc := range map[string]struct {
|
||||
opts GetRewirerMappingsOpts
|
||||
want []*btypes.Changeset
|
||||
@ -1162,28 +1159,28 @@ func testStoreChangesetSpecsCurrentStateAndTextSearch(t *testing.T, ctx context.
|
||||
"state and text": {
|
||||
opts: GetRewirerMappingsOpts{
|
||||
TextSearch: []search.TextSearchTerm{{Term: "foo"}},
|
||||
CurrentState: statePtr(btypes.ChangesetStateOpen),
|
||||
CurrentState: pointers.Ptr(btypes.ChangesetStateOpen),
|
||||
},
|
||||
want: []*btypes.Changeset{openFoo},
|
||||
},
|
||||
"state and not text": {
|
||||
opts: GetRewirerMappingsOpts{
|
||||
TextSearch: []search.TextSearchTerm{{Term: "foo", Not: true}},
|
||||
CurrentState: statePtr(btypes.ChangesetStateOpen),
|
||||
CurrentState: pointers.Ptr(btypes.ChangesetStateOpen),
|
||||
},
|
||||
want: []*btypes.Changeset{openBar},
|
||||
},
|
||||
"state match only": {
|
||||
opts: GetRewirerMappingsOpts{
|
||||
TextSearch: []search.TextSearchTerm{{Term: "bar"}},
|
||||
CurrentState: statePtr(btypes.ChangesetStateClosed),
|
||||
CurrentState: pointers.Ptr(btypes.ChangesetStateClosed),
|
||||
},
|
||||
want: []*btypes.Changeset{},
|
||||
},
|
||||
"text match only": {
|
||||
opts: GetRewirerMappingsOpts{
|
||||
TextSearch: []search.TextSearchTerm{{Term: "foo"}},
|
||||
CurrentState: statePtr(btypes.ChangesetStateMerged),
|
||||
CurrentState: pointers.Ptr(btypes.ChangesetStateMerged),
|
||||
},
|
||||
want: []*btypes.Changeset{},
|
||||
},
|
||||
|
||||
@ -29,6 +29,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/extsvc/gitlab"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func testStoreChangesets(t *testing.T, ctx context.Context, s *Store, clock bt.Clock) {
|
||||
@ -1216,15 +1217,13 @@ func testStoreChangesets(t *testing.T, ctx context.Context, s *Store, clock bt.C
|
||||
OwnedByBatchChange: 123,
|
||||
Metadata: &github.PullRequest{Title: "Se titel"},
|
||||
})
|
||||
intptr := func(i int32) *int32 { return &i }
|
||||
strptr := func(i string) *string { return &i }
|
||||
|
||||
cs.ExternalBranch = "refs/heads/branch-2"
|
||||
cs.ExternalState = btypes.ChangesetExternalStateDeleted
|
||||
cs.ExternalReviewState = btypes.ChangesetReviewStateApproved
|
||||
cs.ExternalCheckState = btypes.ChangesetCheckStateFailed
|
||||
cs.DiffStatAdded = intptr(100)
|
||||
cs.DiffStatDeleted = intptr(100)
|
||||
cs.DiffStatAdded = pointers.Ptr(int32(100))
|
||||
cs.DiffStatDeleted = pointers.Ptr(int32(100))
|
||||
cs.Metadata = &github.PullRequest{Title: "The title"}
|
||||
want := cs.Clone()
|
||||
|
||||
@ -1237,7 +1236,7 @@ func testStoreChangesets(t *testing.T, ctx context.Context, s *Store, clock bt.C
|
||||
cs.PublicationState = btypes.ChangesetPublicationStatePublished
|
||||
cs.UiPublicationState = &published
|
||||
cs.ReconcilerState = btypes.ReconcilerStateCompleted
|
||||
cs.FailureMessage = strptr("very bad for real this time")
|
||||
cs.FailureMessage = pointers.Ptr("very bad for real this time")
|
||||
cs.NumFailures = 100
|
||||
cs.OwnedByBatchChangeID = 234
|
||||
cs.Closing = true
|
||||
@ -1533,7 +1532,7 @@ func testStoreChangesets(t *testing.T, ctx context.Context, s *Store, clock bt.C
|
||||
NumResets: 0,
|
||||
NumFailures: 0,
|
||||
SyncErrorMessage: nil,
|
||||
PreviousFailureMessage: strPtr("horse was here"),
|
||||
PreviousFailureMessage: pointers.Ptr("horse was here"),
|
||||
})
|
||||
})
|
||||
|
||||
@ -2667,5 +2666,3 @@ func TestCleanDetachedChangesets(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func strPtr(s string) *string { return &s }
|
||||
|
||||
1
enterprise/internal/batches/types/BUILD.bazel
generated
1
enterprise/internal/batches/types/BUILD.bazel
generated
@ -87,6 +87,7 @@ go_test(
|
||||
"//internal/timeutil",
|
||||
"//lib/batches",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
"@com_github_sourcegraph_go_diff//diff",
|
||||
"@com_github_stretchr_testify//assert",
|
||||
|
||||
@ -4,6 +4,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestChangesetSpec_ForkGetters(t *testing.T) {
|
||||
@ -18,14 +20,14 @@ func TestChangesetSpec_ForkGetters(t *testing.T) {
|
||||
namespace: nil,
|
||||
},
|
||||
"fork to user": {
|
||||
spec: &ChangesetSpec{ForkNamespace: strPtr(changesetSpecForkNamespaceUser)},
|
||||
spec: &ChangesetSpec{ForkNamespace: pointers.Ptr(changesetSpecForkNamespaceUser)},
|
||||
isFork: true,
|
||||
namespace: nil,
|
||||
},
|
||||
"fork to namespace": {
|
||||
spec: &ChangesetSpec{ForkNamespace: strPtr("org")},
|
||||
spec: &ChangesetSpec{ForkNamespace: pointers.Ptr("org")},
|
||||
isFork: true,
|
||||
namespace: strPtr("org"),
|
||||
namespace: pointers.Ptr("org"),
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
@ -47,5 +49,3 @@ func TestChangesetSpec_SetForkToUser(t *testing.T) {
|
||||
assert.NotNil(t, cs.ForkNamespace)
|
||||
assert.Equal(t, changesetSpecForkNamespaceUser, *cs.ForkNamespace)
|
||||
}
|
||||
|
||||
func strPtr(s string) *string { return &s }
|
||||
|
||||
@ -34,6 +34,7 @@ go_test(
|
||||
embed = [":window"],
|
||||
deps = [
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"//schema",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
"@com_github_stretchr_testify//assert",
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
"github.com/sourcegraph/sourcegraph/schema"
|
||||
)
|
||||
|
||||
@ -20,8 +21,7 @@ var (
|
||||
)
|
||||
|
||||
func timeOfDayPtr(hour, minute int8) *timeOfDay {
|
||||
t := timeOfDayFromParts(hour, minute)
|
||||
return &t
|
||||
return pointers.Ptr(timeOfDayFromParts(hour, minute))
|
||||
}
|
||||
|
||||
func TestConfiguration_Estimate(t *testing.T) {
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/executor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/timeutil"
|
||||
batcheslib "github.com/sourcegraph/sourcegraph/lib/batches"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestParseJSONLogsFromOutput(t *testing.T) {
|
||||
@ -262,7 +263,7 @@ func TestParseLogLines(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Started but timeout",
|
||||
entry: executor.ExecutionLogEntry{StartTime: time1, ExitCode: intPtr(-1), DurationMs: intPtr(500)},
|
||||
entry: executor.ExecutionLogEntry{StartTime: time1, ExitCode: pointers.Ptr(-1), DurationMs: pointers.Ptr(500)},
|
||||
lines: []*batcheslib.LogEvent{
|
||||
{
|
||||
Timestamp: time1,
|
||||
@ -287,7 +288,7 @@ func TestParseLogLines(t *testing.T) {
|
||||
1: {
|
||||
StartedAt: time1,
|
||||
FinishedAt: time1.Add(500 * time.Millisecond),
|
||||
ExitCode: intPtr(-1),
|
||||
ExitCode: pointers.Ptr(-1),
|
||||
Environment: map[string]string{"env": "var"},
|
||||
},
|
||||
},
|
||||
@ -485,5 +486,3 @@ func TestParseLogLines(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func intPtr(i int) *int { return &i }
|
||||
|
||||
@ -26,6 +26,7 @@ go_library(
|
||||
"//internal/observation",
|
||||
"//lib/codeintel/autoindex/config",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"@com_github_graph_gophers_graphql_go//:graphql-go",
|
||||
"@io_opentelemetry_go_otel//attribute",
|
||||
],
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/lib/codeintel/autoindex/config"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
// 🚨 SECURITY: Only entrypoint is within the repository resolver so the user is already authenticated
|
||||
@ -97,7 +98,7 @@ func (r *indexConfigurationResolver) Configuration(ctx context.Context) (_ *stri
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return resolverstubs.NonZeroPtr(string(configuration.Data)), nil
|
||||
return pointers.NonZeroPtr(string(configuration.Data)), nil
|
||||
}
|
||||
|
||||
func (r *indexConfigurationResolver) InferredConfiguration(ctx context.Context) (_ resolverstubs.InferredConfigurationResolver, err error) {
|
||||
|
||||
@ -15,14 +15,15 @@ import (
|
||||
resolverstubs "github.com/sourcegraph/sourcegraph/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/lib/codeintel/autoindex/config"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
// 🚨 SECURITY: Only site admins may infer auto-index jobs
|
||||
func (r *rootResolver) InferAutoIndexJobsForRepo(ctx context.Context, args *resolverstubs.InferAutoIndexJobsForRepoArgs) (_ resolverstubs.InferAutoIndexJobsResultResolver, err error) {
|
||||
ctx, _, endObservation := r.operations.inferAutoIndexJobsForRepo.WithErrors(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
|
||||
attribute.String("repository", string(args.Repository)),
|
||||
attribute.String("rev", resolverstubs.Deref(args.Rev, "")),
|
||||
attribute.String("script", resolverstubs.Deref(args.Script, "")),
|
||||
attribute.String("rev", pointers.Deref(args.Rev, "")),
|
||||
attribute.String("script", pointers.Deref(args.Script, "")),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
@ -68,8 +69,8 @@ func (r *rootResolver) InferAutoIndexJobsForRepo(ctx context.Context, args *reso
|
||||
func (r *rootResolver) QueueAutoIndexJobsForRepo(ctx context.Context, args *resolverstubs.QueueAutoIndexJobsForRepoArgs) (_ []resolverstubs.PreciseIndexResolver, err error) {
|
||||
ctx, traceErrs, endObservation := r.operations.queueAutoIndexJobsForRepo.WithErrors(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
|
||||
attribute.String("repository", string(args.Repository)),
|
||||
attribute.String("rev", resolverstubs.Deref(args.Rev, "")),
|
||||
attribute.String("configuration", resolverstubs.Deref(args.Configuration, "")),
|
||||
attribute.String("rev", pointers.Deref(args.Rev, "")),
|
||||
attribute.String("configuration", pointers.Deref(args.Configuration, "")),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
|
||||
@ -36,6 +36,7 @@ go_library(
|
||||
"//internal/metrics",
|
||||
"//internal/observation",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"@com_github_graph_gophers_graphql_go//:graphql-go",
|
||||
"@com_github_sourcegraph_go_lsp//:go-lsp",
|
||||
"@com_github_sourcegraph_log//:log",
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/internal/codeintel/shared/resolvers/gitresolvers"
|
||||
resolverstubs "github.com/sourcegraph/sourcegraph/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
// DefaultDiagnosticsPageSize is the diagnostic result page size when no limit is supplied.
|
||||
@ -16,7 +17,7 @@ const DefaultDiagnosticsPageSize = 100
|
||||
|
||||
// Diagnostics returns the diagnostics for documents with the given path prefix.
|
||||
func (r *gitBlobLSIFDataResolver) Diagnostics(ctx context.Context, args *resolverstubs.LSIFDiagnosticsArgs) (_ resolverstubs.DiagnosticConnectionResolver, err error) {
|
||||
limit := int(resolverstubs.Deref(args.First, DefaultDiagnosticsPageSize))
|
||||
limit := int(pointers.Deref(args.First, DefaultDiagnosticsPageSize))
|
||||
if limit <= 0 {
|
||||
return nil, ErrIllegalLimit
|
||||
}
|
||||
@ -55,13 +56,13 @@ func newDiagnosticResolver(diagnostic codenav.DiagnosticAtUpload, locationResolv
|
||||
|
||||
func (r *diagnosticResolver) Severity() (*string, error) { return toSeverity(r.diagnostic.Severity) }
|
||||
func (r *diagnosticResolver) Code() (*string, error) {
|
||||
return resolverstubs.NonZeroPtr(r.diagnostic.Code), nil
|
||||
return pointers.NonZeroPtr(r.diagnostic.Code), nil
|
||||
}
|
||||
func (r *diagnosticResolver) Source() (*string, error) {
|
||||
return resolverstubs.NonZeroPtr(r.diagnostic.Source), nil
|
||||
return pointers.NonZeroPtr(r.diagnostic.Source), nil
|
||||
}
|
||||
func (r *diagnosticResolver) Message() (*string, error) {
|
||||
return resolverstubs.NonZeroPtr(r.diagnostic.Message), nil
|
||||
return pointers.NonZeroPtr(r.diagnostic.Message), nil
|
||||
}
|
||||
|
||||
func (r *diagnosticResolver) Location(ctx context.Context) (resolverstubs.LocationResolver, error) {
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/internal/codeintel/codenav"
|
||||
resolverstubs "github.com/sourcegraph/sourcegraph/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
// DefaultReferencesPageSize is the implementation result page size when no limit is supplied.
|
||||
@ -20,7 +21,7 @@ const DefaultImplementationsPageSize = 100
|
||||
var ErrIllegalLimit = errors.New("illegal limit")
|
||||
|
||||
func (r *gitBlobLSIFDataResolver) Implementations(ctx context.Context, args *resolverstubs.LSIFPagedQueryPositionArgs) (_ resolverstubs.LocationConnectionResolver, err error) {
|
||||
limit := int(resolverstubs.Deref(args.First, DefaultImplementationsPageSize))
|
||||
limit := int(pointers.Deref(args.First, DefaultImplementationsPageSize))
|
||||
if limit <= 0 {
|
||||
return nil, ErrIllegalLimit
|
||||
}
|
||||
@ -63,11 +64,11 @@ func (r *gitBlobLSIFDataResolver) Implementations(ctx context.Context, args *res
|
||||
impls = filtered
|
||||
}
|
||||
|
||||
return newLocationConnectionResolver(impls, resolverstubs.NonZeroPtr(nextCursor), r.locationResolver), nil
|
||||
return newLocationConnectionResolver(impls, pointers.NonZeroPtr(nextCursor), r.locationResolver), nil
|
||||
}
|
||||
|
||||
func (r *gitBlobLSIFDataResolver) Prototypes(ctx context.Context, args *resolverstubs.LSIFPagedQueryPositionArgs) (_ resolverstubs.LocationConnectionResolver, err error) {
|
||||
limit := int(resolverstubs.Deref(args.First, DefaultImplementationsPageSize))
|
||||
limit := int(pointers.Deref(args.First, DefaultImplementationsPageSize))
|
||||
if limit <= 0 {
|
||||
return nil, ErrIllegalLimit
|
||||
}
|
||||
@ -110,7 +111,7 @@ func (r *gitBlobLSIFDataResolver) Prototypes(ctx context.Context, args *resolver
|
||||
prototypes = filtered
|
||||
}
|
||||
|
||||
return newLocationConnectionResolver(prototypes, resolverstubs.NonZeroPtr(nextCursor), r.locationResolver), nil
|
||||
return newLocationConnectionResolver(prototypes, pointers.NonZeroPtr(nextCursor), r.locationResolver), nil
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@ -11,13 +11,14 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/internal/codeintel/codenav"
|
||||
resolverstubs "github.com/sourcegraph/sourcegraph/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
const DefaultReferencesPageSize = 100
|
||||
|
||||
// References returns the list of source locations that reference the symbol at the given position.
|
||||
func (r *gitBlobLSIFDataResolver) References(ctx context.Context, args *resolverstubs.LSIFPagedQueryPositionArgs) (_ resolverstubs.LocationConnectionResolver, err error) {
|
||||
limit := int(resolverstubs.Deref(args.First, DefaultReferencesPageSize))
|
||||
limit := int(pointers.Deref(args.First, DefaultReferencesPageSize))
|
||||
if limit <= 0 {
|
||||
return nil, ErrIllegalLimit
|
||||
}
|
||||
@ -60,7 +61,7 @@ func (r *gitBlobLSIFDataResolver) References(ctx context.Context, args *resolver
|
||||
refs = filtered
|
||||
}
|
||||
|
||||
return newLocationConnectionResolver(refs, resolverstubs.NonZeroPtr(nextCursor), r.locationResolver), nil
|
||||
return newLocationConnectionResolver(refs, pointers.NonZeroPtr(nextCursor), r.locationResolver), nil
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@ -58,6 +58,7 @@ go_test(
|
||||
"//internal/observation",
|
||||
"//internal/timeutil",
|
||||
"//internal/types",
|
||||
"//lib/pointers",
|
||||
"@com_github_derision_test_glock//:glock",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
],
|
||||
|
||||
@ -48,10 +48,6 @@ func insertRepo(t testing.TB, db database.DB, id int, name string, private bool)
|
||||
}
|
||||
}
|
||||
|
||||
func boolPtr(value bool) *bool {
|
||||
return &value
|
||||
}
|
||||
|
||||
// scanPolicyRepositories returns a map of policyIDs that have a slice of their correspondent repoIDs (repoIDs associated with that policyIDs).
|
||||
func scanPolicyRepositories(rows *sql.Rows, queryErr error) (_ map[int][]int, err error) {
|
||||
if queryErr != nil {
|
||||
|
||||
@ -17,6 +17,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
internaltypes "github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestGetRetentionPolicyOverview(t *testing.T) {
|
||||
@ -46,7 +47,7 @@ func TestGetRetentionPolicyOverview(t *testing.T) {
|
||||
mockPolicies: []policiesshared.RetentionPolicyMatchCandidate{
|
||||
{
|
||||
ConfigurationPolicy: &policiesshared.ConfigurationPolicy{
|
||||
RetentionDuration: timePtr(time.Hour * 24),
|
||||
RetentionDuration: pointers.Ptr(time.Hour * 24),
|
||||
RetainIntermediateCommits: false,
|
||||
Type: policiesshared.GitObjectTypeTag,
|
||||
Pattern: "*",
|
||||
@ -74,7 +75,7 @@ func TestGetRetentionPolicyOverview(t *testing.T) {
|
||||
mockPolicies: []policiesshared.RetentionPolicyMatchCandidate{
|
||||
{
|
||||
ConfigurationPolicy: &policiesshared.ConfigurationPolicy{
|
||||
RetentionDuration: timePtr(time.Hour * 24),
|
||||
RetentionDuration: pointers.Ptr(time.Hour * 24),
|
||||
RetainIntermediateCommits: false,
|
||||
Type: policiesshared.GitObjectTypeTag,
|
||||
Pattern: "*",
|
||||
@ -125,7 +126,7 @@ func TestGetRetentionPolicyOverview(t *testing.T) {
|
||||
mockPolicies: []policiesshared.RetentionPolicyMatchCandidate{
|
||||
{
|
||||
ConfigurationPolicy: &policiesshared.ConfigurationPolicy{
|
||||
RetentionDuration: timePtr(time.Hour * 24),
|
||||
RetentionDuration: pointers.Ptr(time.Hour * 24),
|
||||
RetainIntermediateCommits: false,
|
||||
Type: policiesshared.GitObjectTypeTag,
|
||||
Pattern: "*",
|
||||
@ -134,7 +135,7 @@ func TestGetRetentionPolicyOverview(t *testing.T) {
|
||||
},
|
||||
{
|
||||
ConfigurationPolicy: &policiesshared.ConfigurationPolicy{
|
||||
RetentionDuration: timePtr(time.Hour * 24),
|
||||
RetentionDuration: pointers.Ptr(time.Hour * 24),
|
||||
RetainIntermediateCommits: false,
|
||||
Type: policiesshared.GitObjectTypeTree,
|
||||
Pattern: "*",
|
||||
@ -162,7 +163,7 @@ func TestGetRetentionPolicyOverview(t *testing.T) {
|
||||
mockPolicies: []policiesshared.RetentionPolicyMatchCandidate{
|
||||
{
|
||||
ConfigurationPolicy: &policiesshared.ConfigurationPolicy{
|
||||
RetentionDuration: timePtr(time.Hour * 24),
|
||||
RetentionDuration: pointers.Ptr(time.Hour * 24),
|
||||
RetainIntermediateCommits: false,
|
||||
Type: policiesshared.GitObjectTypeTag,
|
||||
Pattern: "*",
|
||||
@ -252,7 +253,7 @@ func TestRetentionPolicyOverview_ByVisibility(t *testing.T) {
|
||||
mockPolicies: []policiesshared.RetentionPolicyMatchCandidate{
|
||||
{
|
||||
ConfigurationPolicy: &policiesshared.ConfigurationPolicy{
|
||||
RetentionDuration: timePtr(time.Hour * 24),
|
||||
RetentionDuration: pointers.Ptr(time.Hour * 24),
|
||||
RetainIntermediateCommits: false,
|
||||
Type: policiesshared.GitObjectTypeTag,
|
||||
Pattern: "*",
|
||||
@ -329,10 +330,6 @@ func TestRetentionPolicyOverview_ByVisibility(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func timePtr(t time.Duration) *time.Duration {
|
||||
return &t
|
||||
}
|
||||
|
||||
func mockConfigurationPolicies(policies []policiesshared.RetentionPolicyMatchCandidate) (mockedCandidates []policiesshared.RetentionPolicyMatchCandidate, mockedPolicies []policiesshared.ConfigurationPolicy) {
|
||||
for i, policy := range policies {
|
||||
if policy.ConfigurationPolicy != nil {
|
||||
|
||||
@ -24,6 +24,7 @@ go_library(
|
||||
"//internal/metrics",
|
||||
"//internal/observation",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"@com_github_graph_gophers_graphql_go//:graphql-go",
|
||||
"@io_opentelemetry_go_otel//attribute",
|
||||
],
|
||||
|
||||
@ -10,12 +10,13 @@ import (
|
||||
resolverstubs "github.com/sourcegraph/sourcegraph/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
// 🚨 SECURITY: Only site admins may modify code intelligence configuration policies
|
||||
func (r *rootResolver) CreateCodeIntelligenceConfigurationPolicy(ctx context.Context, args *resolverstubs.CreateCodeIntelligenceConfigurationPolicyArgs) (_ resolverstubs.CodeIntelligenceConfigurationPolicyResolver, err error) {
|
||||
ctx, traceErrs, endObservation := r.operations.createConfigurationPolicy.WithErrors(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
|
||||
attribute.String("repository", string(resolverstubs.Deref(args.Repository, ""))),
|
||||
attribute.String("repository", string(pointers.Deref(args.Repository, ""))),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
policiesshared "github.com/sourcegraph/sourcegraph/enterprise/internal/codeintel/policies/shared"
|
||||
resolverstubs "github.com/sourcegraph/sourcegraph/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
const DefaultConfigurationPolicyPageSize = 50
|
||||
@ -16,13 +17,13 @@ const DefaultConfigurationPolicyPageSize = 50
|
||||
// 🚨 SECURITY: dbstore layer handles authz for GetConfigurationPolicies
|
||||
func (r *rootResolver) CodeIntelligenceConfigurationPolicies(ctx context.Context, args *resolverstubs.CodeIntelligenceConfigurationPoliciesArgs) (_ resolverstubs.CodeIntelligenceConfigurationPolicyConnectionResolver, err error) {
|
||||
ctx, traceErrs, endObservation := r.operations.configurationPolicies.WithErrors(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
|
||||
attribute.Int("first", int(resolverstubs.Deref(args.First, 0))),
|
||||
attribute.String("after", resolverstubs.Deref(args.After, "")),
|
||||
attribute.String("repository", string(resolverstubs.Deref(args.Repository, ""))),
|
||||
attribute.String("query", resolverstubs.Deref(args.Query, "")),
|
||||
attribute.Bool("forDataRetention", resolverstubs.Deref(args.ForDataRetention, false)),
|
||||
attribute.Bool("forIndexing", resolverstubs.Deref(args.ForIndexing, false)),
|
||||
attribute.Bool("protected", resolverstubs.Deref(args.Protected, false)),
|
||||
attribute.Int("first", int(pointers.Deref(args.First, 0))),
|
||||
attribute.String("after", pointers.Deref(args.After, "")),
|
||||
attribute.String("repository", string(pointers.Deref(args.Repository, ""))),
|
||||
attribute.String("query", pointers.Deref(args.Query, "")),
|
||||
attribute.Bool("forDataRetention", pointers.Deref(args.ForDataRetention, false)),
|
||||
attribute.Bool("forIndexing", pointers.Deref(args.ForIndexing, false)),
|
||||
attribute.Bool("protected", pointers.Deref(args.Protected, false)),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
resolverstubs "github.com/sourcegraph/sourcegraph/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -21,7 +22,7 @@ const (
|
||||
|
||||
func (r *rootResolver) PreviewRepositoryFilter(ctx context.Context, args *resolverstubs.PreviewRepositoryFilterArgs) (_ resolverstubs.RepositoryFilterPreviewResolver, err error) {
|
||||
ctx, _, endObservation := r.operations.previewRepoFilter.With(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
|
||||
attribute.Int("first", int(resolverstubs.Deref(args.First, 0))),
|
||||
attribute.Int("first", int(pointers.Deref(args.First, 0))),
|
||||
attribute.StringSlice("patterns", args.Patterns),
|
||||
}})
|
||||
defer endObservation(1, observation.Args{})
|
||||
@ -56,7 +57,7 @@ func (r *rootResolver) PreviewRepositoryFilter(ctx context.Context, args *resolv
|
||||
|
||||
func (r *rootResolver) PreviewGitObjectFilter(ctx context.Context, id graphql.ID, args *resolverstubs.PreviewGitObjectFilterArgs) (_ resolverstubs.GitObjectFilterPreviewResolver, err error) {
|
||||
ctx, _, endObservation := r.operations.previewGitObjectFilter.With(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
|
||||
attribute.Int("first", int(resolverstubs.Deref(args.First, 0))),
|
||||
attribute.Int("first", int(pointers.Deref(args.First, 0))),
|
||||
attribute.String("type", string(args.Type)),
|
||||
attribute.String("pattern", args.Pattern),
|
||||
}})
|
||||
|
||||
@ -19,6 +19,7 @@ go_library(
|
||||
"//internal/gqlutil",
|
||||
"//internal/metrics",
|
||||
"//internal/observation",
|
||||
"//lib/pointers",
|
||||
"@com_github_graph_gophers_graphql_go//:graphql-go",
|
||||
"@io_opentelemetry_go_otel//attribute",
|
||||
],
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
resolverstubs "github.com/sourcegraph/sourcegraph/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
type rootResolver struct {
|
||||
@ -45,8 +46,8 @@ func NewRootResolver(
|
||||
|
||||
func (r *rootResolver) Vulnerabilities(ctx context.Context, args resolverstubs.GetVulnerabilitiesArgs) (_ resolverstubs.VulnerabilityConnectionResolver, err error) {
|
||||
ctx, _, endObservation := r.operations.getVulnerabilities.WithErrors(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
|
||||
attribute.Int("first", int(resolverstubs.Deref(args.First, 0))),
|
||||
attribute.String("after", resolverstubs.Deref(args.After, "")),
|
||||
attribute.Int("first", int(pointers.Deref(args.First, 0))),
|
||||
attribute.String("after", pointers.Deref(args.After, "")),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
@ -73,8 +74,8 @@ func (r *rootResolver) Vulnerabilities(ctx context.Context, args resolverstubs.G
|
||||
|
||||
func (r *rootResolver) VulnerabilityMatches(ctx context.Context, args resolverstubs.GetVulnerabilityMatchesArgs) (_ resolverstubs.VulnerabilityMatchConnectionResolver, err error) {
|
||||
ctx, errTracer, endObservation := r.operations.getMatches.WithErrors(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
|
||||
attribute.Int("first", int(resolverstubs.Deref(args.First, 0))),
|
||||
attribute.String("after", resolverstubs.Deref(args.After, "")),
|
||||
attribute.Int("first", int(pointers.Deref(args.First, 0))),
|
||||
attribute.String("after", pointers.Deref(args.After, "")),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
|
||||
@ -54,6 +54,7 @@ go_test(
|
||||
"//internal/workerutil",
|
||||
"//internal/workerutil/dbworker/store",
|
||||
"//lib/codeintel/precise",
|
||||
"//lib/pointers",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
"@com_github_keegancsmith_sqlf//:sqlf",
|
||||
"@com_github_sourcegraph_scip//bindings/go/scip",
|
||||
|
||||
@ -18,6 +18,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/internal/timeutil"
|
||||
internaltypes "github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestUploadExpirer(t *testing.T) {
|
||||
@ -93,10 +94,10 @@ func TestUploadExpirer(t *testing.T) {
|
||||
func setupMockPolicyService() *MockPolicyService {
|
||||
policies := []policiesshared.ConfigurationPolicy{
|
||||
{ID: 1, RepositoryID: nil},
|
||||
{ID: 2, RepositoryID: intPtr(53)},
|
||||
{ID: 2, RepositoryID: pointers.Ptr(53)},
|
||||
{ID: 3, RepositoryID: nil},
|
||||
{ID: 4, RepositoryID: nil},
|
||||
{ID: 5, RepositoryID: intPtr(50)},
|
||||
{ID: 5, RepositoryID: pointers.Ptr(50)},
|
||||
}
|
||||
|
||||
getConfigurationPolicies := func(ctx context.Context, opts policiesshared.GetConfigurationPoliciesOptions) (filtered []policiesshared.ConfigurationPolicy, _ int, _ error) {
|
||||
@ -261,10 +262,6 @@ func testUploadExpirerMockPolicyMatcher() *MockPolicyMatcher {
|
||||
return policyMatcher
|
||||
}
|
||||
|
||||
func intPtr(v int) *int {
|
||||
return &v
|
||||
}
|
||||
|
||||
func days(n int) *time.Duration {
|
||||
t := time.Hour * 24 * time.Duration(n)
|
||||
return &t
|
||||
|
||||
@ -79,6 +79,7 @@ go_test(
|
||||
"//internal/observation",
|
||||
"//lib/codeintel/precise",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"//schema",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
"@com_github_keegancsmith_sqlf//:sqlf",
|
||||
|
||||
@ -17,6 +17,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbtest"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestHardDeleteUploadsByIDs(t *testing.T) {
|
||||
@ -574,24 +575,24 @@ func TestExpireFailedRecords(t *testing.T) {
|
||||
|
||||
insertIndexes(t, db,
|
||||
// young failures (none removed)
|
||||
uploadsshared.Index{ID: 1, RepositoryID: 50, Commit: makeCommit(1), FinishedAt: timePtr(now.Add(-time.Minute * 10)), State: "failed"},
|
||||
uploadsshared.Index{ID: 2, RepositoryID: 50, Commit: makeCommit(2), FinishedAt: timePtr(now.Add(-time.Minute * 20)), State: "failed"},
|
||||
uploadsshared.Index{ID: 3, RepositoryID: 50, Commit: makeCommit(3), FinishedAt: timePtr(now.Add(-time.Minute * 20)), State: "failed"},
|
||||
uploadsshared.Index{ID: 1, RepositoryID: 50, Commit: makeCommit(1), FinishedAt: pointers.Ptr(now.Add(-time.Minute * 10)), State: "failed"},
|
||||
uploadsshared.Index{ID: 2, RepositoryID: 50, Commit: makeCommit(2), FinishedAt: pointers.Ptr(now.Add(-time.Minute * 20)), State: "failed"},
|
||||
uploadsshared.Index{ID: 3, RepositoryID: 50, Commit: makeCommit(3), FinishedAt: pointers.Ptr(now.Add(-time.Minute * 20)), State: "failed"},
|
||||
|
||||
// failures prior to a success (both removed)
|
||||
uploadsshared.Index{ID: 4, RepositoryID: 50, Commit: makeCommit(4), FinishedAt: timePtr(now.Add(-time.Hour * 10)), Root: "foo", State: "completed"},
|
||||
uploadsshared.Index{ID: 5, RepositoryID: 50, Commit: makeCommit(5), FinishedAt: timePtr(now.Add(-time.Hour * 12)), Root: "foo", State: "failed"},
|
||||
uploadsshared.Index{ID: 6, RepositoryID: 50, Commit: makeCommit(6), FinishedAt: timePtr(now.Add(-time.Hour * 14)), Root: "foo", State: "failed"},
|
||||
uploadsshared.Index{ID: 4, RepositoryID: 50, Commit: makeCommit(4), FinishedAt: pointers.Ptr(now.Add(-time.Hour * 10)), Root: "foo", State: "completed"},
|
||||
uploadsshared.Index{ID: 5, RepositoryID: 50, Commit: makeCommit(5), FinishedAt: pointers.Ptr(now.Add(-time.Hour * 12)), Root: "foo", State: "failed"},
|
||||
uploadsshared.Index{ID: 6, RepositoryID: 50, Commit: makeCommit(6), FinishedAt: pointers.Ptr(now.Add(-time.Hour * 14)), Root: "foo", State: "failed"},
|
||||
|
||||
// old failures (one is left for debugging)
|
||||
uploadsshared.Index{ID: 7, RepositoryID: 51, Commit: makeCommit(7), FinishedAt: timePtr(now.Add(-time.Hour * 3)), State: "failed"},
|
||||
uploadsshared.Index{ID: 8, RepositoryID: 51, Commit: makeCommit(8), FinishedAt: timePtr(now.Add(-time.Hour * 4)), State: "failed"},
|
||||
uploadsshared.Index{ID: 9, RepositoryID: 51, Commit: makeCommit(9), FinishedAt: timePtr(now.Add(-time.Hour * 5)), State: "failed"},
|
||||
uploadsshared.Index{ID: 7, RepositoryID: 51, Commit: makeCommit(7), FinishedAt: pointers.Ptr(now.Add(-time.Hour * 3)), State: "failed"},
|
||||
uploadsshared.Index{ID: 8, RepositoryID: 51, Commit: makeCommit(8), FinishedAt: pointers.Ptr(now.Add(-time.Hour * 4)), State: "failed"},
|
||||
uploadsshared.Index{ID: 9, RepositoryID: 51, Commit: makeCommit(9), FinishedAt: pointers.Ptr(now.Add(-time.Hour * 5)), State: "failed"},
|
||||
|
||||
// failures prior to queued uploads (one removed; queued does not reset failures)
|
||||
uploadsshared.Index{ID: 10, RepositoryID: 52, Commit: makeCommit(10), Root: "foo", State: "queued"},
|
||||
uploadsshared.Index{ID: 11, RepositoryID: 52, Commit: makeCommit(11), FinishedAt: timePtr(now.Add(-time.Hour * 12)), Root: "foo", State: "failed"},
|
||||
uploadsshared.Index{ID: 12, RepositoryID: 52, Commit: makeCommit(12), FinishedAt: timePtr(now.Add(-time.Hour * 14)), Root: "foo", State: "failed"},
|
||||
uploadsshared.Index{ID: 11, RepositoryID: 52, Commit: makeCommit(11), FinishedAt: pointers.Ptr(now.Add(-time.Hour * 12)), Root: "foo", State: "failed"},
|
||||
uploadsshared.Index{ID: 12, RepositoryID: 52, Commit: makeCommit(12), FinishedAt: pointers.Ptr(now.Add(-time.Hour * 14)), Root: "foo", State: "failed"},
|
||||
)
|
||||
|
||||
if _, _, err := store.ExpireFailedRecords(ctx, 100, time.Hour, now); err != nil {
|
||||
@ -618,10 +619,6 @@ func TestExpireFailedRecords(t *testing.T) {
|
||||
//
|
||||
//
|
||||
|
||||
func timePtr(t time.Time) *time.Time {
|
||||
return &t
|
||||
}
|
||||
|
||||
func getIndexStates(db database.DB, ids ...int) (map[int]string, error) {
|
||||
if len(ids) == 0 {
|
||||
return nil, nil
|
||||
|
||||
@ -41,6 +41,7 @@ go_library(
|
||||
"//internal/metrics",
|
||||
"//internal/observation",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"@com_github_grafana_regexp//:regexp",
|
||||
"@com_github_graph_gophers_graphql_go//:graphql-go",
|
||||
"@com_github_graph_gophers_graphql_go//relay",
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
resolverstubs "github.com/sourcegraph/sourcegraph/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/internal/executor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
// indexStepsResolver resolves the steps of an index record.
|
||||
@ -167,7 +168,7 @@ func newIndexStepResolver(siteAdminChecker sharedresolvers.SiteAdminChecker, ind
|
||||
|
||||
func (r *indexStepResolver) Commands() []string { return r.index.LocalSteps }
|
||||
func (r *indexStepResolver) IndexerArgs() []string { return r.index.IndexerArgs }
|
||||
func (r *indexStepResolver) Outfile() *string { return resolverstubs.NonZeroPtr(r.index.Outfile) }
|
||||
func (r *indexStepResolver) Outfile() *string { return pointers.NonZeroPtr(r.index.Outfile) }
|
||||
|
||||
func (r *indexStepResolver) RequestedEnvVars() *[]string {
|
||||
if len(r.index.RequestedEnvVars) == 0 {
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
uploadsshared "github.com/sourcegraph/sourcegraph/enterprise/internal/codeintel/uploads/shared"
|
||||
resolverstubs "github.com/sourcegraph/sourcegraph/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
// 🚨 SECURITY: Only site admins may modify code intelligence upload data
|
||||
@ -67,7 +68,7 @@ func (r *rootResolver) DeletePreciseIndexes(ctx context.Context, args *resolvers
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
term := resolverstubs.Deref(args.Query, "")
|
||||
term := pointers.Deref(args.Query, "")
|
||||
|
||||
visibleAtTip := false
|
||||
if args.IsLatestForRepo != nil {
|
||||
@ -158,7 +159,7 @@ func (r *rootResolver) ReindexPreciseIndexes(ctx context.Context, args *resolver
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
term := resolverstubs.Deref(args.Query, "")
|
||||
term := pointers.Deref(args.Query, "")
|
||||
|
||||
visibleAtTip := false
|
||||
if args.IsLatestForRepo != nil {
|
||||
|
||||
1
enterprise/internal/database/BUILD.bazel
generated
1
enterprise/internal/database/BUILD.bazel
generated
@ -110,6 +110,7 @@ go_test(
|
||||
"//internal/timeutil",
|
||||
"//internal/types",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"//schema",
|
||||
"@com_github_gitchander_permutation//:permutation",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
|
||||
@ -37,6 +37,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/timeutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
"github.com/sourcegraph/sourcegraph/schema"
|
||||
)
|
||||
|
||||
@ -3999,7 +4000,7 @@ func TestPermsStore_ListUserPermissions(t *testing.T) {
|
||||
Name: "TestPagination",
|
||||
UserID: 555,
|
||||
Args: &ListUserPermissionsArgs{
|
||||
PaginationArgs: &database.PaginationArgs{First: toIntPtr(2), After: toStringPtr("'public_repo_5'"), OrderBy: database.OrderBy{{Field: "repo.name"}}},
|
||||
PaginationArgs: &database.PaginationArgs{First: pointers.Ptr(2), After: pointers.Ptr("'public_repo_5'"), OrderBy: database.OrderBy{{Field: "repo.name"}}},
|
||||
},
|
||||
WantResults: []*listUserPermissionsResult{
|
||||
{
|
||||
@ -4184,7 +4185,7 @@ func TestPermsStore_ListRepoPermissions(t *testing.T) {
|
||||
Name: "TestPaginationWithPrivateRepo",
|
||||
RepoID: 1,
|
||||
Args: &ListRepoPermissionsArgs{
|
||||
PaginationArgs: &database.PaginationArgs{First: toIntPtr(1), After: toStringPtr("555"), OrderBy: database.OrderBy{{Field: "users.id"}}, Ascending: true},
|
||||
PaginationArgs: &database.PaginationArgs{First: pointers.Ptr(1), After: pointers.Ptr("555"), OrderBy: database.OrderBy{{Field: "users.id"}}, Ascending: true},
|
||||
},
|
||||
WantResults: []*listRepoPermissionsResult{
|
||||
{
|
||||
@ -4364,14 +4365,6 @@ type listRepoPermissionsResult struct {
|
||||
Reason UserRepoPermissionReason
|
||||
}
|
||||
|
||||
func toIntPtr(num int) *int {
|
||||
return &num
|
||||
}
|
||||
|
||||
func toStringPtr(str string) *string {
|
||||
return &str
|
||||
}
|
||||
|
||||
type fakeProvider struct {
|
||||
codeHost *extsvc.CodeHost
|
||||
extAcct *extsvc.Account
|
||||
|
||||
1
enterprise/internal/insights/store/BUILD.bazel
generated
1
enterprise/internal/insights/store/BUILD.bazel
generated
@ -60,6 +60,7 @@ go_test(
|
||||
"//internal/database/dbtest",
|
||||
"//internal/timeutil",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
"@com_github_hexops_autogold_v2//:autogold",
|
||||
"@com_github_hexops_valast//:valast",
|
||||
|
||||
@ -16,17 +16,15 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbtest"
|
||||
"github.com/sourcegraph/sourcegraph/internal/timeutil"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func initializeData(ctx context.Context, store *Store, repos, times int, withCapture int) string {
|
||||
var cv []*string
|
||||
strPtr := func(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
if withCapture > 0 {
|
||||
for i := 0; i < withCapture; i++ {
|
||||
cv = append(cv, strPtr(fmt.Sprintf("%d", i)))
|
||||
cv = append(cv, pointers.Ptr(fmt.Sprintf("%d", i)))
|
||||
}
|
||||
} else {
|
||||
cv = append(cv, nil)
|
||||
|
||||
@ -20,6 +20,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbtest"
|
||||
"github.com/sourcegraph/sourcegraph/internal/timeutil"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestSeriesPoints(t *testing.T) {
|
||||
@ -148,8 +149,7 @@ func TestCountData(t *testing.T) {
|
||||
return v
|
||||
}
|
||||
timePtr := func(s string) *time.Time {
|
||||
t := timeValue(s)
|
||||
return &t
|
||||
return pointers.Ptr(timeValue(s))
|
||||
}
|
||||
optionalString := func(v string) *string { return &v }
|
||||
optionalRepoID := func(v api.RepoID) *api.RepoID { return &v }
|
||||
|
||||
1
enterprise/internal/licensing/BUILD.bazel
generated
1
enterprise/internal/licensing/BUILD.bazel
generated
@ -56,6 +56,7 @@ go_test(
|
||||
deps = [
|
||||
"//enterprise/internal/license",
|
||||
"//internal/redispool",
|
||||
"//lib/pointers",
|
||||
"@com_github_derision_test_glock//:glock",
|
||||
"@com_github_gomodule_redigo//redis",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
|
||||
@ -4,6 +4,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestNewCodyGatewayChatRateLimit(t *testing.T) {
|
||||
@ -17,7 +19,7 @@ func TestNewCodyGatewayChatRateLimit(t *testing.T) {
|
||||
{
|
||||
name: "Enterprise plan with GPT tag and user count",
|
||||
plan: PlanEnterprise1,
|
||||
userCount: intPtr(50),
|
||||
userCount: pointers.Ptr(50),
|
||||
licenseTags: []string{GPTLLMAccessTag},
|
||||
want: CodyGatewayRateLimit{
|
||||
AllowedModels: []string{"openai/gpt-4", "openai/gpt-3.5-turbo"},
|
||||
@ -28,7 +30,7 @@ func TestNewCodyGatewayChatRateLimit(t *testing.T) {
|
||||
{
|
||||
name: "Enterprise plan with no GPT tag",
|
||||
plan: PlanEnterprise1,
|
||||
userCount: intPtr(50),
|
||||
userCount: pointers.Ptr(50),
|
||||
want: CodyGatewayRateLimit{
|
||||
AllowedModels: []string{"anthropic/claude-v1", "anthropic/claude-instant-v1"},
|
||||
Limit: 2500,
|
||||
@ -75,7 +77,7 @@ func TestCodyGatewayCodeRateLimit(t *testing.T) {
|
||||
{
|
||||
name: "Enterprise plan with GPT tag and user count",
|
||||
plan: PlanEnterprise1,
|
||||
userCount: intPtr(50),
|
||||
userCount: pointers.Ptr(50),
|
||||
licenseTags: []string{GPTLLMAccessTag},
|
||||
want: CodyGatewayRateLimit{
|
||||
AllowedModels: []string{"openai/gpt-3.5-turbo"},
|
||||
@ -86,7 +88,7 @@ func TestCodyGatewayCodeRateLimit(t *testing.T) {
|
||||
{
|
||||
name: "Enterprise plan with no GPT tag",
|
||||
plan: PlanEnterprise1,
|
||||
userCount: intPtr(50),
|
||||
userCount: pointers.Ptr(50),
|
||||
want: CodyGatewayRateLimit{
|
||||
AllowedModels: []string{"anthropic/claude-instant-v1"},
|
||||
Limit: 50000,
|
||||
@ -133,7 +135,7 @@ func TestCodyGatewayEmbeddingsRateLimit(t *testing.T) {
|
||||
{
|
||||
name: "Enterprise plan",
|
||||
plan: PlanEnterprise1,
|
||||
userCount: intPtr(50),
|
||||
userCount: pointers.Ptr(50),
|
||||
want: CodyGatewayRateLimit{
|
||||
AllowedModels: []string{"openai/text-embedding-ada-002"},
|
||||
Limit: 20 * 50 * 2_500_000 / 30,
|
||||
@ -168,5 +170,3 @@ func TestCodyGatewayEmbeddingsRateLimit(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func intPtr(i int) *int { return &i }
|
||||
|
||||
1
enterprise/internal/rockskip/BUILD.bazel
generated
1
enterprise/internal/rockskip/BUILD.bazel
generated
@ -59,6 +59,7 @@ go_test(
|
||||
"//internal/gitserver/gitdomain",
|
||||
"//internal/search",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
"@com_github_sourcegraph_go_ctags//:go-ctags",
|
||||
"@com_github_sourcegraph_log//logtest",
|
||||
|
||||
@ -4,6 +4,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
func TestIsFileExtensionMatch(t *testing.T) {
|
||||
@ -37,16 +39,14 @@ func TestIsFileExtensionMatch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIsLiteralPrefix(t *testing.T) {
|
||||
ptr := func(s string) *string { return &s }
|
||||
|
||||
tests := []struct {
|
||||
expr string
|
||||
prefix *string
|
||||
}{
|
||||
{``, nil},
|
||||
{`^`, ptr(``)},
|
||||
{`^foo`, ptr(`foo`)},
|
||||
{`^foo/bar\.go`, ptr(`foo/bar.go`)},
|
||||
{`^`, pointers.Ptr(``)},
|
||||
{`^foo`, pointers.Ptr(`foo`)},
|
||||
{`^foo/bar\.go`, pointers.Ptr(`foo/bar.go`)},
|
||||
{`foo/bar\.go`, nil},
|
||||
}
|
||||
|
||||
|
||||
1
enterprise/internal/scim/BUILD.bazel
generated
1
enterprise/internal/scim/BUILD.bazel
generated
@ -69,6 +69,7 @@ go_test(
|
||||
"//internal/txemail",
|
||||
"//internal/types",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"//schema",
|
||||
"@com_github_elimity_com_scim//:scim",
|
||||
"@com_github_elimity_com_scim//errors",
|
||||
|
||||
@ -16,6 +16,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
"github.com/sourcegraph/sourcegraph/schema"
|
||||
)
|
||||
|
||||
@ -122,7 +123,7 @@ func Test_UserResourceHandler_PatchRemoveWithFilter(t *testing.T) {
|
||||
userResourceHandler := NewUserResourceHandler(context.Background(), &observation.TestContext, db)
|
||||
operations := []scim.PatchOperation{
|
||||
{Op: "remove", Path: parseStringPath("emails[type eq \"work\" and primary eq false]")},
|
||||
{Op: "remove", Path: createPath(AttrName, strPtr(AttrNameMiddle))},
|
||||
{Op: "remove", Path: createPath(AttrName, pointers.Ptr(AttrNameMiddle))},
|
||||
}
|
||||
|
||||
userRes, err := userResourceHandler.Patch(createDummyRequest(), "1", operations)
|
||||
@ -237,7 +238,7 @@ func Test_UserResourceHandler_PatchNoChange(t *testing.T) {
|
||||
db := createMockDB()
|
||||
userResourceHandler := NewUserResourceHandler(context.Background(), &observation.TestContext, db)
|
||||
operations := []scim.PatchOperation{
|
||||
{Op: "replace", Path: createPath(AttrName, strPtr(AttrNameGiven)), Value: "Nannie"},
|
||||
{Op: "replace", Path: createPath(AttrName, pointers.Ptr(AttrNameGiven)), Value: "Nannie"},
|
||||
}
|
||||
|
||||
userRes, err := userResourceHandler.Patch(createDummyRequest(), "1", operations)
|
||||
@ -303,7 +304,7 @@ func Test_UserResourceHandler_PatchReactiveUser(t *testing.T) {
|
||||
"type": "work",
|
||||
"value": "primary@work.com",
|
||||
"primary": true
|
||||
},
|
||||
},
|
||||
],
|
||||
"name": {
|
||||
"givenName": "Nannie",
|
||||
@ -421,11 +422,6 @@ func parseStringPath(path string) *filter.Path {
|
||||
return &f
|
||||
}
|
||||
|
||||
// strPtr returns a pointer to the given string.
|
||||
func strPtr(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
// toInterfaceSlice converts a slice of maps to a slice of interfaces.
|
||||
func toInterfaceSlice(maps ...map[string]interface{}) []interface{} {
|
||||
s := make([]interface{}, 0, len(maps))
|
||||
|
||||
1
internal/codeintel/resolvers/BUILD.bazel
generated
1
internal/codeintel/resolvers/BUILD.bazel
generated
@ -22,6 +22,7 @@ go_library(
|
||||
"//internal/markdown",
|
||||
"//internal/types",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"@com_github_graph_gophers_graphql_go//:graphql-go",
|
||||
"@com_github_graph_gophers_graphql_go//relay",
|
||||
],
|
||||
|
||||
@ -6,6 +6,8 @@ import (
|
||||
|
||||
"github.com/graph-gophers/graphql-go"
|
||||
"github.com/graph-gophers/graphql-go/relay"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/lib/pointers"
|
||||
)
|
||||
|
||||
type ConnectionResolver[T any] interface {
|
||||
@ -169,7 +171,7 @@ type ConnectionArgs struct {
|
||||
}
|
||||
|
||||
func (a *ConnectionArgs) Limit(defaultValue int32) int32 {
|
||||
return Deref(a.First, defaultValue)
|
||||
return pointers.Deref(a.First, defaultValue)
|
||||
}
|
||||
|
||||
type PagedConnectionArgs struct {
|
||||
@ -199,30 +201,6 @@ func (er *EmptyResponse) AlwaysNil() *string {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Ptr[T any](v T) *T {
|
||||
return &v
|
||||
}
|
||||
|
||||
func NonZeroPtr[T comparable](v T) *T {
|
||||
if v != zero[T]() {
|
||||
return Ptr(v)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func zero[T any]() (zeroValue T) {
|
||||
return zeroValue
|
||||
}
|
||||
|
||||
func Deref[T any](v *T, defaultValue T) T {
|
||||
if v != nil {
|
||||
return *v
|
||||
}
|
||||
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
func UnmarshalID[T any](id graphql.ID) (val T, err error) {
|
||||
err = relay.UnmarshalSpec(id, &val)
|
||||
return
|
||||
|
||||
1
internal/conf/BUILD.bazel
generated
1
internal/conf/BUILD.bazel
generated
@ -62,6 +62,7 @@ go_test(
|
||||
"//internal/api/internalapi",
|
||||
"//internal/conf/conftypes",
|
||||
"//lib/errors",
|
||||
"//lib/pointers",
|
||||
"//schema",
|
||||
"@com_github_google_go_cmp//cmp",
|
||||
"@com_github_sourcegraph_log//:log",
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user