config_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package config
  2. import "testing"
  3. func TestSaveConfig(t *testing.T) {
  4. conf := &Config{}
  5. id := 12245
  6. conf.Id = &id
  7. conf.Net.Listen = "tcp:localhost:12345"
  8. conf.Net.As = "tcp:10.0.0.1:12345"
  9. conf.Net.Command = "unix:/tmp/bdjncl"
  10. in := []Io{{"video", "application/mod"}}
  11. out := []Io{{"result", "application/json"}}
  12. sk := Skill{"test", in, out}
  13. sk2 := Skill{"test2", in, out}
  14. conf.Peers = []Peer{
  15. Peer{As: "tcp:localhost:12346", Skills: []Skill{sk}},
  16. Peer{As: "tcp:localhost:12347", Skills: []Skill{sk}},
  17. }
  18. st0 := Step{"s3-download", `"$input_video"`}
  19. st1 := Step{"sh", `/bin/echo "$input_video" "$output_result"`}
  20. conf.Jobs = []Job{
  21. Job{sk, []Step{st0, st1}},
  22. Job{sk2, []Step{st1, st0}},
  23. }
  24. conf.States = []State{
  25. State{"test", "running", 1},
  26. }
  27. err := conf.SaveTomlFileName("testdata/config.toml")
  28. if err != nil {
  29. t.Errorf("Error saving: %s", err)
  30. }
  31. err = conf.SaveYamlFileName("testdata/config.yaml")
  32. if err != nil {
  33. t.Errorf("Error saving: %s", err)
  34. }
  35. dat, err := LoadYamlFileName("testdata/config.yaml")
  36. if err != nil {
  37. t.Errorf("Error loading: %s", err)
  38. }
  39. t.Logf("Encoded: %v", conf)
  40. t.Logf("Loaded: %v", dat)
  41. err = conf.SaveHclFileName("testdata/config.hcl")
  42. if err != nil {
  43. t.Errorf("Error saving: %s", err)
  44. }
  45. dat, err = LoadHclFileName("testdata/config.hcl")
  46. if err != nil {
  47. t.Errorf("Error loading: %s", err)
  48. }
  49. t.Logf("Encoded: %v", conf)
  50. t.Logf("Loaded: %v", dat)
  51. }