github.com/metacurrency/holochain@v0.1.0-alpha-26.0.20200915073418-5c83169c9b5b/app_package_test.go (about)

     1  package holochain
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  	. "github.com/smartystreets/goconvey/convey"
     7  	"strings"
     8  	"testing"
     9  )
    10  
    11  func TestLoadAppPackage(t *testing.T) {
    12  	appPackageBlob := bytes.NewBuffer([]byte(BasicTemplateAppPackage))
    13  	appPackage, err := LoadAppPackage(appPackageBlob, BasicTemplateAppPackageFormat)
    14  	Convey("it should load dna from a appPackage blob", t, func() {
    15  		So(err, ShouldBeNil)
    16  		dna := appPackage.DNA
    17  		So(dna.Name, ShouldEqual, "templateApp")
    18  		So(dna.Properties["description"], ShouldEqual, "provides an application template")
    19  		So(fmt.Sprintf("%v", dna.UUID), ShouldEqual, "00000000-0000-0000-0000-000000000000")
    20  		So(dna.Version, ShouldEqual, 1)
    21  		So(dna.DHTConfig.HashType, ShouldEqual, "sha2-256")
    22  		So(strings.Contains(dna.PropertiesSchema, `"properties"`), ShouldBeTrue)
    23  		So(strings.Contains(dna.Zomes[0].Code, "function genesis"), ShouldBeTrue)
    24  		So(dna.Zomes[0].Entries[0].Name, ShouldEqual, "sampleEntry")
    25  		So(dna.Zomes[0].Entries[0].Schema, ShouldEqual, "{\n	\"title\": \"sampleEntry Schema\",\n	\"type\": \"object\",\n	\"properties\": {\n		\"content\": {\n			\"type\": \"string\"\n		},\n		\"timestamp\": {\n			\"type\": \"integer\"\n		}\n	},\n    \"required\": [\"content\", \"timestamp\"]\n}")
    26  		So(dna.Zomes[0].Functions[0].Name, ShouldEqual, "sampleEntryCreate")
    27  	})
    28  
    29  	Convey("it should load tests from a appPackage blob", t, func() {
    30  		So(appPackage.TestSets[0].Name, ShouldEqual, "sample")
    31  		So(appPackage.TestSets[0].TestSet.Tests[0].Convey, ShouldEndWith, "We can create a new sampleEntry")
    32  	})
    33  
    34  	Convey("it should load scenarios from a appPackage blob", t, func() {
    35  		So(appPackage.Scenarios[0].Name, ShouldEqual, "sampleScenario")
    36  		So(appPackage.Scenarios[0].Roles[0].Name, ShouldEqual, "listener")
    37  		So(len(appPackage.Scenarios[0].Roles[0].TestSet.Tests), ShouldEqual, 1)
    38  		So(appPackage.Scenarios[0].Roles[0].TestSet.Tests[0].Convey, ShouldEqual, "add listener test here")
    39  		So(appPackage.Scenarios[0].Roles[1].Name, ShouldEqual, "speaker")
    40  		So(len(appPackage.Scenarios[0].Roles[1].TestSet.Tests), ShouldEqual, 1)
    41  		So(appPackage.Scenarios[0].Roles[1].TestSet.Tests[0].Convey, ShouldEqual, "add speaker test here")
    42  		So(appPackage.Scenarios[0].Config.Duration, ShouldEqual, 5)
    43  		So(appPackage.Scenarios[0].Config.GossipInterval, ShouldEqual, 100)
    44  	})
    45  }