Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
network: Introduce constants for the network model strings
Browse files Browse the repository at this point in the history
Introduce constants for the network model strings, so as to
avoid using the strings directly at multiple places.

Signed-off-by: Archana Shinde <[email protected]>
  • Loading branch information
amshinde committed Oct 22, 2018
1 parent 71e7fa6 commit 8152832
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
22 changes: 17 additions & 5 deletions virtcontainers/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,34 @@ func (n NetInterworkingModel) IsValid() bool {
return 0 <= int(n) && int(n) < int(NetXConnectInvalidModel)
}

const (
defaultNetModelStr = "default"

bridgedNetModelStr = "bridged"

macvtapNetModelStr = "macvtap"

enlightenedNetModelStr = "enlightened"

tcFilterNetModelStr = "tcfilter"
)

//SetModel change the model string value
func (n *NetInterworkingModel) SetModel(modelName string) error {
switch modelName {
case "default":
case defaultNetModelStr:
*n = DefaultNetInterworkingModel
return nil
case "bridged":
case bridgedNetModelStr:
*n = NetXConnectBridgedModel
return nil
case "macvtap":
case macvtapNetModelStr:
*n = NetXConnectMacVtapModel
return nil
case "enlightened":
case enlightenedNetModelStr:
*n = NetXConnectEnlightenedModel
return nil
case "tcfilter":
case tcFilterNetModelStr:
*n = NetXConnectTCFilterModel
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions virtcontainers/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ func TestNetInterworkingModelSetModel(t *testing.T) {
wantErr bool
}{
{"Invalid Model", "Invalid", true},
{"default Model", "default", false},
{"bridged Model", "bridged", false},
{"macvtap Model", "macvtap", false},
{"enlightened Model", "enlightened", false},
{"tcfilter Model", "tcfilter", false},
{"default Model", defaultNetModelStr, false},
{"bridged Model", bridgedNetModelStr, false},
{"macvtap Model", macvtapNetModelStr, false},
{"enlightened Model", enlightenedNetModelStr, false},
{"tcfilter Model", tcFilterNetModelStr, false},
}

for _, tt := range tests {
Expand Down

0 comments on commit 8152832

Please sign in to comment.