api_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // API version number check
  2. package main
  3. import (
  4. "fmt"
  5. "testing"
  6. "github.com/xyproto/algernon/engine"
  7. "github.com/xyproto/permissionbolt/v2"
  8. permissions "github.com/xyproto/permissions2/v2"
  9. "github.com/xyproto/pinterface"
  10. "github.com/xyproto/simplebolt"
  11. "github.com/xyproto/simpleredis/v2"
  12. //"github.com/xyproto/permissionsql"
  13. //"github.com/xyproto/pstore"
  14. //"github.com/xyproto/simplehstore"
  15. //"github.com/xyproto/simplemaria"
  16. )
  17. // VersionInfo helps to keep track of package names and versions
  18. type VersionInfo struct {
  19. name string
  20. current float64
  21. target float64
  22. }
  23. // New takes the name of the go package, the current and the desired version
  24. func New(name string, current, target float64) *VersionInfo {
  25. return &VersionInfo{name, current, target}
  26. }
  27. // Check compares the current and target version
  28. func (v *VersionInfo) Check() error {
  29. if v.current != v.target {
  30. return fmt.Errorf("is %.1f, needs version %.1f", v.current, v.target)
  31. }
  32. return nil
  33. }
  34. func TestAPI(t *testing.T) {
  35. if err := New("simplebolt", simplebolt.Version, 5.1).Check(); err != nil {
  36. t.Error(err)
  37. }
  38. if err := New("permissionbolt", permissionbolt.Version, 2.6).Check(); err != nil {
  39. t.Error(err)
  40. }
  41. if err := New("simpleredis", simpleredis.Version, 2.6).Check(); err != nil {
  42. t.Error(err)
  43. }
  44. if err := New("permissions2", permissions.Version, 2.6).Check(); err != nil {
  45. t.Error(err)
  46. }
  47. if err := New("pinterface", pinterface.Version, 5.3).Check(); err != nil {
  48. t.Error(err)
  49. }
  50. if err := New("engine", engine.Version, 2.0).Check(); err != nil {
  51. t.Error(err)
  52. }
  53. // These adds many dependencies when testing
  54. // if err := New("simplemaria", simplemaria.Version, 3.0).Check(); err != nil {
  55. // t.Error(err)
  56. // }
  57. // if err := New("permissionsql", permissionsql.Version, 2.0).Check(); err != nil {
  58. // t.Error(err)
  59. // }
  60. // if err := New("simplehstore", simplehstore.Version, 2.3).Check(); err != nil {
  61. // t.Error(err)
  62. // }
  63. // if err := New("pstore", pstore.Version, 3.1).Check(); err != nil {
  64. // t.Error(err)
  65. // }
  66. }