Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/google.golang.org/api-…
Browse files Browse the repository at this point in the history
…0.148.0
  • Loading branch information
dsuhinin authored Oct 20, 2023
2 parents feb0e5e + 0e7a64b commit 25e6763
Show file tree
Hide file tree
Showing 12 changed files with 298 additions and 43 deletions.
21 changes: 17 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}",
"program": "${workspaceFolder}/main.go",
"buildFlags": "-tags '${config:go.buildTags}'",
"args": [
"server",
Expand All @@ -22,7 +22,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}",
"program": "${workspaceFolder}/main.go",
"buildFlags": "-tags '${config:go.buildTags}'",
"args": [
"server",
Expand All @@ -35,7 +35,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}",
"program": "${workspaceFolder}/main.go",
"buildFlags": "-tags '${config:go.buildTags}'",
"args": [
"server",
Expand All @@ -48,13 +48,26 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}",
"program": "${workspaceFolder}/main.go",
"buildFlags": "-tags '${config:go.buildTags}'",
"args": [
"server",
"--database-uri",
"sqlite://encrypted.db?_key=passphrase"
],
},
{
"name": "Launch server (supports integration tests)",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"buildFlags": "-tags '${config:go.buildTags}'",
"args": [
"server",
"--database-uri",
"sqlite:///tmp/fasttrackml.db"
],
}
]
}
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
// Please keep the content of go.buildTags identical to the content of the authoritative file .go-build-tags
"go.buildTags": "netgo,osusergo,sqlite_foreign_keys,sqlite_math_functions,sqlite_omit_load_extension,sqlite_unlock_notify,sqlite_vacuum_incr",
// Please keep the content of go.buildTags identical to the content of the authoritative file .go-build-tags (but add integration tests tag here)
"go.buildTags": "netgo,osusergo,sqlite_foreign_keys,sqlite_math_functions,sqlite_omit_load_extension,sqlite_unlock_notify,sqlite_vacuum_incr,integration",
"gopls": {
"formatting.local": "github.com/G-Research/fasttrackml",
"formatting.gofumpt": true
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ services:

minio:
image: minio/minio:latest
entrypoint: sh
command: -c 'mkdir -p /data/{bucket1,bucket2,bucket3} && exec minio server /data'
command: server /data
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 5s
Expand Down
27 changes: 24 additions & 3 deletions tests/integration/golang/aim/app/update_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ func (s *UpdateAppTestSuite) Test_Ok() {
"/apps/%s", app.ID,
),
)
assert.Nil(
s.T(),
s.AIMClient.WithMethod(
http.MethodPut,
).WithRequest(
tt.requestBody,
).WithResponse(
&resp,
).DoRequest(
"/apps/%s", app.ID,
),
)
assert.Equal(s.T(), "app-type", resp.Type)
assert.Equal(s.T(), response.AppState{"app-state-key": "new-app-state-value"}, resp.State)
})
Expand Down Expand Up @@ -116,13 +128,23 @@ func (s *UpdateAppTestSuite) Test_Error() {

tests := []struct {
name string
ID uuid.UUID
requestBody any
error string
}{
{
name: "UpdateAppWithIncorrectState",
ID: app.ID,
requestBody: map[string]any{
"State": "this-cannot-unmarshal",
},
error: "cannot unmarshal",
},
{
name: "UpdateAppWithUnknownID",
ID: uuid.New(),
requestBody: map[string]any{},
error: "Not Found",
},
}
for _, tt := range tests {
Expand All @@ -137,11 +159,10 @@ func (s *UpdateAppTestSuite) Test_Error() {
).WithResponse(
&resp,
).DoRequest(
"/apps/%s", app.ID,
"/apps/%s", tt.ID,
),
)
assert.Nil(s.T(), err)
assert.Contains(s.T(), resp.Message, "cannot unmarshal")
assert.Contains(s.T(), resp.Message, tt.error)
})
}
}
25 changes: 23 additions & 2 deletions tests/integration/golang/aim/dashboard/update_dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ func (s *UpdateDashboardTestSuite) Test_Ok() {
"/dashboards/%s", dashboard.ID,
),
)
assert.Nil(
s.T(),
s.AIMClient.WithMethod(
http.MethodPut,
).WithRequest(
tt.requestBody,
).WithResponse(
&resp,
).DoRequest(
"/dashboards/%s", dashboard.ID,
),
)

actualDashboard, err := s.DashboardFixtures.GetDashboardByID(context.Background(), dashboard.ID.String())

Expand Down Expand Up @@ -147,13 +159,22 @@ func (s *UpdateDashboardTestSuite) Test_Error() {

tests := []struct {
name string
ID uuid.UUID
requestBody map[string]interface{}
error string
}{
{
name: "UpdateDashboardWithIncorrectDescriptionType",
ID: dashboard.ID,
requestBody: map[string]interface{}{
"Description": map[string]interface{}{"Description": "latest-description"},
},
error: "cannot unmarshal",
},
{
name: "UpdateDashboardWithUnknownID",
ID: uuid.New(),
error: "Not Found",
},
}
for _, tt := range tests {
Expand All @@ -166,9 +187,9 @@ func (s *UpdateDashboardTestSuite) Test_Error() {
).WithResponse(
&resp,
).DoRequest(
"/dashboards/%s", dashboard.ID,
"/dashboards/%s", tt.ID,
))
assert.Contains(s.T(), resp.Message, "cannot unmarshal")
assert.Contains(s.T(), resp.Message, tt.error)
})
}
}
18 changes: 13 additions & 5 deletions tests/integration/golang/aim/experiment/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,20 @@ func (s *DeleteExperimentTestSuite) Test_Error() {
assert.Nil(s.T(), err)

tests := []struct {
name string
ID string
name string
ID string
error string
}{
{
ID: "123",
name: "DeleteWithUnknownIDFails",
ID: "123",
name: "DeleteWithUnknownIDFails",
error: "Not Found",
},
{
name: "DeleteIncorrectExperimentID",
error: `: unable to parse experiment id "incorrect_experiment_id": strconv.ParseInt:` +
` parsing "incorrect_experiment_id": invalid syntax`,
ID: "incorrect_experiment_id",
},
}
for _, tt := range tests {
Expand All @@ -121,7 +129,7 @@ func (s *DeleteExperimentTestSuite) Test_Error() {
"/experiments/%s", tt.ID,
),
)
assert.Contains(s.T(), resp.Error(), "Not Found")
assert.Contains(s.T(), resp.Error(), tt.error)
assert.NoError(s.T(), err)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,20 @@ func (s *GetExperimentActivityTestSuite) Test_Error() {
assert.Nil(s.T(), err)

tests := []struct {
name string
ID string
name string
ID string
error string
}{
{
name: "GetInvalidExperimentID",
ID: "123",
name: "GetInvalidExperimentID",
ID: "123",
error: "Not Found",
},
{
name: "DeleteIncorrectExperimentID",
error: `: unable to parse experiment id "incorrect_experiment_id": strconv.ParseInt:` +
` parsing "incorrect_experiment_id": invalid syntax`,
ID: "incorrect_experiment_id",
},
}
for _, tt := range tests {
Expand All @@ -94,9 +102,9 @@ func (s *GetExperimentActivityTestSuite) Test_Error() {
assert.Nil(s.T(), s.AIMClient.WithQuery(map[any]any{
"limit": 4,
}).WithResponse(&resp).DoRequest(
"/experiments/%s/runs", tt.ID,
"/experiments/%s/activity", tt.ID,
))
assert.Contains(s.T(), resp.Error(), "Not Found")
assert.Contains(s.T(), resp.Error(), tt.error)
})
}
}
14 changes: 12 additions & 2 deletions tests/integration/golang/aim/run/update_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,23 @@ func (s *UpdateRunTestSuite) Test_Error() {
}()
tests := []struct {
name string
ID string
requestBody any
error string
}{
{
name: "UpdateRunWithIncorrectArchived",
ID: s.run.ID,
requestBody: map[string]any{
"Archived": "this-cannot-unmarshal",
},
error: "cannot unmarshal",
},
{
name: "UpdateRunWithUnknownID",
ID: "incorrect-ID",
requestBody: map[string]any{},
error: "unable to find run 'incorrect-ID'",
},
}
for _, tt := range tests {
Expand All @@ -119,10 +129,10 @@ func (s *UpdateRunTestSuite) Test_Error() {
).WithResponse(
&resp,
).DoRequest(
"/runs/%s", s.run.ID,
"/runs/%s", tt.ID,
),
)
assert.Contains(s.T(), resp.Message, "cannot unmarshal")
assert.Contains(s.T(), resp.Message, tt.error)
})
}
}
72 changes: 72 additions & 0 deletions tests/integration/golang/helpers/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package helpers

import (
"context"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
awsConfig "github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/rotisserie/eris"
)

var testBuckets = []string{"bucket1", "bucket2"}

// NewS3Client creates new instance of S3 client.
func NewS3Client(endpoint string) (*s3.Client, error) {
cfg, err := awsConfig.LoadDefaultConfig(context.Background(), awsConfig.WithEndpointResolverWithOptions(
Expand All @@ -31,3 +35,71 @@ func NewS3Client(endpoint string) (*s3.Client, error) {
o.UsePathStyle = true
}), nil
}

// CreateBuckets creates the test bucekts.
func CreateBuckets(s3Client *s3.Client) error {
for _, bucket := range testBuckets {
_, err := s3Client.CreateBucket(context.Background(), &s3.CreateBucketInput{
Bucket: aws.String(bucket),
})
if err != nil {
return eris.Wrapf(err, "failed to create bucket '%s'", bucket)
}
}
return nil
}

// RemoveBuckets removes the test buckets.
func RemoveBuckets(s3Client *s3.Client) error {
for _, bucket := range testBuckets {
if err := removeBucket(s3Client, bucket); err != nil {
return eris.Wrapf(err, "failed to remove bucket '%s'", bucket)
}
}
return nil
}

// removeBucket removes a bucket and its objects.
func removeBucket(s3Client *s3.Client, bucket string) error {
// Delete all objects in the bucket
var objectIDs []types.ObjectIdentifier
paginator := s3.NewListObjectsV2Paginator(s3Client, &s3.ListObjectsV2Input{
Bucket: aws.String(bucket),
})
for paginator.HasMorePages() {
page, err := paginator.NextPage(context.Background())
if err != nil {
return eris.Wrapf(err, "error paging objects in bucket '%s'", bucket)
}
for _, object := range page.Contents {
objectIDs = append(objectIDs, types.ObjectIdentifier{Key: object.Key})
}
}
if len(objectIDs) > 0 {
_, err := s3Client.DeleteObjects(context.Background(), &s3.DeleteObjectsInput{
Bucket: aws.String(bucket),
Delete: &types.Delete{Objects: objectIDs},
})
if err != nil {
return eris.Wrapf(err, "failed to delete objects in bucket '%s'", bucket)
}
}

// Delete the bucket
if _, err := s3Client.DeleteBucket(context.Background(), &s3.DeleteBucketInput{
Bucket: aws.String(bucket),
}); err != nil {
return eris.Wrapf(err, "failed to delete bucket '%s'", bucket)
}
waiter := s3.NewBucketNotExistsWaiter(s3Client)
if err := waiter.Wait(
context.Background(),
&s3.HeadBucketInput{
Bucket: aws.String(bucket),
},
time.Second*10,
); err != nil {
return eris.Wrapf(err, "error waiting for bucket '%s' deletion", bucket)
}
return nil
}
Loading

0 comments on commit 25e6763

Please sign in to comment.