github.com/bilus/oya@v0.0.3-0.20190301162104-da4acbd394c6/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: Render templated paths
    70    Given file ./Oyafile containing
    71      """
    72      Project: project
    73      Values:
    74        foo: xxx
    75        bar: yyy
    76      """
    77    Given file ./templates/${foo}.txt containing
    78      """
    79      $foo
    80      """
    81    Given file ./templates/$bar/${foo}.txt containing
    82      """
    83      $bar
    84      """
    85    When I run "oya render ./templates/"
    86    Then the command succeeds
    87    And file ./xxx.txt contains
    88    """
    89    xxx
    90    """
    91    And file ./yyy/xxx.txt contains
    92    """
    93    yyy
    94    """
    95  
    96  Scenario: Rendering values in specified scope pointing to imported pack
    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    And file ./.oya/packs/github.com/test/foo@v0.0.1/Oyafile containing
   108      """
   109      Values:
   110        fruit: orange
   111      """
   112    And file ./templates/file.txt containing
   113      """
   114      $fruit
   115      """
   116    When I run "oya render --scope foo ./templates/file.txt"
   117    Then the command succeeds
   118    And file ./file.txt contains
   119    """
   120    orange
   121    """
   122  
   123  Scenario: Rendered values in specified scope can be overridden
   124    Given file ./Oyafile containing
   125      """
   126      Project: project
   127  
   128      Require:
   129        github.com/test/foo: v0.0.1
   130  
   131      Import:
   132        foo: github.com/test/foo
   133  
   134      Values:
   135        foo:
   136          fruit: banana
   137      """
   138    And file ./.oya/packs/github.com/test/foo@v0.0.1/Oyafile containing
   139      """
   140      Values:
   141        fruit: orange
   142      """
   143    And file ./templates/file.txt containing
   144      """
   145      $fruit
   146      """
   147    When I run "oya render --scope foo ./templates/file.txt"
   148    Then the command succeeds
   149    And file ./file.txt contains
   150    """
   151    banana
   152    """
   153  
   154  
   155  Scenario: Imported tasks render using their own Oyafile scope by default
   156    Given file ./Oyafile containing
   157      """
   158      Project: project
   159  
   160      Require:
   161        github.com/test/foo: v0.0.1
   162  
   163      Import:
   164        foo: github.com/test/foo
   165      """
   166    And file ./.oya/packs/github.com/test/foo@v0.0.1/Oyafile containing
   167      """
   168      Values:
   169        fruit: orange
   170  
   171      render:
   172        $OyaCmd render ./templates/file.txt
   173      """
   174    And file ./templates/file.txt containing
   175      """
   176      $fruit
   177      """
   178    When I run "oya run foo.render"
   179    Then the command succeeds
   180    And file ./file.txt contains
   181    """
   182    orange
   183    """
   184  
   185  Scenario: Values in imported pack scope can be overridden
   186    Given file ./Oyafile containing
   187      """
   188      Project: project
   189  
   190      Require:
   191        github.com/test/foo: v0.0.1
   192  
   193      Import:
   194        foo: github.com/test/foo
   195  
   196      Values:
   197        foo:
   198          fruit: banana
   199      """
   200    And file ./.oya/packs/github.com/test/foo@v0.0.1/Oyafile containing
   201      """
   202      Values:
   203        fruit: orange
   204  
   205      render:
   206        $OyaCmd render ./templates/file.txt
   207      """
   208    And file ./templates/file.txt containing
   209      """
   210      $fruit
   211      """
   212    When I run "oya run foo.render"
   213    Then the command succeeds
   214    And file ./file.txt contains
   215    """
   216    banana
   217    """
   218  Scenario: Scope of the importing Oyafile can be optionally used
   219    Given file ./Oyafile containing
   220      """
   221      Project: project
   222  
   223      Require:
   224        github.com/test/foo: v0.0.1
   225  
   226      Import:
   227        foo: github.com/test/foo
   228  
   229      Values:
   230        fruit: apple
   231      """
   232    And file ./.oya/packs/github.com/test/foo@v0.0.1/Oyafile containing
   233      """
   234      Values:
   235        fruit: orange
   236  
   237      render:
   238        $OyaCmd render --auto-scope=false ./templates/file.txt
   239      """
   240    And file ./templates/file.txt containing
   241      """
   242      $fruit
   243      """
   244    When I run "oya run foo.render"
   245    Then the command succeeds
   246    And file ./file.txt contains
   247    """
   248    apple
   249    """
   250  
   251  
   252  Scenario: Rendering values in specified scope
   253    Given file ./Oyafile containing
   254      """
   255      Project: project
   256  
   257      Values:
   258        fruits:
   259          fruit: orange
   260      """
   261    And file ./templates/file.txt containing
   262      """
   263      $fruit
   264      """
   265    When I run "oya render --scope fruits ./templates/file.txt"
   266    Then the command succeeds
   267    And file ./file.txt contains
   268    """
   269    orange
   270    """
   271  
   272  Scenario: Rendering values in specified nested scope
   273    Given file ./Oyafile containing
   274      """
   275      Project: project
   276  
   277      Values:
   278        plants:
   279          fruits:
   280            fruit: orange
   281      """
   282    And file ./templates/file.txt containing
   283      """
   284      $fruit
   285      """
   286    When I run "oya render --scope plants.fruits ./templates/file.txt"
   287    Then the command succeeds
   288    And file ./file.txt contains
   289    """
   290    orange
   291    """
   292  
   293  Scenario: Rendering one file to an output dir
   294    Given file ./Oyafile containing
   295      """
   296      Project: project
   297  
   298      Values:
   299        fruit: orange
   300      """
   301    And file ./templates/file.txt containing
   302      """
   303      $fruit
   304      """
   305    When I run "oya render --output-dir ./foobar ./templates/file.txt"
   306    Then the command succeeds
   307    And file ./foobar/file.txt contains
   308    """
   309    orange
   310    """
   311  
   312  Scenario: Rendering a dir to an output dir
   313    Given file ./Oyafile containing
   314      """
   315      Project: project
   316  
   317      Values:
   318        culprit: Eve
   319        weapon: apple
   320      """
   321    And file ./templates/file1.txt containing
   322      """
   323      $weapon
   324      """
   325    And file ./templates/file2.txt containing
   326      """
   327      $culprit
   328      """
   329    When I run "oya render --output-dir ./foobar ./templates/"
   330    Then the command succeeds
   331    And file ./foobar/file1.txt contains
   332    """
   333    apple
   334    """
   335    And file ./foobar/file2.txt contains
   336    """
   337    Eve
   338    """
   339  
   340  Scenario: Render dir excluding files and directories
   341    Given file ./Oyafile containing
   342      """
   343      Project: project
   344      Values:
   345        foo: xxx
   346        bar: yyy
   347      """
   348    Given file ./templates/file.txt containing
   349      """
   350      $foo
   351      """
   352    And file ./templates/excludeme.txt containing
   353      """
   354      $badvariable
   355      """
   356    And file ./templates/subdir/excludeme.txt containing
   357      """
   358      $badvariable
   359      """
   360    And file ./templates/subdir/file.txt containing
   361      """
   362      $bar
   363      """
   364    And file ./templates/excludeme/excludeme.txt containing
   365      """
   366      $badvariable
   367      """
   368    When I run "oya render --exclude excludeme.txt --exclude subdir/excludeme.txt --exclude excludeme/* ./templates/"
   369    Then the command succeeds
   370    And file ./file.txt contains
   371    """
   372    xxx
   373    """
   374    And file ./subdir/file.txt contains
   375    """
   376    yyy
   377    """
   378    And file ./excludeme.txt does not exist
   379    And file ./subdir/excludeme.txt does not exist
   380    And file ./excludeme/excludeme.txt does not exist
   381  
   382  
   383  Scenario: Render dir excluding using globbing
   384    Given file ./Oyafile containing
   385      """
   386      Project: project
   387      Values:
   388        foo: xxx
   389        bar: yyy
   390      """
   391    Given file ./templates/file.txt containing
   392      """
   393      $foo
   394      """
   395    And file ./templates/excludeme.txt containing
   396      """
   397      $badvariable
   398      """
   399    And file ./templates/subdir/excludeme.txt containing
   400      """
   401      $badvariable
   402      """
   403    And file ./templates/subdir/file.txt containing
   404      """
   405      $bar
   406      """
   407    And file ./templates/excludeme/excludeme.txt containing
   408      """
   409      $badvariable
   410      """
   411    When I run "oya render --exclude **excludeme.txt ./templates/"
   412    Then the command succeeds
   413    And file ./file.txt contains
   414    """
   415    xxx
   416    """
   417    And file ./subdir/file.txt contains
   418    """
   419    yyy
   420    """
   421    And file ./excludeme.txt does not exist
   422    And file ./subdir/excludeme.txt does not exist
   423    And file ./excludeme/excludeme.txt does not exist
   424  
   425  
   426  Scenario: Rendering a dir to an output dir outside project dir
   427    Given file ./Oyafile containing
   428      """
   429      Project: project
   430  
   431      Values:
   432        culprit: Eve
   433        weapon: apple
   434      """
   435    And file ./templates/file1.txt containing
   436      """
   437      $weapon
   438      """
   439    And file ./templates/file2.txt containing
   440      """
   441      $culprit
   442      """
   443    When I run "oya render --output-dir /tmp/foobar ./templates/"
   444    Then the command succeeds
   445    And file /tmp/foobar/file1.txt contains
   446    """
   447    apple
   448    """
   449    And file /tmp/foobar/file2.txt contains
   450    """
   451    Eve
   452    """