app_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package main
  2. import (
  3. "strings"
  4. "testing"
  5. )
  6. func TestSetBaseURL(t *testing.T) {
  7. urlWithSlash := "http://test.com:880/test/"
  8. urlWithoutSlash := "http://test.com:880/test"
  9. t.Log("Testing if mandatory slash is added to the end of BaseURL.")
  10. var app Application
  11. app.SetBaseURL(urlWithSlash)
  12. if strings.HasSuffix(app.BaseURL, "//") {
  13. t.Errorf("URL has been malformed: %v", app.BaseURL)
  14. } else {
  15. t.Log("URL with slash was set correctly!")
  16. }
  17. app.SetBaseURL(urlWithoutSlash)
  18. if !strings.HasSuffix(app.BaseURL, "/") {
  19. t.Errorf("URL has been malformed: %v", app.BaseURL)
  20. } else {
  21. t.Log("URL without slash was set correctly!")
  22. }
  23. }
  24. func TestLoadLanguages(t *testing.T) {
  25. var app Application
  26. app.LoadLanguages()
  27. testLanguageCode := "dan"
  28. testLanguage := "Danish"
  29. t.Log("Testing if languages have been successfully loaded to app.Languages dictionary.")
  30. _, ok := app.Languages[testLanguageCode]
  31. if !ok {
  32. t.Fatalf("There's no key '%v'!", testLanguageCode)
  33. } else if app.Languages[testLanguageCode] == testLanguage {
  34. t.Log("Languages are in dictionary!")
  35. } else {
  36. t.Fatalf("Value of key '%v' isn't '%v'", testLanguageCode, testLanguage)
  37. }
  38. }