Skip to content

Commit

Permalink
fix unit tests + int test panic
Browse files Browse the repository at this point in the history
fix a logr panic in int tests

make sure the unit test fake harness honors
object sub-statuses

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
  • Loading branch information
astoycos committed May 31, 2024
1 parent 42d9751 commit eb341c4
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion cmd/bpfman-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var (

func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(bpfmaniov1alpha1.AddToScheme(scheme))
utilruntime.Must(bpfmaniov1alpha1.Install(scheme))

Check warning on line 55 in cmd/bpfman-agent/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/bpfman-agent/main.go#L55

Added line #L55 was not covered by tests
utilruntime.Must(v1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/bpfman-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var (

func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(bpfmaniov1alpha1.AddToScheme(scheme))
utilruntime.Must(bpfmaniov1alpha1.Install(scheme))

Check warning on line 48 in cmd/bpfman-operator/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/bpfman-operator/main.go#L48

Added line #L48 was not covered by tests
//+kubebuilder:scaffold:scheme
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/bpfman-agent/fentry-program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestFentryProgramControllerCreate(t *testing.T) {
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgramList{})

// Create a fake client to mock API calls.
cl := fake.NewClientBuilder().WithRuntimeObjects(objs...).Build()
cl := fake.NewClientBuilder().WithStatusSubresource(Fentry).WithStatusSubresource(&bpfmaniov1alpha1.BpfProgram{}).WithRuntimeObjects(objs...).Build()

cli := agenttestutils.NewBpfmanClientFake()

Expand Down
2 changes: 1 addition & 1 deletion controllers/bpfman-agent/fexit-program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestFexitProgramControllerCreate(t *testing.T) {
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgramList{})

// Create a fake client to mock API calls.
cl := fake.NewClientBuilder().WithRuntimeObjects(objs...).Build()
cl := fake.NewClientBuilder().WithStatusSubresource(Fexit).WithStatusSubresource(&bpfmaniov1alpha1.BpfProgram{}).WithRuntimeObjects(objs...).Build()

cli := agenttestutils.NewBpfmanClientFake()

Expand Down
2 changes: 1 addition & 1 deletion controllers/bpfman-agent/kprobe-program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestKprobeProgramControllerCreate(t *testing.T) {
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgramList{})

// Create a fake client to mock API calls.
cl := fake.NewClientBuilder().WithRuntimeObjects(objs...).Build()
cl := fake.NewClientBuilder().WithStatusSubresource(Kprobe).WithStatusSubresource(&bpfmaniov1alpha1.BpfProgram{}).WithRuntimeObjects(objs...).Build()

cli := agenttestutils.NewBpfmanClientFake()

Expand Down
5 changes: 2 additions & 3 deletions controllers/bpfman-agent/tc-program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestTcProgramControllerCreate(t *testing.T) {
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgramList{})

// Create a fake client to mock API calls.
cl := fake.NewClientBuilder().WithRuntimeObjects(objs...).Build()
cl := fake.NewClientBuilder().WithStatusSubresource(tc).WithStatusSubresource(&bpfmaniov1alpha1.BpfProgram{}).WithRuntimeObjects(objs...).Build()

cli := agenttestutils.NewBpfmanClientFake()

Expand Down Expand Up @@ -256,12 +256,11 @@ func TestTcProgramControllerCreateMultiIntf(t *testing.T) {
// Register operator types with the runtime scheme.
s := scheme.Scheme
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, tc)
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.TcProgramList{})
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgram{})
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgramList{})

// Create a fake client to mock API calls.
cl := fake.NewClientBuilder().WithRuntimeObjects(objs...).Build()
cl := fake.NewClientBuilder().WithStatusSubresource(tc).WithStatusSubresource(&bpfmaniov1alpha1.BpfProgram{}).WithRuntimeObjects(objs...).Build()

cli := agenttestutils.NewBpfmanClientFake()

Expand Down
2 changes: 1 addition & 1 deletion controllers/bpfman-agent/tracepoint-program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestTracepointProgramControllerCreate(t *testing.T) {
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgramList{})

// Create a fake client to mock API calls.
cl := fake.NewClientBuilder().WithRuntimeObjects(objs...).Build()
cl := fake.NewClientBuilder().WithStatusSubresource(Tracepoint).WithStatusSubresource(&bpfmaniov1alpha1.BpfProgram{}).WithRuntimeObjects(objs...).Build()

cli := agenttestutils.NewBpfmanClientFake()

Expand Down
2 changes: 1 addition & 1 deletion controllers/bpfman-agent/uprobe-program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestUprobeProgramControllerCreate(t *testing.T) {
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgramList{})

// Create a fake client to mock API calls.
cl := fake.NewClientBuilder().WithRuntimeObjects(objs...).Build()
cl := fake.NewClientBuilder().WithStatusSubresource(Uprobe).WithStatusSubresource(&bpfmaniov1alpha1.BpfProgram{}).WithRuntimeObjects(objs...).Build()

cli := agenttestutils.NewBpfmanClientFake()

Expand Down
2 changes: 1 addition & 1 deletion controllers/bpfman-agent/xdp-program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func xdpProgramControllerCreate(t *testing.T, multiInterface bool, multiConditio
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgramList{})

// Create a fake client to mock API calls.
cl := fake.NewClientBuilder().WithRuntimeObjects(objs...).Build()
cl := fake.NewClientBuilder().WithStatusSubresource(xdp).WithStatusSubresource(&bpfmaniov1alpha1.BpfProgram{}).WithRuntimeObjects(objs...).Build()

cli := agenttestutils.NewBpfmanClientFake()

Expand Down
3 changes: 1 addition & 2 deletions controllers/bpfman-operator/fentry-program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,11 @@ func fentryProgramReconcile(t *testing.T, multiCondition bool) {
// Register operator types with the runtime scheme.
s := scheme.Scheme
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, Fentry)
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.TcProgramList{})
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgram{})
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgramList{})

// Create a fake client to mock API calls.
cl := fake.NewClientBuilder().WithRuntimeObjects(objs...).Build()
cl := fake.NewClientBuilder().WithStatusSubresource(Fentry).WithRuntimeObjects(objs...).Build()

rc := ReconcilerCommon{
Client: cl,
Expand Down
3 changes: 1 addition & 2 deletions controllers/bpfman-operator/fexit-program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,11 @@ func fexitProgramReconcile(t *testing.T, multiCondition bool) {
// Register operator types with the runtime scheme.
s := scheme.Scheme
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, Fexit)
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.TcProgramList{})
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgram{})
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgramList{})

// Create a fake client to mock API calls.
cl := fake.NewClientBuilder().WithRuntimeObjects(objs...).Build()
cl := fake.NewClientBuilder().WithStatusSubresource(Fexit).WithRuntimeObjects(objs...).Build()

rc := ReconcilerCommon{
Client: cl,
Expand Down
3 changes: 1 addition & 2 deletions controllers/bpfman-operator/kprobe-program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,11 @@ func kprobeProgramReconcile(t *testing.T, multiCondition bool) {
// Register operator types with the runtime scheme.
s := scheme.Scheme
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, Kprobe)
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.TcProgramList{})
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgram{})
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgramList{})

// Create a fake client to mock API calls.
cl := fake.NewClientBuilder().WithRuntimeObjects(objs...).Build()
cl := fake.NewClientBuilder().WithStatusSubresource(Kprobe).WithRuntimeObjects(objs...).Build()

rc := ReconcilerCommon{
Client: cl,
Expand Down
3 changes: 1 addition & 2 deletions controllers/bpfman-operator/tc-program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,11 @@ func TestTcProgramReconcile(t *testing.T) {
// Register operator types with the runtime scheme.
s := scheme.Scheme
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, tc)
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.TcProgramList{})
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgram{})
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgramList{})

// Create a fake client to mock API calls.
cl := fake.NewClientBuilder().WithRuntimeObjects(objs...).Build()
cl := fake.NewClientBuilder().WithStatusSubresource(tc).WithRuntimeObjects(objs...).Build()

rc := ReconcilerCommon{
Client: cl,
Expand Down
3 changes: 1 addition & 2 deletions controllers/bpfman-operator/tracepoint-program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,11 @@ func TestTracepointProgramReconcile(t *testing.T) {
// Register operator types with the runtime scheme.
s := scheme.Scheme
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, Tracepoint)
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.TcProgramList{})
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgram{})
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgramList{})

// Create a fake client to mock API calls.
cl := fake.NewClientBuilder().WithRuntimeObjects(objs...).Build()
cl := fake.NewClientBuilder().WithStatusSubresource(Tracepoint).WithRuntimeObjects(objs...).Build()

rc := ReconcilerCommon{
Client: cl,
Expand Down
3 changes: 1 addition & 2 deletions controllers/bpfman-operator/uprobe-program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,11 @@ func TestUprobeProgramReconcile(t *testing.T) {
// Register operator types with the runtime scheme.
s := scheme.Scheme
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, Uprobe)
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.TcProgramList{})
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgram{})
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgramList{})

// Create a fake client to mock API calls.
cl := fake.NewClientBuilder().WithRuntimeObjects(objs...).Build()
cl := fake.NewClientBuilder().WithStatusSubresource(Uprobe).WithRuntimeObjects(objs...).Build()

rc := ReconcilerCommon{
Client: cl,
Expand Down
3 changes: 1 addition & 2 deletions controllers/bpfman-operator/xdp-program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,11 @@ func TestXdpProgramReconcile(t *testing.T) {
// Register operator types with the runtime scheme.
s := scheme.Scheme
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, Xdp)
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.TcProgramList{})
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgram{})
s.AddKnownTypes(bpfmaniov1alpha1.SchemeGroupVersion, &bpfmaniov1alpha1.BpfProgramList{})

// Create a fake client to mock API calls.
cl := fake.NewClientBuilder().WithRuntimeObjects(objs...).Build()
cl := fake.NewClientBuilder().WithStatusSubresource(Xdp).WithRuntimeObjects(objs...).Build()

rc := ReconcilerCommon{
Client: cl,
Expand Down
8 changes: 6 additions & 2 deletions test/integration/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ import (
"github.com/kong/kubernetes-testing-framework/pkg/environments"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"github.com/bpfman/bpfman-operator/internal"
"github.com/bpfman/bpfman-operator/pkg/client/clientset/versioned"
"github.com/bpfman/bpfman-operator/pkg/client/clientset"
bpfmanHelpers "github.com/bpfman/bpfman-operator/pkg/helpers"
)

var (
ctx context.Context
cancel context.CancelFunc
env environments.Environment
bpfmanClient *versioned.Clientset
bpfmanClient *clientset.Clientset

// These images should already be built on the node so they can
// be loaded into kind.
Expand All @@ -46,6 +48,8 @@ const (
)

func TestMain(m *testing.M) {
logf.SetLogger(zap.New())

// check that we have the bpfman-agent, and bpfman-operator images to use for the tests.
// generally the runner of the tests should have built these from the latest
// changes prior to the tests and fed them to the test suite.
Expand Down

0 comments on commit eb341c4

Please sign in to comment.