Skip to content
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

Dave/stalwart 27 #6719

Merged
merged 8 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
22 changes: 18 additions & 4 deletions components/infra-proxy-service/migrations/pipeline/utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/chef/automate/api/interservice/authz"
"github.com/chef/automate/components/infra-proxy-service/pipeline"
"github.com/chef/automate/components/infra-proxy-service/storage"
log "github.com/sirupsen/logrus"
"io"
"os"
"path"
"path/filepath"

"github.com/chef/automate/api/interservice/authz"
"github.com/chef/automate/components/infra-proxy-service/pipeline"
"github.com/chef/automate/components/infra-proxy-service/storage"
log "github.com/sirupsen/logrus"
)

// StoreOrgs reads the Result struct and populate the orgs table
Expand Down Expand Up @@ -341,3 +342,16 @@ func Unzip(ctx context.Context, mst storage.MigrationStorage, result pipeline.Re
}
return result, nil
}

func ValidateZip(ctx context.Context, st storage.Storage, mst storage.MigrationStorage, result pipeline.Result) (pipeline.Result, error) {
unzipFolder := result.Meta.UnzipFolder

_, err := os.Stat(unzipFolder + "/organizations")
if err != nil {
log.Errorf("Failed to validate unzip folder for migration id %s : %s", result.Meta.MigrationID, err.Error())
return result, err
}

result.Meta.IsValid = true
return result, nil
}
22 changes: 22 additions & 0 deletions components/infra-proxy-service/migrations/pipeline/utility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/chef/automate/components/infra-proxy-service/storage/testDB"
"github.com/golang/mock/gomock"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
)

func TestStoreOrg(t *testing.T) {
Expand Down Expand Up @@ -129,3 +130,24 @@ func TestCreatePreview(t *testing.T) {
})
}
}

func TestValidateZip(t *testing.T) {
type args struct {
ctx context.Context
st storage.Storage
mst storage.MigrationStorage
result pipeline.Result
}

arg := args{
ctx: context.Background(),
st: &testDB.TestDB{},
mst: &testDB.MigrationDB{},
result: pipeline.Result{Meta: pipeline.Meta{UnzipFolder: "../../testdata/backup", ServerID: "server1", MigrationID: "mig1"}},
}

res, err := ValidateZip(arg.ctx, arg.st, arg.mst, arg.result)
require.NoError(t, err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need these assertions? can we check the desired result and what we got, like other test cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are doing it already require.True(t, res.Meta.IsValid)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think then require.True is only required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

require.True(t, res.Meta.IsValid)
require.NotNil(t, res)
}
3 changes: 3 additions & 0 deletions components/infra-proxy-service/pipeline/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ type Meta struct {

// Migration ID
MigrationID string `json:"migration_id"`

// To check whether zip file extracted successfully
IsValid bool `json:"is_valid"`
}

type StageResult struct {
Expand Down