github.com/please-build/go-rules/tools/please_go@v0.0.0-20240319165128-ea27d6f5caba/test/find_cover_vars_test.go (about)

     1  package test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  // The library here is a (very) reduced version of core that only has one file in it.
    10  var coverageVars = []CoverVar{{
    11  	Dir:        "tools/please_go/test/test_data",
    12  	ImportPath: "tools/please_go/test/test_data/core",
    13  	Var:        "GoCover_lock_go",
    14  	File:       "tools/please_go/test/test_data/lock.go",
    15  }}
    16  
    17  func TestFindCoverVars(t *testing.T) {
    18  	vars, err := FindCoverVars("tools/please_go/test/test_data", "", false, []string{"tools/please_go/test/test_data/x", "tools/please_go/test/test_data/binary"})
    19  	assert.NoError(t, err)
    20  	assert.Equal(t, coverageVars, vars)
    21  }
    22  
    23  func TestFindCoverVarsFailsGracefully(t *testing.T) {
    24  	_, err := FindCoverVars("wibble", "", false, nil)
    25  	assert.Error(t, err)
    26  }
    27  
    28  func TestFindCoverVarsReturnsNothingForEmptyPath(t *testing.T) {
    29  	vars, err := FindCoverVars("", "", false, nil)
    30  	assert.NoError(t, err)
    31  	assert.Equal(t, 0, len(vars))
    32  }
    33  
    34  func TestFindBinaryCoverVars(t *testing.T) {
    35  	// Test for Go 1.7 binary format.
    36  	expected := []CoverVar{{
    37  		Dir:        "tools/please_go/test/test_data/binary",
    38  		ImportPath: "tools/please_go/test/test_data/binary/core",
    39  		Var:        "GoCover_lock_go",
    40  		File:       "tools/please_go/test/test_data/binary/lock.go",
    41  	}}
    42  	vars, err := FindCoverVars("tools/please_go/test/test_data/binary", "", false, nil)
    43  	assert.NoError(t, err)
    44  	assert.Equal(t, expected, vars)
    45  }