personality_test.go 766 B

123456789101112131415161718192021222324252627282930
  1. package eliza
  2. import (
  3. "encoding/json"
  4. "io/ioutil"
  5. "os"
  6. "testing"
  7. )
  8. func TestParsePersonality(t *testing.T) {
  9. t.Log("Reading Personality test\n")
  10. jsonFile, err := os.Open("../bots/eliza.json")
  11. // if we os.Open returns an error then handle it
  12. if err != nil {
  13. t.Errorf(err.Error())
  14. }
  15. t.Log("Successfully Opened eliza.json")
  16. byteValue, _ := ioutil.ReadAll(jsonFile)
  17. // we initialize our Users array
  18. var personality Personality
  19. // we unmarshal our byteArray which contains our
  20. // jsonFile's content into 'users' which we defined above
  21. json.Unmarshal(byteValue, &personality)
  22. t.Log("Successfully Parsed eliza.json - name field is "+personality.Name)
  23. // defer the closing of our jsonFile so that we can parse it later on
  24. defer jsonFile.Close()
  25. }