2023-04-17 10:21:21 +00:00
package config_tests
import (
"context"
"fmt"
"path/filepath"
"testing"
2023-05-16 16:35:39 +00:00
"github.com/databricks/cli/bundle"
2024-03-27 10:49:05 +00:00
"github.com/databricks/cli/bundle/phases"
2023-04-17 10:21:21 +00:00
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestConflictingResourceIdsNoSubconfig ( t * testing . T ) {
2023-08-11 12:28:05 +00:00
ctx := context . Background ( )
2024-03-27 10:49:05 +00:00
b , err := bundle . Load ( ctx , "./conflicting_resource_ids/no_subconfigurations" )
require . NoError ( t , err )
diags := bundle . Apply ( ctx , b , phases . Load ( ) )
2023-07-18 10:16:34 +00:00
bundleConfigPath := filepath . FromSlash ( "conflicting_resource_ids/no_subconfigurations/databricks.yml" )
2024-03-27 10:49:05 +00:00
assert . ErrorContains ( t , diags . Error ( ) , fmt . Sprintf ( "multiple resources named foo (job at %s, pipeline at %s)" , bundleConfigPath , bundleConfigPath ) )
2023-04-17 10:21:21 +00:00
}
func TestConflictingResourceIdsOneSubconfig ( t * testing . T ) {
2023-08-11 12:28:05 +00:00
ctx := context . Background ( )
b , err := bundle . Load ( ctx , "./conflicting_resource_ids/one_subconfiguration" )
2023-04-17 10:21:21 +00:00
require . NoError ( t , err )
2024-03-27 10:49:05 +00:00
diags := bundle . Apply ( ctx , b , phases . Load ( ) )
2023-07-18 10:16:34 +00:00
bundleConfigPath := filepath . FromSlash ( "conflicting_resource_ids/one_subconfiguration/databricks.yml" )
2023-04-17 10:21:21 +00:00
resourcesConfigPath := filepath . FromSlash ( "conflicting_resource_ids/one_subconfiguration/resources.yml" )
2024-03-25 14:18:47 +00:00
assert . ErrorContains ( t , diags . Error ( ) , fmt . Sprintf ( "multiple resources named foo (job at %s, pipeline at %s)" , bundleConfigPath , resourcesConfigPath ) )
2023-04-17 10:21:21 +00:00
}
func TestConflictingResourceIdsTwoSubconfigs ( t * testing . T ) {
2023-08-11 12:28:05 +00:00
ctx := context . Background ( )
b , err := bundle . Load ( ctx , "./conflicting_resource_ids/two_subconfigurations" )
2023-04-17 10:21:21 +00:00
require . NoError ( t , err )
2024-03-27 10:49:05 +00:00
diags := bundle . Apply ( ctx , b , phases . Load ( ) )
2023-04-17 10:21:21 +00:00
resources1ConfigPath := filepath . FromSlash ( "conflicting_resource_ids/two_subconfigurations/resources1.yml" )
resources2ConfigPath := filepath . FromSlash ( "conflicting_resource_ids/two_subconfigurations/resources2.yml" )
2024-03-25 14:18:47 +00:00
assert . ErrorContains ( t , diags . Error ( ) , fmt . Sprintf ( "multiple resources named foo (job at %s, pipeline at %s)" , resources1ConfigPath , resources2ConfigPath ) )
2023-04-17 10:21:21 +00:00
}