donNewtonAlpha | b9b85eb | 2018-08-14 14:28:22 -0400 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2017 the original author or authors. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package api_test |
| 18 | |
| 19 | import ( |
| 20 | "fmt" |
| 21 | "testing" |
| 22 | |
| 23 | "gerrit.opencord.org/abstract-olt/api" |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame^] | 24 | "gerrit.opencord.org/abstract-olt/models/abstract" |
donNewtonAlpha | b9b85eb | 2018-08-14 14:28:22 -0400 | [diff] [blame] | 25 | "golang.org/x/net/context" |
| 26 | ) |
| 27 | |
| 28 | var clli string |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame^] | 29 | var slotHostname = "SlotOne" |
donNewtonAlpha | b9b85eb | 2018-08-14 14:28:22 -0400 | [diff] [blame] | 30 | var ctx context.Context |
| 31 | var server api.Server |
| 32 | |
| 33 | func TestHandler_CreateChassis(t *testing.T) { |
| 34 | fmt.Println("in handlerTest_CreateChassis") |
| 35 | ctx = context.Background() |
| 36 | server = api.Server{} |
| 37 | message := &api.AddChassisMessage{CLLI: "my cilli", VCoreIP: "192.168.0.1", VCorePort: 9191} |
| 38 | ret, err := server.CreateChassis(ctx, message) |
| 39 | if err != nil { |
| 40 | t.Fatalf("CreateChassis failed %v\n", err) |
| 41 | } |
| 42 | clli = ret.DeviceID |
| 43 | |
| 44 | } |
| 45 | func TestHandler_CreateOLTChassis(t *testing.T) { |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame^] | 46 | fmt.Println("in handlerTest_CreateChassis") |
donNewtonAlpha | b9b85eb | 2018-08-14 14:28:22 -0400 | [diff] [blame] | 47 | message := &api.AddOLTChassisMessage{CLLI: clli, SlotIP: "12.2.2.0", SlotPort: 9191, |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame^] | 48 | Hostname: slotHostname, Type: api.AddOLTChassisMessage_edgecore} |
donNewtonAlpha | b9b85eb | 2018-08-14 14:28:22 -0400 | [diff] [blame] | 49 | ret, err := server.CreateOLTChassis(ctx, message) |
| 50 | if err != nil { |
| 51 | t.Fatalf("CreateOLTChassis failed %v\n", err) |
| 52 | } |
| 53 | fmt.Printf("CreateOLTChassis success %v\n", ret) |
| 54 | |
| 55 | } |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame^] | 56 | func TestHandler_ProvisionOnt(t *testing.T) { |
| 57 | ctx = context.Background() |
| 58 | server = api.Server{} |
| 59 | fmt.Println("in handlerTest_CreateChassis") |
| 60 | // this one should succeed |
| 61 | message := &api.AddOntMessage{CLLI: clli, SlotNumber: 1, PortNumber: 3, OntNumber: 2, SerialNumber: "2033029402"} |
| 62 | ret, err := server.ProvisionOnt(ctx, message) |
| 63 | if err != nil { |
| 64 | t.Fatalf("ProvisionOnt failed %v\n", err) |
| 65 | } |
| 66 | // this one should fail |
| 67 | fmt.Println("here") |
| 68 | message = &api.AddOntMessage{CLLI: clli, SlotNumber: 2, PortNumber: 3, OntNumber: 2, SerialNumber: "2033029402"} |
| 69 | ret, err = server.ProvisionOnt(ctx, message) |
| 70 | if err != nil { |
| 71 | switch err.(type) { |
| 72 | case *abstract.UnprovisonedPortError: |
| 73 | fmt.Printf("ProvisionOnt failed as it should with %v\n", err) |
| 74 | default: |
| 75 | t.Fatalf("ProvsionOnt test failed with %v\n", err) |
| 76 | } |
| 77 | } else { |
| 78 | t.Fatalf("ProvsionOnt should have failed but didn't") |
| 79 | } |
| 80 | fmt.Printf("ProvisionOnt success %v\n", ret) |
| 81 | |
| 82 | } |