github.com/jonsyu1/godel@v0.0.0-20171017211503-64567a0cf169/layout/wrapper_test.go (about)

     1  // Copyright 2016 Palantir Technologies, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package layout_test
    16  
    17  import (
    18  	"io/ioutil"
    19  	"os"
    20  	"path"
    21  	"testing"
    22  
    23  	"github.com/nmiyake/pkg/dirs"
    24  	"github.com/palantir/pkg/specdir"
    25  	"github.com/stretchr/testify/assert"
    26  	"github.com/stretchr/testify/require"
    27  
    28  	"github.com/palantir/godel/layout"
    29  )
    30  
    31  func TestWrapperLayoutNoValidation(t *testing.T) {
    32  	specDir, err := specdir.New("testRoot", layout.WrapperSpec(), nil, specdir.SpecOnly)
    33  	require.NoError(t, err)
    34  
    35  	for i, currCase := range []struct {
    36  		aliasName string
    37  		want      string
    38  	}{
    39  		{
    40  			aliasName: layout.WrapperConfigDir,
    41  			want:      "testRoot/godel/config",
    42  		},
    43  		{
    44  			aliasName: layout.WrapperAppDir,
    45  			want:      "testRoot/godel",
    46  		},
    47  		{
    48  			aliasName: layout.WrapperScriptFile,
    49  			want:      "testRoot/godelw",
    50  		},
    51  	} {
    52  		assert.Equal(t, currCase.want, specDir.Path(currCase.aliasName), "Case %d", i)
    53  	}
    54  }
    55  
    56  func TestWrapperLayoutValidationFail(t *testing.T) {
    57  	spec := layout.WrapperSpec()
    58  	err := spec.Validate("testRoot", nil)
    59  	assert.EqualError(t, err, "testRoot/godelw does not exist")
    60  }
    61  
    62  func TestWrapperLayoutValidation(t *testing.T) {
    63  	tmpDir, cleanup, err := dirs.TempDir("", "")
    64  	defer cleanup()
    65  	require.NoError(t, err)
    66  
    67  	err = os.MkdirAll(path.Join(tmpDir, "wrapperParent", "godel", "config"), 0755)
    68  	require.NoError(t, err)
    69  
    70  	err = os.MkdirAll(path.Join(tmpDir, "wrapperParent", "godel", ".src"), 0755)
    71  	require.NoError(t, err)
    72  
    73  	err = ioutil.WriteFile(path.Join(tmpDir, "wrapperParent", "godelw"), []byte("test file"), 0644)
    74  	require.NoError(t, err)
    75  
    76  	specDir, err := specdir.New(path.Join(tmpDir, "wrapperParent"), layout.WrapperSpec(), nil, specdir.Validate)
    77  	require.NoError(t, err)
    78  
    79  	for i, currCase := range []struct {
    80  		aliasName string
    81  		want      string
    82  	}{
    83  		{
    84  			aliasName: layout.WrapperAppDir,
    85  			want:      "wrapperParent/godel",
    86  		},
    87  		{
    88  			aliasName: layout.WrapperConfigDir,
    89  			want:      "wrapperParent/godel/config",
    90  		},
    91  		{
    92  			aliasName: layout.WrapperScriptFile,
    93  			want:      "wrapperParent/godelw",
    94  		},
    95  	} {
    96  		assert.Equal(t, path.Join(tmpDir, currCase.want), specDir.Path(currCase.aliasName), "Case %d", i)
    97  	}
    98  }