diff options
author | Ondrej Fabry <ofabry@cisco.com> | 2018-08-22 06:07:04 +0200 |
---|---|---|
committer | Ondrej Fabry <ofabry@cisco.com> | 2018-08-22 06:07:04 +0200 |
commit | 892683bef86cacc2ccda2b4df2b079171bd92164 (patch) | |
tree | bb27f2abca3b1998ac808874d4759ff81b9c83dc /cmd/binapi-generator | |
parent | 08ddeac03fd3832d44a3dfb48ee85ecd95d2b388 (diff) |
Show VPPApiError value always and remove RegisterBinAPITypes for mock adapter
Change-Id: I3b216748df1a372f25cc94e3df5d7b1b2b7a8a40
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'cmd/binapi-generator')
-rw-r--r-- | cmd/binapi-generator/generate.go | 2 | ||||
-rw-r--r-- | cmd/binapi-generator/generate_test.go | 53 |
2 files changed, 27 insertions, 28 deletions
diff --git a/cmd/binapi-generator/generate.go b/cmd/binapi-generator/generate.go index e29c84d..33ab614 100644 --- a/cmd/binapi-generator/generate.go +++ b/cmd/binapi-generator/generate.go @@ -181,6 +181,7 @@ func generateHeader(ctx *context, w io.Writer) { fmt.Fprintf(w, "\t%s\n", filepath.Base(ctx.inputFile)) fmt.Fprintln(w) fmt.Fprintln(w, "It contains these VPP binary API objects:") + var printObjNum = func(obj string, num int) { if num > 0 { if num > 1 { @@ -194,6 +195,7 @@ func generateHeader(ctx *context, w io.Writer) { printObjNum("enum", len(ctx.packageData.Enums)) printObjNum("union", len(ctx.packageData.Unions)) printObjNum("service", len(ctx.packageData.Services)) + fmt.Fprintln(w, "*/") fmt.Fprintf(w, "package %s\n", ctx.packageName) fmt.Fprintln(w) diff --git a/cmd/binapi-generator/generate_test.go b/cmd/binapi-generator/generate_test.go index c1181f0..4b06733 100644 --- a/cmd/binapi-generator/generate_test.go +++ b/cmd/binapi-generator/generate_test.go @@ -15,6 +15,8 @@ package main import ( + "bufio" + "bytes" "os" "testing" @@ -25,7 +27,7 @@ func TestGetInputFiles(t *testing.T) { RegisterTestingT(t) result, err := getInputFiles("testdata") Expect(err).ShouldNot(HaveOccurred()) - Expect(result).To(HaveLen(5)) + Expect(result).To(HaveLen(3)) for _, file := range result { Expect(file).To(BeAnExistingFile()) } @@ -45,10 +47,10 @@ func TestGenerateFromFile(t *testing.T) { defer os.RemoveAll(outDir) err := generateFromFile("testdata/acl.api.json", outDir) Expect(err).ShouldNot(HaveOccurred()) - fileInfo, err := os.Stat(outDir + "/acl/acl.go") + fileInfo, err := os.Stat(outDir + "/acl/acl.ba.go") Expect(err).ShouldNot(HaveOccurred()) Expect(fileInfo.IsDir()).To(BeFalse()) - Expect(fileInfo.Name()).To(BeEquivalentTo("acl.go")) + Expect(fileInfo.Name()).To(BeEquivalentTo("acl.ba.go")) } func TestGenerateFromFileInputError(t *testing.T) { @@ -56,7 +58,7 @@ func TestGenerateFromFileInputError(t *testing.T) { outDir := "test_output_directory" err := generateFromFile("testdata/nonexisting.json", outDir) Expect(err).Should(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring("reading data from file failed")) + Expect(err.Error()).To(ContainSubstring("invalid input file name")) } func TestGenerateFromFileReadJsonError(t *testing.T) { @@ -64,7 +66,7 @@ func TestGenerateFromFileReadJsonError(t *testing.T) { outDir := "test_output_directory" err := generateFromFile("testdata/input-read-json-error.json", outDir) Expect(err).Should(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring("JSON unmarshall failed")) + Expect(err.Error()).To(ContainSubstring("invalid input file name")) } func TestGenerateFromFileGeneratePackageError(t *testing.T) { @@ -87,7 +89,7 @@ func TestGetContext(t *testing.T) { result, err := getContext("testdata/af_packet.api.json", outDir) Expect(err).ShouldNot(HaveOccurred()) Expect(result).ToNot(BeNil()) - Expect(result.outputFile).To(BeEquivalentTo(outDir + "/af_packet/af_packet.go")) + Expect(result.outputFile).To(BeEquivalentTo(outDir + "/af_packet/af_packet.ba.go")) } func TestGetContextNoJsonFile(t *testing.T) { @@ -102,12 +104,11 @@ func TestGetContextNoJsonFile(t *testing.T) { func TestGetContextInterfaceJson(t *testing.T) { RegisterTestingT(t) outDir := "test_output_directory" - result, err := getContext("testdata/interface.json", outDir) + result, err := getContext("testdata/ip.api.json", outDir) Expect(err).ShouldNot(HaveOccurred()) Expect(result).ToNot(BeNil()) Expect(result.outputFile) - Expect(result.outputFile).To(BeEquivalentTo(outDir + "/interfaces/interfaces.go")) - + Expect(result.outputFile).To(BeEquivalentTo(outDir + "/ip/ip.ba.go")) } func TestReadJson(t *testing.T) { @@ -129,7 +130,6 @@ func TestReadJsonError(t *testing.T) { Expect(result).To(BeNil()) } -/* func TestGeneratePackage(t *testing.T) { RegisterTestingT(t) // prepare context @@ -140,9 +140,13 @@ func TestGeneratePackage(t *testing.T) { inputData, err := readFile("testdata/ip.api.json") Expect(err).ShouldNot(HaveOccurred()) testCtx.inputBuff = bytes.NewBuffer(inputData) - inFile, _ := parseJSON(inputData) + jsonRoot, err := parseJSON(inputData) + Expect(err).ShouldNot(HaveOccurred()) + testCtx.packageData, err = parsePackage(testCtx, jsonRoot) + Expect(err).ShouldNot(HaveOccurred()) outDir := "test_output_directory" - outFile, _ := os.Create(outDir) + outFile, err := os.Create(outDir) + Expect(err).ShouldNot(HaveOccurred()) defer os.RemoveAll(outDir) // prepare writer @@ -152,7 +156,6 @@ func TestGeneratePackage(t *testing.T) { Expect(err).ShouldNot(HaveOccurred()) } - func TestGenerateMessageType(t *testing.T) { RegisterTestingT(t) // prepare context @@ -163,31 +166,25 @@ func TestGenerateMessageType(t *testing.T) { inputData, err := readFile("testdata/ip.api.json") Expect(err).ShouldNot(HaveOccurred()) testCtx.inputBuff = bytes.NewBuffer(inputData) - inFile, _ := parseJSON(inputData) + jsonRoot, err := parseJSON(inputData) + Expect(err).ShouldNot(HaveOccurred()) outDir := "test_output_directory" - outFile, _ := os.Create(outDir) + outFile, err := os.Create(outDir) + Expect(err).ShouldNot(HaveOccurred()) + testCtx.packageData, err = parsePackage(testCtx, jsonRoot) + Expect(err).ShouldNot(HaveOccurred()) defer os.RemoveAll(outDir) // prepare writer writer := bufio.NewWriter(outFile) - types := inFile.Map("types") - testCtx.types = map[string]string{ - "u32": "sw_if_index", - "u8": "weight", - } - Expect(types.Len()).To(BeEquivalentTo(1)) - for i := 0; i < types.Len(); i++ { - typ := types.At(i) - Expect(writer.Buffered()).To(BeZero()) - err := generateMessage(testCtx, writer, typ, true) - Expect(err).ShouldNot(HaveOccurred()) + for _, msg := range testCtx.packageData.Messages { + generateMessage(testCtx, writer, &msg) Expect(writer.Buffered()).ToNot(BeZero()) - } } -func TestGenerateMessageName(t *testing.T) { +/*func TestGenerateMessageName(t *testing.T) { RegisterTestingT(t) // prepare context testCtx := new(context) |