1 // Copyright (c) 2020 Cisco and/or its affiliates.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at:
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
20 . "github.com/onsi/gomega"
22 "git.fd.io/govpp.git/binapigen/vppapi"
25 func TestGenerator(t *testing.T) {
31 {name: "vpe", file: &vppapi.File{
33 Path: "/usr/share/vpp/api/core/vpe.api.json",
39 for _, test := range tests {
40 t.Run(test.name, func(t *testing.T) {
43 apiFiles := []*vppapi.File{test.file}
45 gen, err := New(Options{
48 Expect(err).ToNot(HaveOccurred(), "unexpected generator error: %v", err)
50 Expect(gen.Files).To(HaveLen(1))
51 Expect(gen.Files[0].PackageName).To(BeEquivalentTo(test.expectPackage))
52 Expect(gen.Files[0].GoImportPath).To(BeEquivalentTo("test/" + test.expectPackage))
57 func TestSanitize(t *testing.T) {
62 {"interface", "interfaces"},
64 for _, test := range tests {
65 t.Run(test.name, func(t *testing.T) {
66 s := sanitizedName(test.name)
67 if s != test.expected {
68 t.Fatalf("expected: %q, got: %q", test.expected, s)