code-intelligence.com/cifuzz@v0.40.0/internal/cmdutils/logging/buildlog_test.go (about)

     1  package logging
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  	"strings"
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  	"github.com/stretchr/testify/require"
    12  
    13  	"code-intelligence.com/cifuzz/util/fileutil"
    14  )
    15  
    16  func TestOk(t *testing.T) {
    17  	projectDir, err := os.Getwd()
    18  	require.NoError(t, err)
    19  	testDir := filepath.Join(projectDir, "buildlog_test")
    20  	err = os.MkdirAll(testDir, 0755)
    21  	require.NoError(t, err)
    22  	defer fileutil.Cleanup(testDir)
    23  
    24  	// no fuzz test
    25  	expected := filepath.Join(testDir, ".cifuzz-build", "logs", "build-all.log")
    26  	_, err = BuildOutputToFile(testDir, nil)
    27  	require.NoError(t, err)
    28  	assert.FileExists(t, expected)
    29  
    30  	// one fuzz test
    31  	fuzzTest := "my_fuzz_test"
    32  	expected = filepath.Join(testDir, ".cifuzz-build", "logs", fmt.Sprintf("build-%s.log", fuzzTest))
    33  	_, err = BuildOutputToFile(testDir, []string{fuzzTest})
    34  	require.NoError(t, err)
    35  	assert.FileExists(t, expected)
    36  
    37  	// mutliple fuzz test
    38  	fuzzTests := []string{"my_fuzz_test1", "my_fuzz_test2"}
    39  	expected = filepath.Join(testDir, ".cifuzz-build", "logs", fmt.Sprintf("build-%s.log", strings.Join(fuzzTests, "_")))
    40  	_, err = BuildOutputToFile(testDir, fuzzTests)
    41  	require.NoError(t, err)
    42  	assert.FileExists(t, expected)
    43  }