Skip to content

Commit

Permalink
Update e2e tests to export only what's defined in si-migrator.yml (#13)
Browse files Browse the repository at this point in the history
* Exclude log files

* Update e2e tests to export only what's defined in si-migrator.yml

* Update to relative path

* Remove accidental commited files

* Remove accidental commited files

* Restore removed broker name check

* Replace call to defunct os.TempDir with 2 params

* Update DEVELOPMENT.md

* Update wording in DEVELOPMENT.md

* Remove extra slash
  • Loading branch information
malston committed Apr 2, 2024
1 parent 136431d commit 7a484d5
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# log files
*.log

# coverage artifacts
/coverage.txt
/coverage.html
Expand Down
47 changes: 47 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,51 @@ Run the tests
make test-e2e
```

If you only want to test the migration of a single service, then include the migration config for just that service. You also do not need to migrate from one
foundation to another. You can specify the same `url` for the Ops Manager in both `source` and `target` foundations of the config and that will export from one
space to another. Here's an example:

```sh
cat ./test/e2e/si-migrator.yml <<EOF
debug: true
exclude_orgs:
- system
- p-spring-cloud-services
- p-dataflow
foundations:
source:
url: https://opsman.east.acme.com
username: admin
password: 'XPrQWi9xvwta$Ng'
hostname: opsman.east.acme.com
private_key: ~/.ssh/acme-east-prod
ssh_user: "ubuntu"
target:
url: https://opsman.east.acme.com
username: admin
password: 'XPrQWi9xvwta$Ng'
hostname: opsman.east.acme.com
private_key: ~/.ssh/acme-east-prod
ssh_user: "ubuntu"
migration:
use_default_migrator: true
migrators:
- name: mysql
migrator:
backup_type: scp
scp:
username: ubuntu
hostname: opsman.east.acme.com
port: 22
destination_directory: /home/ubuntu
private_key: ~/.ssh/acme-east-prod
EOF
```

Then we can test exporting just mysql and the user-provided service instance bindings

```sh
make test-export-space
```

Run `make help` for all other tasks.
3 changes: 1 addition & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,7 @@ func newCFClient(t *testing.T, config *cf.Config) cf.Client {
}

func buildSIMigrator(t *testing.T) string {
tmpDir, err := os.TempDir("", "si_artifacts")
require.NoError(t, err, "Error generating a temp artifact dir")
tmpDir := os.TempDir()

executable := filepath.Join(tmpDir, path.Base(packagePath))
if runtime.GOOS == "windows" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (c OpsManager) ValidateSSH() error {
return nil
}

/// initConfig reads in config file and ENV variables if set.
// initConfig reads in config file and ENV variables if set.
func (c *Config) initViperConfig() {
v := viper.New()
if c.ConfigFile != "" {
Expand Down
1 change: 1 addition & 0 deletions test/e2e/export_space_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

func Test_ExportOrgSpaceCommand(t *testing.T) {
test.Setup(t)
test.SetupExportCommand(t)

exportOrgSpace(t)
}
Expand Down
56 changes: 48 additions & 8 deletions test/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ func SetupExportCommand(t *testing.T) cf.Client {
org := createOrg(t, client, ExportOrgName)
space := createSpace(t, client, SpaceName, org.Guid)

createUserProvidedServiceInstance(t, client, space.Guid)
createCredhubService(t, client, space.Guid)
//createSQLServerService(t, client, space.Guid)
createMySQLService(t, client, space.Guid)
createMigrationServices(t, client, space.Guid)

return client
}
Expand Down Expand Up @@ -236,6 +233,47 @@ func createSpace(t *testing.T, client cf.Client, spaceName string, orgGuid strin
return space
}

func createMigrationServices(t *testing.T, client cf.Client, spaceGuid string) {
createUserProvidedServiceInstance(t, client, spaceGuid)

cwd, err := os.Getwd()
if err != nil {
log.Fatalf("could not get current working dir, %s", err)
}

_ = os.Unsetenv("SI_MIGRATOR_CONFIG_FILE")
_ = os.Unsetenv("SI_MIGRATOR_CONFIG_HOME")
err = os.Setenv("SI_MIGRATOR_CONFIG_HOME", cwd)
if err != nil {
log.Fatalf("could not set SI_MIGRATOR_CONFIG_HOME to %s: %v", cwd, err)
}

cfg := config.New("", path.Join(cwd, "si-migrator.yml"))
if err != nil {
log.Fatalf("could not load config, %s", err)
}

mr, err := config.NewMigrationReader(cfg)
require.NoErrorf(t, err, "error reading migrator from config: %s", cfg.ConfigFile)

var migration *config.Migration
migration, err = mr.GetMigration()
require.NoErrorf(t, err, "error reading migrator from config: %s", cfg.ConfigFile)

if migration != nil {
for _, m := range migration.Migrators {
switch m.Name {
case migrate.MySQL.String():
createMySQLService(t, client, spaceGuid)
case migrate.SQLServer.String():
createSQLServerService(t, client, spaceGuid)
case migrate.CredHub.String():
createCredhubService(t, client, spaceGuid)
}
}
}
}

func createUserProvidedServiceInstance(t *testing.T, client cf.Client, spaceGuid string) {
_, err := client.CreateUserProvidedServiceInstance(cfclient.UserProvidedServiceInstanceRequest{
Name: "si-migrator-ups",
Expand Down Expand Up @@ -290,13 +328,17 @@ func createManagedServiceInstance(t *testing.T, client cf.Client, space cfclient
if broker.Name != brokerName {
t.Fatalf("failed to find broker by name: %s", brokerName)
}

var plans []cfclient.ServicePlan
plans, err = client.ListServicePlansByQuery(url.Values{
"q": []string{"service_broker_guid:" + broker.Guid},
})
require.NoError(t, err, "error listing plans by broker guid: %s", broker.Guid)

servicePlan := plans[0] // default to the first plan
var servicePlan cfclient.ServicePlan
if len(plans) > 0 {
servicePlan = plans[0] // default to the first plan
}
for i, p := range plans {
if p.Name == planName {
servicePlan = plans[i]
Expand Down Expand Up @@ -404,9 +446,7 @@ func initLogger(level string) {
}

func buildSIMigrator(t *testing.T) string {
tmpDir, err := os.TempDir("", "si_artifacts")
require.NoError(t, err, "Error generating a temp artifact dir")

tmpDir := os.TempDir()
executable := filepath.Join(tmpDir, path.Base(packagePath))
if runtime.GOOS == "windows" {
executable = executable + ".exe"
Expand Down

0 comments on commit 7a484d5

Please sign in to comment.