github.com/leg100/ots@v0.0.7-0.20210919080622-034055ced4bd/cmd/ots/client_fake.go (about) 1 package main 2 3 import ( 4 "context" 5 6 "github.com/leg100/go-tfe" 7 ) 8 9 type FakeClientConfig struct{} 10 11 func (f FakeClientConfig) NewClient() (Client, error) { return &FakeClient{}, nil } 12 13 type FakeClient struct { 14 Client 15 } 16 17 func (f FakeClient) Organizations() tfe.Organizations { return &FakeOrganizationsClient{} } 18 19 func (f FakeClient) Workspaces() tfe.Workspaces { return &FakeWorkspacesClient{} } 20 21 type FakeOrganizationsClient struct { 22 tfe.Organizations 23 } 24 25 func (f *FakeOrganizationsClient) Create(ctx context.Context, opts tfe.OrganizationCreateOptions) (*tfe.Organization, error) { 26 return &tfe.Organization{ 27 Name: *opts.Name, 28 Email: *opts.Email, 29 }, nil 30 } 31 32 type FakeWorkspacesClient struct { 33 tfe.Workspaces 34 } 35 36 func (f *FakeWorkspacesClient) Read(ctx context.Context, org string, ws string) (*tfe.Workspace, error) { 37 return &tfe.Workspace{ 38 ID: "ws-123", 39 }, nil 40 } 41 42 func (f *FakeWorkspacesClient) List(ctx context.Context, org string, opts tfe.WorkspaceListOptions) (*tfe.WorkspaceList, error) { 43 return &tfe.WorkspaceList{ 44 Items: []*tfe.Workspace{ 45 { 46 ID: "ws-123", 47 }, 48 }, 49 }, nil 50 } 51 52 func (f *FakeWorkspacesClient) Update(ctx context.Context, org string, ws string, opts tfe.WorkspaceUpdateOptions) (*tfe.Workspace, error) { 53 return &tfe.Workspace{ 54 ID: "ws-123", 55 }, nil 56 } 57 58 func (f *FakeWorkspacesClient) Lock(ctx context.Context, id string, opts tfe.WorkspaceLockOptions) (*tfe.Workspace, error) { 59 return &tfe.Workspace{ 60 ID: "ws-123", 61 }, nil 62 } 63 64 func (f *FakeWorkspacesClient) Unlock(ctx context.Context, id string) (*tfe.Workspace, error) { 65 return &tfe.Workspace{ 66 ID: "ws-123", 67 }, nil 68 }