Added tests

This commit is contained in:
Shreyas Goenka 2023-04-19 16:32:50 +02:00
parent 8da8dd579d
commit f8d3c1d50c
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
1 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,62 @@
package terraform
import (
"testing"
tfjson "github.com/hashicorp/terraform-json"
"github.com/stretchr/testify/assert"
)
func TestResourceChangeEventForCreateJob(t *testing.T) {
tfChange := tfjson.ResourceChange{
Change: &tfjson.Change{
Actions: []tfjson.Action{"create"},
},
Type: "databricks_job",
Name: "foo",
}
bundleChange := toResourceChangeEvent(&tfChange)
assert.Equal(t, "create", string(bundleChange.Action))
assert.Equal(t, "job", string(bundleChange.ResourceType))
assert.Equal(t, "foo", string(bundleChange.Name))
}
func TestResourceChangeEventForReplacePipeline(t *testing.T) {
tfChange := tfjson.ResourceChange{
Change: &tfjson.Change{
Actions: []tfjson.Action{"delete", "create"},
},
Type: "databricks_pipeline",
Name: "bar",
}
bundleChange := toResourceChangeEvent(&tfChange)
assert.Equal(t, "replace", string(bundleChange.Action))
assert.Equal(t, "pipeline", string(bundleChange.ResourceType))
assert.Equal(t, "bar", string(bundleChange.Name))
}
func TesResourceChangeEventForDeleteExperiment(t *testing.T) {
tfChange := tfjson.ResourceChange{
Change: &tfjson.Change{
Actions: []tfjson.Action{"delete"},
},
Type: "databricks_mlflow_experiment",
Name: "my_exp",
}
bundleChange := toResourceChangeEvent(&tfChange)
assert.Equal(t, "delete", string(bundleChange.Action))
assert.Equal(t, "mlflow_experiment", string(bundleChange.ResourceType))
assert.Equal(t, "my_exp", string(bundleChange.Name))
}
func TestResourceChangeEventToString(t *testing.T) {
event := ResourceChangeEvent{
Name: "foo",
ResourceType: "job",
Action: ActionCreate,
}
assert.Equal(t, " create job foo", event.String())
}