This repository has been archived by the owner on Oct 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement multi endpoint sidecar approach
Signed-off-by: Victor Morales <[email protected]>
- Loading branch information
1 parent
22ce765
commit e20cc81
Showing
10 changed files
with
348 additions
and
53 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
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,44 @@ | ||
// Copyright 2020 Samsung Electronics | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// 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 main | ||
|
||
import "encoding/json" | ||
|
||
// Endpoint contains the information to create NSM objects | ||
type Endpoint struct { | ||
Name string `json:"name"` | ||
TracerEnabled bool `json:"tracerEnabled"` | ||
NetworkServices []NetworkService `json:"networkServices"` | ||
} | ||
|
||
// NetworkService contains the information to create NSM objects | ||
type NetworkService struct { | ||
Link string `json:"link"` | ||
Labels string `json:"labels"` | ||
IPAddress string `json:"ipAddress"` | ||
Route string `json:"route"` | ||
} | ||
|
||
// GetEndpoint parses a stream of bytes to a Endpoint struct | ||
func GetEndpoint(endpointsFile []byte) (Endpoint, error) { | ||
var endpointsConfig Endpoint | ||
|
||
if err := json.Unmarshal(endpointsFile, &endpointsConfig); err != nil { | ||
return endpointsConfig, err | ||
} | ||
|
||
return endpointsConfig, nil | ||
} |
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,87 @@ | ||
// Copyright 2020 Samsung Electronics | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// 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 main | ||
|
||
import ( | ||
"reflect" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestRead(t *testing.T) { | ||
testCases := []struct { | ||
label string | ||
input []byte | ||
expectedError string | ||
expected Endpoint | ||
}{ | ||
{ | ||
label: "Empty annotation file", | ||
input: []byte(``), | ||
expectedError: "unexpected end of JSON input", | ||
}, | ||
{ | ||
label: "Invalid annotation format", | ||
input: []byte(`{}`), | ||
}, | ||
{ | ||
label: "Read annotations file successfuly", | ||
input: []byte(`{ | ||
"name": "lte-network", | ||
"networkServices": [ | ||
{"link": "s5u", "labels": "app=pgw-s5u", "ipAddress": "172.25.0.0/24"}, | ||
{"link": "sgi", "labels": "app=http-server-sgi", "ipAddress": "10.0.1.0/24", "route": "10.0.3.0/24"} | ||
] | ||
}`), | ||
expected: Endpoint{ | ||
Name: "lte-network", | ||
NetworkServices: []NetworkService{ | ||
NetworkService{ | ||
Link: "s5u", | ||
Labels: "app=pgw-s5u", | ||
IPAddress: "172.25.0.0/24", | ||
}, | ||
NetworkService{ | ||
Link: "sgi", | ||
Labels: "app=http-server-sgi", | ||
IPAddress: "10.0.1.0/24", | ||
Route: "10.0.3.0/24", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
t.Run(testCase.label, func(t *testing.T) { | ||
got, err := GetEndpoint(testCase.input) | ||
if err != nil { | ||
if testCase.expectedError == "" { | ||
t.Fatalf("GetEndpoints returned an unexpected error %s", err) | ||
} | ||
if !strings.Contains(err.Error(), testCase.expectedError) { | ||
t.Fatalf("GetEndpoints returned an unexpected error %s", err) | ||
} | ||
} else { | ||
if !reflect.DeepEqual(testCase.expected, got) { | ||
t.Errorf("GetEndpoints returned unexpected result: got %v;"+ | ||
" expected %v", got, testCase.expected) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
} |
Oops, something went wrong.