helper_test.go 742 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package seo
  2. import (
  3. "os"
  4. "strings"
  5. _ "github.com/lib/pq"
  6. "gorm.io/driver/postgres"
  7. "gorm.io/gorm"
  8. )
  9. type TestQorSEOSetting struct {
  10. QorSEOSetting
  11. }
  12. func init() {
  13. if db, err := gorm.Open(postgres.Open(os.Getenv("DBURL")), &gorm.Config{}); err != nil {
  14. panic(err)
  15. } else {
  16. GlobalDB = db
  17. }
  18. GlobalDB.AutoMigrate(&TestQorSEOSetting{})
  19. }
  20. // @snippet_begin(SeoModelExample)
  21. type Product struct {
  22. Name string
  23. SEO Setting
  24. }
  25. // @snippet_end
  26. func resetDB() {
  27. GlobalDB.Exec("truncate test_qor_seo_settings;")
  28. }
  29. func metaEqual(got, want string) bool {
  30. for _, s := range strings.Split(want, "\n") {
  31. s = strings.TrimSpace(s)
  32. if s == "" {
  33. continue
  34. }
  35. if !strings.Contains(got, s) {
  36. return false
  37. }
  38. }
  39. return true
  40. }