diff --git a/http.go b/http.go index a6cfddf..3c0e038 100644 --- a/http.go +++ b/http.go @@ -43,7 +43,7 @@ func (s *Server) runHTTP() error { router.GET("/ready", s.getReady) router.POST("/suites/:suite-name/runs", s.startTestSuite) - router.GET("/suites", s.getTestSuites) + router.GET("/suites", s.getTestSuitesWithRuns) router.GET("/suites/:suite-name/runs", s.getTestSuiteRuns) router.GET("/suites/:suite-name/runs/:run-id", s.getTestSuiteRun) router.GET("/suites/:suite-name/runs/:run-id/test/:test-name", s.getTestRunResult) @@ -212,6 +212,30 @@ func (s *Server) getTestSuites(w http.ResponseWriter, r *http.Request, p httprou s.writeResponse(w, r, http.StatusOK, testSuites) } +func (s *Server) getTestSuitesWithRuns(w http.ResponseWriter, r *http.Request, p httprouter.Params) { + testSuitesWitRuns := make([]model.TestSuiteWithRuns, 0, len(s.readOnlyTestSuites)) + + for _, suite := range s.readOnlyTestSuites { + runs, err := s.storage.LoadTestSuiteRunsByName(r.Context(), suite.Name) + if err != nil { + s.httpError(w, err) + return + } + + fmt.Println(len(runs)) + + testSuitesWitRuns = append(testSuitesWitRuns, model.TestSuiteWithRuns{ + Suite: suite, + SuiteRuns: runs, + }) + } + + fmt.Println(len(s.readOnlyTestSuites)) + fmt.Println(len(testSuitesWitRuns)) + + s.writeResponse(w, r, http.StatusOK, testSuitesWitRuns) +} + func (s *Server) getTestSuiteRun(w http.ResponseWriter, r *http.Request, p httprouter.Params) { testRun, err := s.loadTestSuiteRun(r.Context(), p) if err != nil { @@ -277,6 +301,8 @@ func (s *Server) writeResponse(w http.ResponseWriter, r *http.Request, status in err = html.RenderTestSuiteRuns(buf.String(), t).Render(r.Context(), w) case []model.TestSuite: err = html.RenderTestSuites(t).Render(r.Context(), w) + case []model.TestSuiteWithRuns: + err = html.RenderTestSuitesWithRuns(t).Render(r.Context(), w) default: return fmt.Errorf("no template available for type %v", t) } diff --git a/internal/html/component/test_suites_with_runs.templ b/internal/html/component/test_suites_with_runs.templ new file mode 100644 index 0000000..ae6d412 --- /dev/null +++ b/internal/html/component/test_suites_with_runs.templ @@ -0,0 +1,55 @@ +package component + +import ( + "fmt" + "github.com/raphi011/handoff/internal/model" +) + +templ TestSuitesWithRuns(suitesWithRuns []model.TestSuiteWithRuns) { +
+
+

Test Suites With Runs

+
+ +
+ +} diff --git a/internal/html/component/test_suites_with_runs_templ.go b/internal/html/component/test_suites_with_runs_templ.go new file mode 100644 index 0000000..1a55f0a --- /dev/null +++ b/internal/html/component/test_suites_with_runs_templ.go @@ -0,0 +1,98 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.793 +package component + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import templruntime "github.com/a-h/templ/runtime" + +import ( + "fmt" + "github.com/raphi011/handoff/internal/model" +) + +func TestSuitesWithRuns(suitesWithRuns []model.TestSuiteWithRuns) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Test Suites With Runs

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return templ_7745c5c3_Err + }) +} + +var _ = templruntime.GeneratedTemplate diff --git a/internal/html/test-run.templ b/internal/html/test-run.templ index f982964..9d71e27 100644 --- a/internal/html/test-run.templ +++ b/internal/html/test-run.templ @@ -49,3 +49,9 @@ templ RenderTestSuites(suites []model.TestSuite) { @component.TestSuites(suites) } } + +templ RenderTestSuitesWithRuns(suites []model.TestSuiteWithRuns) { + @body() { + @component.TestSuitesWithRuns(suites) + } +} diff --git a/internal/html/test-run_templ.go b/internal/html/test-run_templ.go index ab9441f..34206b4 100644 --- a/internal/html/test-run_templ.go +++ b/internal/html/test-run_templ.go @@ -361,4 +361,51 @@ func RenderTestSuites(suites []model.TestSuite) templ.Component { }) } +func RenderTestSuitesWithRuns(suites []model.TestSuiteWithRuns) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var17 := templ.GetChildren(ctx) + if templ_7745c5c3_Var17 == nil { + templ_7745c5c3_Var17 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var18 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = component.TestSuitesWithRuns(suites).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return templ_7745c5c3_Err + }) + templ_7745c5c3_Err = body().Render(templ.WithChildren(ctx, templ_7745c5c3_Var18), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return templ_7745c5c3_Err + }) +} + var _ = templruntime.GeneratedTemplate diff --git a/internal/model/models.go b/internal/model/models.go index 54b7e78..aa6b006 100644 --- a/internal/model/models.go +++ b/internal/model/models.go @@ -310,6 +310,11 @@ type TestSuite struct { // lock *sync.Mutex } +type TestSuiteWithRuns struct { + Suite TestSuite + SuiteRuns []TestSuiteRun +} + func (t TestSuite) SafeTeardown() (err error) { if t.Teardown == nil { return nil