forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuser.go
More file actions
32 lines (26 loc) · 896 Bytes
/
user.go
File metadata and controls
32 lines (26 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package codehost_testing
import (
"context"
"github.com/google/go-github/v55/github"
"github.com/sourcegraph/sourcegraph/lib/errors"
)
// User represents a GitHub user in the scenario.
type User struct {
s *GitHubScenario
name string
}
// Get returns the corresponding GitHub user object that was created by the `CreateUser`
//
// This method will only return a User if the Scenario that created it has been applied otherwise
// it will panic.
func (u *User) Get(ctx context.Context) (*github.User, error) {
if u.s.IsApplied() {
return u.get(ctx)
}
return nil, errors.New("cannot retrieve user before scenario is applied")
}
// get retrieves the GitHub user without panicking if not applied. It is meant as an
// internal helper method while actions are getting applied.
func (u *User) get(ctx context.Context) (*github.User, error) {
return u.s.client.GetUser(ctx, u.name)
}