Skip to content

Commit

Permalink
test: ipam core tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cheina97 authored and adamjensenbot committed Dec 18, 2024
1 parent 904d075 commit 484c9fd
Show file tree
Hide file tree
Showing 11 changed files with 877 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ token
/liqoctl

# test generated files
coverage.txt
coverage*

# example kubeconfig generates by examples
liqo_kubeconf*
Expand Down
3 changes: 2 additions & 1 deletion build/liqo-test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ ENTRYPOINT [ "go", "test" ]

# Remove the -count=1 flag to enable caching of successful tests
# Remove the -failfast flag to run all tests even if some fail
# Remove the -shuffle flag to run tests in the order they are defined
# Add the -v flag to increase verbosity
CMD [ "./cmd/...", "./pkg/...", "./apis/...", "./internal/...", "-count=1", "-failfast" ]
CMD [ "./cmd/...", "./pkg/...", "./apis/...", "./internal/...", "-count=1", "-failfast", "-shuffle=on" ]
27 changes: 27 additions & 0 deletions pkg/ipam/core/core_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2019-2024 The Liqo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License 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 ipamcore_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestCore(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Core Suite")
}
15 changes: 5 additions & 10 deletions pkg/ipam/core/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,14 @@ type Ipam struct {
}

// NewIpam creates a new IPAM instance.
func NewIpam(pools []string) (*Ipam, error) {
ipamRootsPrefixes := make([]netip.Prefix, len(pools))
for i, root := range pools {
ipamRootsPrefixes[i] = netip.MustParsePrefix(root)
}

if err := checkRoots(ipamRootsPrefixes); err != nil {
func NewIpam(pools []netip.Prefix) (*Ipam, error) {
if err := checkRoots(pools); err != nil {
return nil, err
}

ipamRoots := make([]node, len(pools))
for i := range ipamRootsPrefixes {
ipamRoots[i] = newNode(ipamRootsPrefixes[i])
for i := range pools {
ipamRoots[i] = newNode(pools[i])
}

ipam := &Ipam{
Expand Down Expand Up @@ -252,5 +247,5 @@ func (ipam *Ipam) IPSetCreationTimestamp(addr netip.Addr, prefix netip.Prefix, c
return nil
}
}
return nil
return fmt.Errorf("IP address %s not found", addr)
}
Loading

0 comments on commit 484c9fd

Please sign in to comment.