Skip to content

Commit

Permalink
atlasexec: add tests for multiple targets
Browse files Browse the repository at this point in the history
  • Loading branch information
giautm committed Sep 12, 2024
1 parent b13dd7f commit b106740
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions atlasexec/atlas_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,3 +625,35 @@ func TestSchema_Apply(t *testing.T) {
})
}
}

func TestSchema_ApplyEnvs(t *testing.T) {
wd, err := os.Getwd()
require.NoError(t, err)
c, err := atlasexec.NewClient(t.TempDir(), filepath.Join(wd, "./mock-atlas.sh"))
require.NoError(t, err)
require.NoError(t, c.SetEnv(map[string]string{
"TEST_ARGS": "schema apply --format {{ json . }} --env test",
"TEST_STDOUT": `{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Host":"local-su.db"}}
{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Host":"local-pi.db"}}
{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Host":"local-bu.db"}}`,
"TEST_STDERR": `Abort: The plan "From" hash does not match the current state hash (passed with --from):
- iHZMQ1EoarAXt/KU0KQbBljbbGs8gVqX2ZBXefePSGE= (plan value)
+ Cp8xCVYilZuwULkggsfJLqIQHaxYcg/IpU+kgjVUBA4= (current hash)
`,
}))
result, err := c.SchemaApply(context.Background(), &atlasexec.SchemaApplyParams{
Env: "test",
})
require.ErrorContains(t, err, `The plan "From" hash does not match the current state hash`)
require.Nil(t, result)

err2, ok := err.(*atlasexec.SchemaApplyError)
require.True(t, ok, "should be a SchemaApplyError, got %T", err)
require.Contains(t, err2.Stderr, `Abort: The plan "From" hash does not match the current state hash (passed with --from)`)
require.Len(t, err2.Result, 3, "should returns succeed results")
require.Equal(t, "sqlite://local-su.db", err2.Result[0].URL.String())
require.Equal(t, "sqlite://local-pi.db", err2.Result[1].URL.String())
require.Equal(t, "sqlite://local-bu.db", err2.Result[2].URL.String())
}

0 comments on commit b106740

Please sign in to comment.