@@ -33,7 +33,7 @@ impl Templater for DBTTemplater {
33
33
_: & Option < Arc < dyn Formatter > > ,
34
34
) -> Result < TemplatedFile , SQLFluffUserError > {
35
35
let templated_file = Python :: with_gil ( |py| -> PyResult < TemplatedFile > {
36
- let files = [
36
+ let files = [
37
37
(
38
38
"sqruff_templaters/dbt_templater.py" ,
39
39
include_str ! ( "sqruff_templaters/dbt_templater.py" ) ,
@@ -85,3 +85,55 @@ impl Templater for DBTTemplater {
85
85
Ok ( templated_file)
86
86
}
87
87
}
88
+
89
+ #[ cfg( test) ]
90
+ mod tests {
91
+ use super :: * ;
92
+ use std:: path:: PathBuf ;
93
+ #[ test]
94
+ fn test_dbt_simple ( ) {
95
+ let templater = DBTTemplater ;
96
+ let crate_location = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
97
+ let file = crate_location. join ( "src" ) . join ( "templaters" ) . join ( "dbt.rs" ) ;
98
+ let project_dir = file
99
+ . parent ( )
100
+ . unwrap ( )
101
+ . join ( "sqruff_templaters" )
102
+ . join ( "sample_dbt" )
103
+ . canonicalize ( )
104
+ . unwrap ( ) ;
105
+ let profiles_dir = project_dir. join ( ".profiles" ) . canonicalize ( ) . unwrap ( ) ;
106
+ let file_path = project_dir
107
+ . join ( "models/example/my_first_dbt_model.sql" )
108
+ . canonicalize ( )
109
+ . unwrap ( ) ;
110
+ let config = format ! (
111
+ r#"
112
+ [sqruff]
113
+ templater = dbt
114
+ [sqruff:templater:dbt]
115
+ project_dir = {project_dir}
116
+ profiles_dir = {profiles_dir}
117
+ "# ,
118
+ project_dir = project_dir. to_str( ) . unwrap( ) ,
119
+ profiles_dir = profiles_dir. to_str( ) . unwrap( )
120
+ ) ;
121
+ let fluff_config = FluffConfig :: from_source ( & config, None ) ;
122
+ let templated_file = templater
123
+ . process (
124
+ r#"
125
+ {{ config(materialized='table') }}
126
+ with source_data as (
127
+ select 1 as id
128
+ union all
129
+ select null as id
130
+ )
131
+ "# ,
132
+ file_path. to_str ( ) . unwrap ( ) ,
133
+ & fluff_config,
134
+ & None ,
135
+ )
136
+ . unwrap ( ) ;
137
+ assert ! ( !templated_file. sliced_file. is_empty( ) ) ;
138
+ }
139
+ }
0 commit comments