@@ -2,7 +2,9 @@ package adj
22
33import (
44 "encoding/json"
5+ "log"
56 "os"
7+ "os/exec"
68
79 "github.com/HyperloopUPV-H8/h9-backend/internal/utils"
810)
@@ -12,8 +14,8 @@ const (
1214 RepoPath = "./adj/" // Path where the ADJ repository is cloned
1315)
1416
15- func NewADJ (AdjBranch string ) (ADJ , error ) {
16- infoRaw , boardsRaw , err := downloadADJ (AdjBranch )
17+ func NewADJ (AdjBranch string , test bool ) (ADJ , error ) {
18+ infoRaw , boardsRaw , err := downloadADJ (AdjBranch , test )
1719 if err != nil {
1820 return ADJ {}, err
1921 }
@@ -36,21 +38,17 @@ func NewADJ(AdjBranch string) (ADJ, error) {
3638 }
3739 }
3840
39- type BoardList struct {
40- Boards map [string ]string `json:"boards"`
41- }
42-
43- var boardsList BoardList
41+ var boardsList map [string ]string
4442 if err := json .Unmarshal (boardsRaw , & boardsList ); err != nil {
4543 return ADJ {}, err
4644 }
4745
48- boards , err := getBoards (boardsList . Boards )
46+ boards , err := getBoards (boardsList )
4947 if err != nil {
5048 return ADJ {}, err
5149 }
5250
53- info .BoardIds , err = getBoardIds (boardsList . Boards )
51+ info .BoardIds , err = getBoardIds (boardsList )
5452 if err != nil {
5553 return ADJ {}, err
5654 }
@@ -71,10 +69,18 @@ func NewADJ(AdjBranch string) (ADJ, error) {
7169 return adj , nil
7270}
7371
74- func downloadADJ (AdjBranch string ) (json.RawMessage , json.RawMessage , error ) {
72+ func downloadADJ (AdjBranch string , test bool ) (json.RawMessage , json.RawMessage , error ) {
7573 updateRepo (AdjBranch )
7674
77- // The BoardIds are applied in the NewADJ function by the getBoardIds function
75+ //Execute the script testadj.py if indicated in config.toml
76+ if test {
77+ test := exec .Command ("python3" , "testadj.py" )
78+ out , err := test .CombinedOutput ()
79+ if err != nil || len (out ) != 0 {
80+ log .Fatalf ("python test failed:\n Error: %v\n Output: %s\n " , err , string (out ))
81+ }
82+ }
83+
7884 info , err := os .ReadFile (RepoPath + "general_info.json" )
7985 if err != nil {
8086 return nil , nil , err
0 commit comments