// 2019 Rackspace, Inc. // // 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 shared import ( "strings" "testing" ) func TestGetCollection(t *testing.T) { var groups = []string{ "IAD2-MG-01", "DFW1-RVI-03", "LON7-CG-99", } for _, group := range groups { k := GetCollection(group) if k == "iad2" { t.Logf("SUCCESS: found collection %s", k) continue } if k == "dfw1" { t.Logf("SUCCESS: found collection %s", k) continue } if k == "lon7" { t.Logf("SUCCESS: found collection %s", k) continue } t.Fatalf("ERROR: unable to find correctly parsed data") } } func TestParseBridgeGroup(t *testing.T) { var groups = []string{ "BD-301A-1-20-501A-9-20", "BD-301A-20-501A-9-20", "BD-301A-1-20-501A-20", } for _, group := range groups { resp := ParseBridgeGroup(group) for k := range resp { if k == "aggr301-1:Vlan20" { t.Logf("SUCCESS: found %s source zone", k) continue } if k == "aggr301:Vlan20" { t.Logf("SUCCESS: found %s source zone", k) continue } t.Fatalf("ERROR: unable to find correctly parsed data") } } } func TestConcatVLANs(t *testing.T) { var ( ints = []int{2334, 2335, 101, 2224, 1997, 1998, 1999, 2000} expected = "101,1997-2000,2224,2334-2335" ) vlanTest := ConcatVLANs(ints) if strings.Join(vlanTest, ",") != expected { t.Fatalf("ERROR: %s did not match expected value of %s", strings.Join(vlanTest, ","), expected) } t.Logf("SUCCESS: found expected value of %s", expected) }