-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ocp: consider missing namespace in network name
The namespace may be missing from the network name, in this case we need to use the VM's namespace Also contains: ocp: extract to function and add unit test Signed-off-by: Benny Zlotnik <[email protected]>
- Loading branch information
Showing
3 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package ocp | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/ref" | ||
) | ||
|
||
func TestGetNetworkNameAndNamespace(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
networkName string | ||
vmRef *ref.Ref | ||
expectedName string | ||
expectedNS string | ||
}{ | ||
{ | ||
name: "no slash in network name", | ||
networkName: "network", | ||
vmRef: &ref.Ref{Namespace: "vmNamespace"}, | ||
expectedName: "network", | ||
expectedNS: "vmNamespace", | ||
}, | ||
{ | ||
name: "slash in network name", | ||
networkName: "namespace/network", | ||
vmRef: &ref.Ref{Namespace: "vmNamespace"}, | ||
expectedName: "network", | ||
expectedNS: "namespace", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
actualName, actualNS := getNetworkNameAndNamespace(tt.networkName, &ref.Ref{Namespace: tt.vmRef.Namespace}) | ||
if actualName != tt.expectedName || actualNS != tt.expectedNS { | ||
t.Errorf("got (%s, %s), want (%s, %s)", actualName, actualNS, tt.expectedName, tt.expectedNS) | ||
} | ||
}) | ||
} | ||
} |