Skip to content

Commit

Permalink
Merge branch 'newLinkStructsFromRaw' into migratetoolscmdlinkstructs
Browse files Browse the repository at this point in the history
  • Loading branch information
steiler committed Aug 14, 2023
2 parents 82ca87e + 0aaec7f commit 1d03ce0
Show file tree
Hide file tree
Showing 24 changed files with 375 additions and 43 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
if: needs.file-changes.outputs.code == 'true' || startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v3
- uses: WillAbides/setup-go-faster@v1.9.0
- uses: WillAbides/setup-go-faster@v1.10.1
with:
go-version: ${{ env.GOVER }}

Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
if: needs.file-changes.outputs.code == 'true' || startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v3
- uses: WillAbides/setup-go-faster@v1.9.0
- uses: WillAbides/setup-go-faster@v1.10.1
with:
go-version: ${{ env.GOVER }}

Expand All @@ -105,7 +105,7 @@ jobs:
if: needs.file-changes.outputs.code == 'true' || startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v3
- uses: WillAbides/setup-go-faster@v1.9.0
- uses: WillAbides/setup-go-faster@v1.10.1
with:
go-version: ${{ env.GOVER }}

Expand Down Expand Up @@ -150,7 +150,7 @@ jobs:
repository: containers/podman
ref: ${{ env.PODMAN_VER }}

- uses: WillAbides/setup-go-faster@v1.9.0
- uses: WillAbides/setup-go-faster@v1.10.1
if: steps.cache-podman-bin.outputs.cache-hit != 'true'
with:
go-version: ${{ env.GOVER }}
Expand Down Expand Up @@ -464,7 +464,7 @@ jobs:
fetch-depth: 0

- name: Set up Go
uses: WillAbides/setup-go-faster@v1.9.0
uses: WillAbides/setup-go-faster@v1.10.1
with:
go-version: ${{ env.GOVER }}

Expand Down
3 changes: 3 additions & 0 deletions clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ func (c *CLab) VerifyContainersUniqueness(ctx context.Context) error {

dups := []string{}
for _, n := range c.Nodes {
if n.Config().SkipUniquenessCheck {
continue
}
for _, cnt := range containers {
if n.Config().LongName == cnt.Names[0] {
dups = append(dups, n.Config().LongName)
Expand Down
108 changes: 108 additions & 0 deletions clab/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@
package clab

import (
"context"
"fmt"
"os"
"path/filepath"
"reflect"
"testing"

"github.com/containers/podman/v4/pkg/util"
"github.com/golang/mock/gomock"
"github.com/google/go-cmp/cmp"
"github.com/srl-labs/containerlab/labels"
"github.com/srl-labs/containerlab/links"
"github.com/srl-labs/containerlab/mocks/mockruntime"
"github.com/srl-labs/containerlab/runtime"
"github.com/srl-labs/containerlab/runtime/docker"
"github.com/srl-labs/containerlab/utils"
"github.com/stretchr/testify/assert"
)

func setupTestCase(t *testing.T) func(t *testing.T) {
Expand Down Expand Up @@ -478,6 +482,110 @@ func TestLabelsInit(t *testing.T) {
}
}

func TestVerifyContainersUniqueness(t *testing.T) {
tests := map[string]struct {
mockResult struct {
c []runtime.GenericContainer
e error
}
topo string
wantError bool
}{
"no dups": {
mockResult: struct {
c []runtime.GenericContainer
e error
}{
c: []runtime.GenericContainer{
{
Names: []string{"some node"},
Labels: map[string]string{},
},
{
Names: []string{"some other node"},
Labels: map[string]string{},
},
},
e: nil,
},
topo: "test_data/topo1.yml",
wantError: false,
},
"dups": {
mockResult: struct {
c []runtime.GenericContainer
e error
}{
c: []runtime.GenericContainer{
{
Names: []string{"clab-topo1-node1"},
Labels: map[string]string{},
},
{
Names: []string{"somenode"},
Labels: map[string]string{},
},
},
e: nil,
},
wantError: true,
topo: "test_data/topo1.yml",
},
"ext-container": {
mockResult: struct {
c []runtime.GenericContainer
e error
}{
c: []runtime.GenericContainer{
{
Names: []string{"node1"},
Labels: map[string]string{},
},
{
Names: []string{"somenode"},
Labels: map[string]string{},
},
},
e: nil,
},
wantError: false,
topo: "test_data/topo11-ext-cont.yaml",
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
// init Runtime Mock
ctrl := gomock.NewController(t)
rtName := "mock"

opts := []ClabOption{
WithTopoFile(tc.topo, ""),
}
c, err := NewContainerLab(opts...)
if err != nil {
t.Fatal(err)
}

// set mockRuntime parameters
mockRuntime := mockruntime.NewMockContainerRuntime(ctrl)
c.Runtimes[rtName] = mockRuntime
c.globalRuntime = rtName

// prepare runtime result
mockRuntime.EXPECT().ListContainers(gomock.Any(), gomock.Any()).AnyTimes().Return(tc.mockResult.c, tc.mockResult.e)

ctx := context.Background()
err = c.VerifyContainersUniqueness(ctx)
if tc.wantError {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
})
}
}

func TestEnvFileInit(t *testing.T) {
tests := map[string]struct {
got string
Expand Down
12 changes: 12 additions & 0 deletions clab/test_data/topo11-ext-cont.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: topo11
topology:
nodes:
node1:
kind: ext-container
exec:
- ip l
node2:
kind: linux
image: alpine:latest


1 change: 1 addition & 0 deletions docs/htmltest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ IgnoreURLs:
- https://twitter.com/*
- mysocket.io # remove mysocket.io links until we rework to border0.com
- https://supportcenter.checkpoint.com/ # started to fail, meh.
- https://marketplace.visualstudio.com/*
IgnoreDirectoryMissingTrailingSlash: true
IgnoreAltMissing: true
IgnoreSSLVerify: true
Expand Down
Loading

0 comments on commit 1d03ce0

Please sign in to comment.