summaryrefslogtreecommitdiff
path: root/vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/generator_test.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2018-03-26 09:39:14 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-04-23 14:29:45 +0000
commit8493dba23c73617d9529b7ca13b400d50ac6f455 (patch)
treec0de0c67334b9fa7166e01cae95dc560c1e2455a /vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/generator_test.go
parentcf1d884ffa45b342f38a78189bbd86186ce6cbfe (diff)
downloadpodman-8493dba23c73617d9529b7ca13b400d50ac6f455.tar.gz
podman-8493dba23c73617d9529b7ca13b400d50ac6f455.tar.bz2
podman-8493dba23c73617d9529b7ca13b400d50ac6f455.zip
Initial varlink implementation
Signed-off-by: baude <bbaude@redhat.com> Closes: #627 Approved by: mheon
Diffstat (limited to 'vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/generator_test.go')
-rw-r--r--vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/generator_test.go85
1 files changed, 85 insertions, 0 deletions
diff --git a/vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/generator_test.go b/vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/generator_test.go
new file mode 100644
index 000000000..aa3a8565f
--- /dev/null
+++ b/vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/generator_test.go
@@ -0,0 +1,85 @@
+package main
+
+import (
+ "strings"
+ "testing"
+)
+
+func expect(t *testing.T, expected string, returned string) {
+ if strings.Compare(returned, expected) != 0 {
+ t.Fatalf("Expected(%d): `%s`\nGot(%d): `%s`\n",
+ len(expected), expected,
+ len(returned), returned)
+ }
+}
+
+func TestIDLParser(t *testing.T) {
+ pkgname, b, err := generateTemplate(`
+# Interface to jump a spacecraft to another point in space. The
+# FTL Drive is the propulsion system to achieve faster-than-light
+# travel through space. A ship making a properly calculated
+# jump can arrive safely in planetary orbit, or alongside other
+# ships or spaceborne objects.
+interface org.example.ftl
+
+# The current state of the FTL drive and the amount of fuel
+# available to jump.
+type DriveCondition (
+ state: (idle, spooling, busy),
+ booster: bool,
+ active_engines: [](id: int, state: bool),
+ tylium_level: int
+)
+
+# Speed, trajectory and jump duration is calculated prior to
+# activating the FTL drive.
+type DriveConfiguration (
+ speed: int,
+ trajectory: int,
+ duration: int
+)
+
+# The galactic coordinates use the Sun as the origin. Galactic
+# longitude is measured with primary direction from the Sun to
+# the center of the galaxy in the galactic plane, while the
+# galactic latitude measures the angle of the object above the
+# galactic plane.
+type Coordinate (
+ longitude: float,
+ latitude: float,
+ distance: int
+)
+
+# Monitor the drive. The method will reply with an update whenever
+# the drive's state changes
+method Monitor() -> (condition: DriveCondition)
+
+# Calculate the drive's jump parameters from the current
+# position to the target position in the galaxy
+method CalculateConfiguration(
+ current: Coordinate,
+ target: Coordinate
+) -> (configuration: DriveConfiguration)
+
+# Jump to the calculated point in space
+method Jump(configuration: DriveConfiguration) -> ()
+
+# There is not enough tylium to jump with the given parameters
+error NotEnoughEnergy ()
+
+# The supplied parameters are outside the supported range
+error ParameterOutOfRange (field: string)
+
+# some more coverage
+method Foo(interface: string) -> (ret: (go: string, switch: bool, more: (t:bool, f:bool)))
+ `)
+
+ if err != nil {
+ t.Fatalf("Error parsing %v", err)
+ }
+ expect(t, "orgexampleftl", pkgname)
+ if len(b) <= 0 {
+ t.Fatal("No generated go source")
+ }
+ // FIXME: compare b.String() against expected output
+}