github.com/cilium/cilium@v1.16.2/pkg/datapath/loader/compile_test.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package loader
     5  
     6  import (
     7  	"context"
     8  	"fmt"
     9  	"os"
    10  	"testing"
    11  
    12  	"github.com/stretchr/testify/require"
    13  
    14  	"github.com/cilium/cilium/pkg/testutils"
    15  )
    16  
    17  func TestCompile(t *testing.T) {
    18  	testutils.PrivilegedTest(t)
    19  
    20  	debugOutput := func(p *progInfo) *progInfo {
    21  		cpy := *p
    22  		cpy.Output = cpy.Source
    23  		cpy.OutputType = outputSource
    24  		return &cpy
    25  	}
    26  
    27  	dirs := getDirs(t)
    28  	for _, prog := range []*progInfo{
    29  		epProg,
    30  		hostEpProg,
    31  		debugOutput(epProg),
    32  		debugOutput(hostEpProg),
    33  	} {
    34  		name := fmt.Sprintf("%s:%s", prog.OutputType, prog.Output)
    35  		t.Run(name, func(t *testing.T) {
    36  			path, err := compile(context.Background(), prog, dirs)
    37  			require.NoError(t, err)
    38  
    39  			stat, err := os.Stat(path)
    40  			require.NoError(t, err)
    41  			require.False(t, stat.IsDir())
    42  			require.NotZero(t, stat.Size())
    43  		})
    44  	}
    45  }