Skip to content

Commit

Permalink
Add mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
jayanthvn committed Aug 17, 2023
1 parent c94d236 commit ded96db
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 12 deletions.
15 changes: 15 additions & 0 deletions pkg/tc/generate_mocks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
package tc

//go:generate go run github.com/golang/mock/mockgen -destination mocks/tc_mocks.go . BpfTc
104 changes: 104 additions & 0 deletions pkg/tc/mocks/tc_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 13 additions & 11 deletions pkg/tc/tc.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,22 @@ const (

var log = logger.Get()

type BpfTcAPIs interface {
type BpfTc interface {
TCIngressAttach(interfaceName string, progFD int, funcName string) error
TCIngressDetach(interfaceName string) error
TCEgressAttach(interfaceName string, progFD int, funcName string) error
TCEgressDetach(interfaceName string) error
CleanupQdiscs(prefix string, ingressCleanup bool, egressCleanup bool) error
CleanupQdiscs(ingressCleanup bool, egressCleanup bool) error
}

type BpfTc struct {
var _ BpfTc = &bpfTc{}

type bpfTc struct {
InterfacePrefix string
}

func New(interfacePrefix string) *BpfTc {
return &BpfTc{
func New(interfacePrefix string) BpfTc {
return &bpfTc{
InterfacePrefix: interfacePrefix,
}

Expand Down Expand Up @@ -73,15 +75,15 @@ func enableQdisc(link netlink.Link) bool {

}

func (m *BpfTc) mismatchedInterfacePrefix(interfaceName string) error {
func (m *bpfTc) mismatchedInterfacePrefix(interfaceName string) error {
if !strings.HasPrefix(interfaceName, m.InterfacePrefix) {
log.Errorf("expected prefix - %s but got %s", m.InterfacePrefix, interfaceName)
return errors.New("Mismatched initialized prefix name and passed interface name")
}
return nil
}

func (m *BpfTc) TCIngressAttach(interfaceName string, progFD int, funcName string) error {
func (m *bpfTc) TCIngressAttach(interfaceName string, progFD int, funcName string) error {

if err := m.mismatchedInterfacePrefix(interfaceName); err != nil {
return err
Expand Down Expand Up @@ -133,7 +135,7 @@ func (m *BpfTc) TCIngressAttach(interfaceName string, progFD int, funcName strin
return nil
}

func (m *BpfTc) TCIngressDetach(interfaceName string) error {
func (m *bpfTc) TCIngressDetach(interfaceName string) error {

if err := m.mismatchedInterfacePrefix(interfaceName); err != nil {
return err
Expand Down Expand Up @@ -169,7 +171,7 @@ func (m *BpfTc) TCIngressDetach(interfaceName string) error {
return fmt.Errorf("no active filter to detach-%s", interfaceName)
}

func (m *BpfTc) TCEgressAttach(interfaceName string, progFD int, funcName string) error {
func (m *bpfTc) TCEgressAttach(interfaceName string, progFD int, funcName string) error {

if err := m.mismatchedInterfacePrefix(interfaceName); err != nil {
return err
Expand Down Expand Up @@ -221,7 +223,7 @@ func (m *BpfTc) TCEgressAttach(interfaceName string, progFD int, funcName string
return nil
}

func (m *BpfTc) TCEgressDetach(interfaceName string) error {
func (m *bpfTc) TCEgressDetach(interfaceName string) error {

if err := m.mismatchedInterfacePrefix(interfaceName); err != nil {
return err
Expand Down Expand Up @@ -257,7 +259,7 @@ func (m *BpfTc) TCEgressDetach(interfaceName string) error {
return fmt.Errorf("no active filter to detach-%s", interfaceName)
}

func (m *BpfTc) CleanupQdiscs(ingressCleanup bool, egressCleanup bool) error {
func (m *bpfTc) CleanupQdiscs(ingressCleanup bool, egressCleanup bool) error {

if m.InterfacePrefix == "" {
log.Errorf("invalid empty prefix")
Expand Down
2 changes: 1 addition & 1 deletion pkg/tc/tc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type testMocks struct {
ctrl *gomock.Controller
ebpf_progs *mock_ebpf_progs.MockBpfProgAPIs
ebpf_maps *mock_ebpf_maps.MockBpfMapAPIs
tcClient *BpfTc
tcClient BpfTc
}

func setup(t *testing.T, testPath string, interfacePrefix string) *testMocks {
Expand Down

0 comments on commit ded96db

Please sign in to comment.