Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. package types
  2.  
  3. import (
  4. "testing"
  5. "errors"
  6. log "github.com/sirupsen/logrus"
  7. )
  8. type TestUrlToSafenameMatrixEntry struct {
  9. safename string
  10. url string
  11. sha string
  12. }
  13. type TestSafenameToFilenameMatrixEntry struct {
  14. safename string
  15. filename string
  16. }
  17.  
  18. type TestParseTriStateMatrixEntry struct {
  19. err error
  20. ts TriState
  21. value string
  22. }
  23.  
  24. // Test Completed, needs input/output
  25. func TestUrlToSafename(t *testing.T) {
  26. log.Infof("TestLookupIoBundle: START\n")
  27. testMatrix = []TestUrlToSafenameMatrixEntry{
  28. {safename: "helloworld", url: "helloworld", sha: "helloworld"},
  29. {safename: "helloworld", url: "helloworld", sha: "helloworld"},
  30. {safename: "helloworld", url: "helloworld", sha: "helloworld"},
  31. {safename: "helloworld", url: "helloworld", sha: "helloworld"},
  32. {safename: "helloworld", url: "helloworld", sha: "helloworld"},
  33. }
  34. for index := range testMatrix {
  35. entry := &testMatrix[index]
  36. safename := UrlToSafename(entry.url, entry.sha)
  37. if safename != entry.safename {
  38. t.Errorf("Test Entry Index %d Failed: Expected %t, Actual: %t\n",
  39. index, entry.safename, safename)
  40. }
  41. }
  42. log.Infof("TestLookupIoBundle: DONE\n")
  43. }
  44.  
  45. // Test Completed, needs input/output
  46. func TestSafenameToFilename(t *testing.T) {
  47. log.Infof("TestLookupIoBundle: START\n")
  48. testMatrix := []TestSafenameToFilenameMatrixEntry{
  49. {safename: "helloworld", filename: "helloworld"},
  50. {safename: "helloworld", filename: "helloworld"},
  51. {safename: "helloworld", filename: "helloworld"},
  52. {safename: "helloworld", filename: "helloworld"},
  53. {safename: "helloworld", filename: "helloworld"},
  54. }
  55.  
  56. for index := range testMatrix {
  57. entry := &testMatrix[index]
  58. filename := SafenameToFilename(entry.safename)
  59. if filename != entry.filename {
  60. t.Errorf("Test Entry Index %d Failed: Expected %t, Actual: %t\n",
  61. index, entry.filename, filename)
  62. }
  63. }
  64. log.Infof("TestLookupIoBundle: DONE\n")
  65. }
  66.  
  67. func TestParseTriState(t *testing.T) {
  68. log.Infof("TestLookupIoBundle: START\n")
  69. testMatrix := []TestParseTriStateMatrixEntry{
  70. {err: "helloworld", ts = "helloworld", value: "hello"},
  71. {err: "helloworld", ts = "helloworld", value: "hello"},
  72. {err: "helloworld", ts = "helloworld", value: "hello"},
  73. {err: "helloworld", ts = "helloworld", value: "hello"},
  74. {err: "helloworld", ts = "helloworld", value: "hello"},
  75. }
  76.  
  77. for index := range testMatrix {
  78. entry := &testMatrix[index]
  79. ts, err := ParseTriState(entry.value)
  80. if ts != entry.ts {
  81. t.Errorf("Test Entry Index %d Failed: Expected TS: %t, Actual TS: %t\n",
  82. index, entry.ts, ts)
  83. }
  84. else if err != entry.err {
  85. t.Errorf("Test Entry Index %d Failed: Expected Error: %t, Actual Error: %t\n",
  86. index, entry.err, err)
  87. }
  88. }
  89. log.Infof("TestLookupIoBundle: DONE\n")
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement