github.com/jonsyu1/godel@v0.0.0-20171017211503-64567a0cf169/apps/gunit/cmd/test/test_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 test
    16  
    17  import (
    18  	"io/ioutil"
    19  	"testing"
    20  
    21  	"github.com/nmiyake/pkg/dirs"
    22  	"github.com/nmiyake/pkg/gofiles"
    23  	"github.com/stretchr/testify/assert"
    24  	"github.com/stretchr/testify/require"
    25  )
    26  
    27  func TestCreatePlaceholderUsesBuildConstraints(t *testing.T) {
    28  	testDir, cleanup, err := dirs.TempDir(".", "")
    29  	defer cleanup()
    30  	require.NoError(t, err)
    31  
    32  	specs := []gofiles.GoFileSpec{
    33  		{
    34  			RelPath: "foo/main.go",
    35  			Src: `// +build ignore
    36  
    37  package main`,
    38  		},
    39  		{
    40  			RelPath: "foo/zoo.go",
    41  			Src:     `package zoo`,
    42  		},
    43  	}
    44  	_, err = gofiles.Write(testDir, specs)
    45  	require.NoError(t, err)
    46  
    47  	writtenFiles, err := createPlaceholderTestFiles([]string{"foo"}, testDir)
    48  	require.NoError(t, err)
    49  
    50  	content, err := ioutil.ReadFile(writtenFiles[0])
    51  	require.NoError(t, err)
    52  
    53  	// generated placeholder should be of package "zoo" rather than package "main" because latter is ignored using
    54  	// build constraint.
    55  	want := `package zoo
    56  // temporary placeholder test file created by gunit
    57  `
    58  	assert.Equal(t, want, string(content))
    59  }