Skip to content

chore: add tests for creating workspaces from workspace IDs #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 172 additions & 0 deletions workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,46 @@ func TestCreateAndDeleteWorkspace(t *testing.T) {
}
}

func TestCreateAndDeleteWorkspaceFromWorkspace(t *testing.T) {
id, err := g.CreateWorkspace(context.Background(), "directory")
if err != nil {
t.Fatalf("Error creating workspace: %v", err)
}

err = g.WriteFileInWorkspace(context.Background(), "file.txt", []byte("hello world"), WriteFileInWorkspaceOptions{
WorkspaceID: id,
})
if err != nil {
t.Errorf("Error creating file: %v", err)
}

newID, err := g.CreateWorkspace(context.Background(), "directory", id)
if err != nil {
t.Errorf("Error creating workspace from workspace: %v", err)
}

data, err := g.ReadFileInWorkspace(context.Background(), "file.txt", ReadFileInWorkspaceOptions{
WorkspaceID: newID,
})
if err != nil {
t.Errorf("Error reading file: %v", err)
}

if !bytes.Equal(data, []byte("hello world")) {
t.Errorf("Unexpected content: %s", data)
}

err = g.DeleteWorkspace(context.Background(), id)
if err != nil {
t.Errorf("Error deleting workspace: %v", err)
}

err = g.DeleteWorkspace(context.Background(), newID)
if err != nil {
t.Errorf("Error deleting new workspace: %v", err)
}
}

func TestWriteReadAndDeleteFileFromWorkspace(t *testing.T) {
id, err := g.CreateWorkspace(context.Background(), "directory")
if err != nil {
Expand Down Expand Up @@ -270,6 +310,138 @@ func TestCreateAndDeleteWorkspaceS3(t *testing.T) {
}
}

func TestCreateAndDeleteWorkspaceFromWorkspaceS3(t *testing.T) {
if os.Getenv("AWS_ACCESS_KEY_ID") == "" || os.Getenv("AWS_SECRET_ACCESS_KEY") == "" || os.Getenv("WORKSPACE_PROVIDER_S3_BUCKET") == "" {
t.Skip("Skipping test because AWS credentials are not set")
}

id, err := g.CreateWorkspace(context.Background(), "s3")
if err != nil {
t.Fatalf("Error creating workspace: %v", err)
}

err = g.WriteFileInWorkspace(context.Background(), "file.txt", []byte("hello world"), WriteFileInWorkspaceOptions{
WorkspaceID: id,
})
if err != nil {
t.Errorf("Error creating file: %v", err)
}

newID, err := g.CreateWorkspace(context.Background(), "s3", id)
if err != nil {
t.Errorf("Error creating workspace from workspace: %v", err)
}

data, err := g.ReadFileInWorkspace(context.Background(), "file.txt", ReadFileInWorkspaceOptions{
WorkspaceID: newID,
})
if err != nil {
t.Errorf("Error reading file: %v", err)
}

if !bytes.Equal(data, []byte("hello world")) {
t.Errorf("Unexpected content: %s", data)
}

err = g.DeleteWorkspace(context.Background(), id)
if err != nil {
t.Errorf("Error deleting workspace: %v", err)
}

err = g.DeleteWorkspace(context.Background(), newID)
if err != nil {
t.Errorf("Error deleting new workspace: %v", err)
}
}

func TestCreateAndDeleteDirectoryWorkspaceFromWorkspaceS3(t *testing.T) {
if os.Getenv("AWS_ACCESS_KEY_ID") == "" || os.Getenv("AWS_SECRET_ACCESS_KEY") == "" || os.Getenv("WORKSPACE_PROVIDER_S3_BUCKET") == "" {
t.Skip("Skipping test because AWS credentials are not set")
}

id, err := g.CreateWorkspace(context.Background(), "s3")
if err != nil {
t.Fatalf("Error creating workspace: %v", err)
}

err = g.WriteFileInWorkspace(context.Background(), "file.txt", []byte("hello world"), WriteFileInWorkspaceOptions{
WorkspaceID: id,
})
if err != nil {
t.Errorf("Error creating file: %v", err)
}

newID, err := g.CreateWorkspace(context.Background(), "directory", id)
if err != nil {
t.Errorf("Error creating workspace from workspace: %v", err)
}

data, err := g.ReadFileInWorkspace(context.Background(), "file.txt", ReadFileInWorkspaceOptions{
WorkspaceID: newID,
})
if err != nil {
t.Errorf("Error reading file: %v", err)
}

if !bytes.Equal(data, []byte("hello world")) {
t.Errorf("Unexpected content: %s", data)
}

err = g.DeleteWorkspace(context.Background(), id)
if err != nil {
t.Errorf("Error deleting workspace: %v", err)
}

err = g.DeleteWorkspace(context.Background(), newID)
if err != nil {
t.Errorf("Error deleting new workspace: %v", err)
}
}

func TestCreateAndDeleteS3WorkspaceFromWorkspaceDirectory(t *testing.T) {
if os.Getenv("AWS_ACCESS_KEY_ID") == "" || os.Getenv("AWS_SECRET_ACCESS_KEY") == "" || os.Getenv("WORKSPACE_PROVIDER_S3_BUCKET") == "" {
t.Skip("Skipping test because AWS credentials are not set")
}

id, err := g.CreateWorkspace(context.Background(), "s3")
if err != nil {
t.Fatalf("Error creating workspace: %v", err)
}

err = g.WriteFileInWorkspace(context.Background(), "file.txt", []byte("hello world"), WriteFileInWorkspaceOptions{
WorkspaceID: id,
})
if err != nil {
t.Errorf("Error creating file: %v", err)
}

newID, err := g.CreateWorkspace(context.Background(), "directory", id)
if err != nil {
t.Errorf("Error creating workspace from workspace: %v", err)
}

data, err := g.ReadFileInWorkspace(context.Background(), "file.txt", ReadFileInWorkspaceOptions{
WorkspaceID: newID,
})
if err != nil {
t.Errorf("Error reading file: %v", err)
}

if !bytes.Equal(data, []byte("hello world")) {
t.Errorf("Unexpected content: %s", data)
}

err = g.DeleteWorkspace(context.Background(), id)
if err != nil {
t.Errorf("Error deleting workspace: %v", err)
}

err = g.DeleteWorkspace(context.Background(), newID)
if err != nil {
t.Errorf("Error deleting new workspace: %v", err)
}
}

func TestWriteReadAndDeleteFileFromWorkspaceS3(t *testing.T) {
if os.Getenv("AWS_ACCESS_KEY_ID") == "" || os.Getenv("AWS_SECRET_ACCESS_KEY") == "" || os.Getenv("WORKSPACE_PROVIDER_S3_BUCKET") == "" {
t.Skip("Skipping test because AWS credentials are not set")
Expand Down
Loading