convert_lua_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // SPDX-FileCopyrightText: Adam Evyčędo
  2. //
  3. // SPDX-License-Identifier: AGPL-3.0-or-later
  4. package traffic
  5. import (
  6. "apiote.xyz/p/szczanieckiej/config"
  7. "bytes"
  8. "log"
  9. "strings"
  10. "testing"
  11. "text/template"
  12. "github.com/yuin/gopher-lua"
  13. )
  14. func TestLuaScripts(t *testing.T) {
  15. for feedID := range RegisterFeeds() {
  16. filenames := []string{"updates", "vehicles", "alerts"}
  17. for _, filename := range filenames {
  18. var buffer bytes.Buffer
  19. temp, err := template.ParseFS(luaScripts, feedID+"_"+filename+".lua")
  20. if err != nil {
  21. if strings.Contains(err.Error(), "pattern matches no files") {
  22. log.Printf("%s.lua for %s does not exist, ignoring\n", feedID, filename)
  23. continue
  24. }
  25. t.Errorf("while parsing template %s: %v", filename, err)
  26. continue
  27. }
  28. err = temp.Execute(&buffer, config.Auth{})
  29. if err != nil {
  30. t.Errorf("while executing template %s: %v", filename, err)
  31. continue
  32. }
  33. updateScript := string(buffer.Bytes())
  34. l := lua.NewState()
  35. if err := l.DoString(updateScript); err != nil {
  36. t.Errorf("in updates, in %s: %v\n", feedID, err)
  37. }
  38. l.Close()
  39. }
  40. }
  41. }