github.com/projectriff/riff-cli@v0.0.5-0.20180301104501-5db7a3bd9fc1/pkg/initializers/node/dockerfile_generator_test.go (about)

     1  /*
     2   * Copyright 2018 the original author or authors.
     3   *
     4   *   Licensed under the Apache License, Version 2.0 (the "License");
     5   *   you may not use this file except in compliance with the License.
     6   *   You may obtain a copy of the License at
     7   *
     8   *        http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   *   Unless required by applicable law or agreed to in writing, software
    11   *   distributed under the License is distributed on an "AS IS" BASIS,
    12   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   *   See the License for the specific language governing permissions and
    14   *   limitations under the License.
    15   */
    16  
    17  package node
    18  
    19  import (
    20  	"fmt"
    21  	"testing"
    22  
    23  	"github.com/projectriff/riff-cli/pkg/options"
    24  	"github.com/stretchr/testify/assert"
    25  )
    26  
    27  func TestNodeDockerfile(t *testing.T) {
    28  	as := assert.New(t)
    29  
    30  	opts := options.InitOptions{
    31  		Artifact:    "square.js",
    32  		RiffVersion: "0.0.3",
    33  		FilePath:    "../../../test_data/node/square/square.js",
    34  		Handler:     "process",
    35  	}
    36  
    37  	docker, err := generateNodeFunctionDockerFile(opts)
    38  	as.NoError(err)
    39  	as.Contains(docker, fmt.Sprintf("FROM projectriff/node-function-invoker:%s\n", opts.RiffVersion))
    40  	as.Contains(docker, fmt.Sprintf("ENV FUNCTION_URI /functions/%s\n", opts.Artifact))
    41  	as.Contains(docker, fmt.Sprintf("ADD %s ${FUNCTION_URI}\n", opts.Artifact))
    42  
    43  	as.NotContains(docker, "ENV FUNCTION_URI /functions/\n")
    44  	as.NotContains(docker, "COPY . ${FUNCTION_URI}\n")
    45  	as.NotContains(docker, "RUN (cd ${FUNCTION_URI} && npm install --production)\n")
    46  }
    47  
    48  func TestNodePackageDockerfile(t *testing.T) {
    49  	as := assert.New(t)
    50  
    51  	opts := options.InitOptions{
    52  		Artifact:    "square.js",
    53  		RiffVersion: "0.0.3",
    54  		FilePath:    "../../../test_data/node/square-package/square.js",
    55  		Handler:     "process",
    56  	}
    57  
    58  	docker, err := generateNodeFunctionDockerFile(opts)
    59  	as.NoError(err)
    60  	as.Contains(docker, fmt.Sprintf("FROM projectriff/node-function-invoker:%s\n", opts.RiffVersion))
    61  	as.Contains(docker, "ENV FUNCTION_URI /functions/\n")
    62  	as.Contains(docker, "COPY . ${FUNCTION_URI}\n")
    63  	as.Contains(docker, "RUN (cd ${FUNCTION_URI} && npm install --production)\n")
    64  
    65  	as.NotContains(docker, fmt.Sprintf("ENV FUNCTION_URI /functions/%s\n", opts.Artifact))
    66  	as.NotContains(docker, fmt.Sprintf("ADD %s ${FUNCTION_URI}\n", opts.Artifact))
    67  }