github.com/tooploox/oya@v0.0.21-0.20230524103240-1cda1861aad6/features/render.feature (about)

     1  Feature: Rendering templates
     2  
     3  Background:
     4     Given I'm in project dir
     5  
     6  Scenario: Render a template
     7    Given file ./Oyafile containing
     8      """
     9      Project: project
    10      Values:
    11        foo: xxx
    12      """
    13    Given file ./templates/file.txt containing
    14      """
    15      <%= foo %>
    16      """
    17    When I run "oya render ./templates/file.txt"
    18    Then the command succeeds
    19    And file ./file.txt contains
    20    """
    21    xxx
    22    """
    23  
    24  Scenario: Render a template explicitly pointing to the Oyafile
    25    Given file ./Oyafile containing
    26      """
    27      Project: project
    28      Values:
    29        foo: xxx
    30      """
    31    Given file ./templates/file.txt containing
    32      """
    33      <%= foo %>
    34      """
    35    When I run "oya render -f ./Oyafile ./templates/file.txt"
    36    Then the command succeeds
    37    And file ./file.txt contains
    38    """
    39    xxx
    40    """
    41  
    42  Scenario: Render a template directory
    43    Given file ./Oyafile containing
    44      """
    45      Project: project
    46      Values:
    47        foo: xxx
    48        bar: yyy
    49      """
    50    Given file ./templates/file.txt containing
    51      """
    52      <%= foo %>
    53      """
    54    Given file ./templates/subdir/file.txt containing
    55      """
    56      <%= bar %>
    57      """
    58    When I run "oya render ./templates/"
    59    Then the command succeeds
    60    And file ./file.txt contains
    61    """
    62    xxx
    63    """
    64    And file ./subdir/file.txt contains
    65    """
    66    yyy
    67    """
    68  
    69  Scenario: Rendering values in specified scope pointing to imported pack
    70    Given file ./Oyafile containing
    71      """
    72      Project: project
    73  
    74      Require:
    75        github.com/test/foo: v0.0.1
    76  
    77      Import:
    78        foo: github.com/test/foo
    79      """
    80    And file ./.oya/packs/github.com/test/foo@v0.0.1/Oyafile containing
    81      """
    82      Values:
    83        fruit: orange
    84      """
    85    And file ./templates/file.txt containing
    86      """
    87      <%= fruit %>
    88      """
    89    When I run "oya render --scope foo ./templates/file.txt"
    90    Then the command succeeds
    91    And file ./file.txt contains
    92    """
    93    orange
    94    """
    95  
    96  Scenario: Rendered values in specified scope can be overridden
    97    Given file ./Oyafile containing
    98      """
    99      Project: project
   100  
   101      Require:
   102        github.com/test/foo: v0.0.1
   103  
   104      Import:
   105        foo: github.com/test/foo
   106  
   107      Values:
   108        foo:
   109          fruit: banana
   110      """
   111    And file ./.oya/packs/github.com/test/foo@v0.0.1/Oyafile containing
   112      """
   113      Values:
   114        fruit: orange
   115      """
   116    And file ./templates/file.txt containing
   117      """
   118      <%= fruit %>
   119      """
   120    When I run "oya render --scope foo ./templates/file.txt"
   121    Then the command succeeds
   122    And file ./file.txt contains
   123    """
   124    banana
   125    """
   126  
   127  
   128  Scenario: Imported tasks render using their own Oyafile scope by default
   129    Given file ./Oyafile containing
   130      """
   131      Project: project
   132  
   133      Require:
   134        github.com/test/foo: v0.0.1
   135  
   136      Import:
   137        foo: github.com/test/foo
   138      """
   139    And file ./.oya/packs/github.com/test/foo@v0.0.1/Oyafile containing
   140      """
   141      Values:
   142        fruit: orange
   143  
   144      render: |
   145        oya render ./templates/file.txt
   146      """
   147    And file ./templates/file.txt containing
   148      """
   149      <%= fruit %>
   150      """
   151    When I run "oya run foo.render"
   152    Then the command succeeds
   153    And file ./file.txt contains
   154    """
   155    orange
   156    """
   157  
   158  Scenario: Values in imported pack scope can be overridden
   159    Given file ./Oyafile containing
   160      """
   161      Project: project
   162  
   163      Require:
   164        github.com/test/foo: v0.0.1
   165  
   166      Import:
   167        foo: github.com/test/foo
   168  
   169      Values:
   170        foo:
   171          fruit: banana
   172      """
   173    And file ./.oya/packs/github.com/test/foo@v0.0.1/Oyafile containing
   174      """
   175      Values:
   176        fruit: orange
   177  
   178      render:
   179        oya render ./templates/file.txt
   180      """
   181    And file ./templates/file.txt containing
   182      """
   183      <%= fruit %>
   184      """
   185    When I run "oya run foo.render"
   186    Then the command succeeds
   187    And file ./file.txt contains
   188    """
   189    banana
   190    """
   191  
   192  Scenario: Rendering values in specified scope
   193    Given file ./Oyafile containing
   194      """
   195      Project: project
   196  
   197      Values:
   198        fruits:
   199          fruit: orange
   200      """
   201    And file ./templates/file.txt containing
   202      """
   203      <%= fruit %>
   204      """
   205    When I run "oya render --scope fruits ./templates/file.txt"
   206    Then the command succeeds
   207    And file ./file.txt contains
   208    """
   209    orange
   210    """
   211  
   212  Scenario: Rendering values in specified nested scope
   213    Given file ./Oyafile containing
   214      """
   215      Project: project
   216  
   217      Values:
   218        plants:
   219          fruits:
   220            fruit: orange
   221      """
   222    And file ./templates/file.txt containing
   223      """
   224      <%= fruit %>
   225      """
   226    When I run "oya render --scope plants.fruits ./templates/file.txt"
   227    Then the command succeeds
   228    And file ./file.txt contains
   229    """
   230    orange
   231    """
   232  
   233  Scenario: Rendering one file to an output dir
   234    Given file ./Oyafile containing
   235      """
   236      Project: project
   237  
   238      Values:
   239        fruit: orange
   240      """
   241    And file ./templates/file.txt containing
   242      """
   243      <%= fruit %>
   244      """
   245    When I run "oya render --output-dir ./foobar ./templates/file.txt"
   246    Then the command succeeds
   247    And file ./foobar/file.txt contains
   248    """
   249    orange
   250    """
   251  
   252  Scenario: Rendering a dir to an output dir
   253    Given file ./Oyafile containing
   254      """
   255      Project: project
   256  
   257      Values:
   258        culprit: Eve
   259        weapon: apple
   260      """
   261    And file ./templates/file1.txt containing
   262      """
   263      <%= weapon %>
   264      """
   265    And file ./templates/file2.txt containing
   266      """
   267      <%= culprit %>
   268      """
   269    When I run "oya render --output-dir ./foobar ./templates/"
   270    Then the command succeeds
   271    And file ./foobar/file1.txt contains
   272    """
   273    apple
   274    """
   275    And file ./foobar/file2.txt contains
   276    """
   277    Eve
   278    """
   279  
   280  Scenario: Render dir excluding files and directories
   281    Given file ./Oyafile containing
   282      """
   283      Project: project
   284      Values:
   285        foo: xxx
   286        bar: yyy
   287      """
   288    Given file ./templates/file.txt containing
   289      """
   290      <%= foo %>
   291      """
   292    And file ./templates/excludeme.txt containing
   293      """
   294      <%= badvariable %>
   295      """
   296    And file ./templates/subdir/excludeme.txt containing
   297      """
   298      <%= badvariable %>
   299      """
   300    And file ./templates/subdir/file.txt containing
   301      """
   302      <%= bar %>
   303      """
   304    And file ./templates/excludeme/excludeme.txt containing
   305      """
   306      <%= badvariable %>
   307      """
   308    When I run "oya render --exclude excludeme.txt --exclude subdir/excludeme.txt --exclude excludeme/* ./templates/"
   309    Then the command succeeds
   310    And file ./file.txt contains
   311    """
   312    xxx
   313    """
   314    And file ./subdir/file.txt contains
   315    """
   316    yyy
   317    """
   318    And file ./excludeme.txt does not exist
   319    And file ./subdir/excludeme.txt does not exist
   320    And file ./excludeme/excludeme.txt does not exist
   321  
   322  Scenario: Render dir excluding using globbing
   323    Given file ./Oyafile containing
   324      """
   325      Project: project
   326      Values:
   327        foo: xxx
   328        bar: yyy
   329      """
   330    Given file ./templates/file.txt containing
   331      """
   332      <%= foo %>
   333      """
   334    And file ./templates/excludeme.txt containing
   335      """
   336      <%= badvariable %>
   337      """
   338    And file ./templates/subdir/excludeme.txt containing
   339      """
   340      <%= badvariable %>
   341      """
   342    And file ./templates/subdir/file.txt containing
   343      """
   344      <%= bar %>
   345      """
   346    And file ./templates/excludeme/excludeme.txt containing
   347      """
   348      <%= badvariable %>
   349      """
   350    When I run "oya render --exclude **excludeme.txt ./templates/"
   351    Then the command succeeds
   352    And file ./file.txt contains
   353    """
   354    xxx
   355    """
   356    And file ./subdir/file.txt contains
   357    """
   358    yyy
   359    """
   360    And file ./excludeme.txt does not exist
   361    And file ./subdir/excludeme.txt does not exist
   362    And file ./excludeme/excludeme.txt does not exist
   363  
   364  Scenario: Rendering a dir to an output dir outside project dir
   365    Given file ./Oyafile containing
   366      """
   367      Project: project
   368  
   369      Values:
   370        culprit: Eve
   371        weapon: apple
   372      """
   373    And file ./templates/file1.txt containing
   374      """
   375      <%= weapon %>
   376      """
   377    And file ./templates/file2.txt containing
   378      """
   379      <%= culprit %>
   380      """
   381    When I run "oya render --output-dir /tmp/foobar ./templates/"
   382    Then the command succeeds
   383    And file /tmp/foobar/file1.txt contains
   384    """
   385    apple
   386    """
   387    And file /tmp/foobar/file2.txt contains
   388    """
   389    Eve
   390    """
   391  
   392  Scenario: Override a value
   393    Given file ./Oyafile containing
   394      """
   395      Project: project
   396      Values:
   397        foo: xxx
   398      """
   399    Given file ./templates/file.txt containing
   400      """
   401      <%= foo %>
   402      """
   403    When I run "oya render --set foo=yyy ./templates/file.txt"
   404    Then the command succeeds
   405    And file ./file.txt contains
   406    """
   407    yyy
   408    """
   409  
   410  Scenario: Override a nested value
   411    Given file ./Oyafile containing
   412      """
   413      Project: project
   414      Values:
   415        bar:
   416          foo:
   417            baz: xxx
   418      """
   419    Given file ./templates/file.txt containing
   420      """
   421      <%= bar["foo"]["baz"] %>
   422      """
   423    When I run "oya render --set bar.foo.baz=yyy ./templates/file.txt"
   424    Then the command succeeds
   425    And file ./file.txt contains
   426    """
   427    yyy
   428    """
   429  
   430  Scenario: Set several value
   431    Given file ./Oyafile containing
   432      """
   433      Project: project
   434      Values:
   435        fooo: aa
   436      """
   437    Given file ./templates/file.txt containing
   438      """
   439      <%= fooo["bar"]["baz"] %>
   440      <%= abc["cde"] %>
   441      """
   442    When I run "oya render --set fooo.bar.baz=yyy --set abc.cde=zzz ./templates/file.txt"
   443    Then the command succeeds
   444    And file ./file.txt contains
   445    """
   446    yyy
   447    zzz
   448    """
   449  
   450  Scenario: Renders html characters unescaped
   451    Given file ./Oyafile containing
   452      """
   453      Project: project
   454      Values:
   455        special_char: "&&"
   456      """
   457    Given file ./templates/file.txt containing
   458      """
   459      <%= "&" %>
   460      <%= special_char %>
   461      <%= "!@#$%^&*()<>/" %>
   462      """
   463    When I run "oya render ./templates/file.txt"
   464    Then the command succeeds
   465    And file ./file.txt contains
   466    """
   467    &
   468    &&
   469    !@#$%^&*()<>/
   470    """
   471  
   472  Scenario: Renders with custom template delimiters
   473    Given file ./Oyafile containing
   474      """
   475      Project: project
   476      Values:
   477        fuu: "bar"
   478        bazz: "demo"
   479      """
   480    Given file ./templates/file.txt containing
   481      """
   482      {%= fuu %}
   483      {%= fuu %}
   484      {%= bazz %}
   485      """
   486    When I run "oya render ./templates/file.txt --delimiters {%...%}"
   487    Then the command succeeds
   488    And file ./file.txt contains
   489    """
   490    bar
   491    bar
   492    demo
   493    """