Skip to content

Commit

Permalink
add combined test suite and runs model and view
Browse files Browse the repository at this point in the history
  • Loading branch information
nigogo committed Nov 24, 2024
1 parent a03fc3d commit d4256e1
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 1 deletion.
28 changes: 27 additions & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
55 changes: 55 additions & 0 deletions internal/html/component/test_suites_with_runs.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package component

import (
"fmt"
"github.com/raphi011/handoff/internal/model"
)

templ TestSuitesWithRuns(suitesWithRuns []model.TestSuiteWithRuns) {
<main class="lg:pl-72">
<header class="flex items-center justify-between border-b border-white/5 px-4 py-4 sm:px-6 sm:py-6 lg:px-8">
<h1 class="text-base/7 font-semibold text-gray-900">Test Suites With Runs</h1>
</header>
<ul role="list" class="divide-y divide-gray/5 border-t border-b">
for _, suite := range suitesWithRuns {
<li class="relative flex items-center space-x-4 px-4 py-4 sm:px-6 lg:px-8">
<div class="min-w-0 flex-auto">
<div class="flex items-center gap-x-3">
<div class="flex-none rounded-full bg-gray-600/10 p-1 text-gray-500">
<div class="size-2 rounded-full bg-current"></div>
</div>
<h2 class="min-w-0 text-sm/6 font-semibold text-gray-500">
<a href={ templ.URL(fmt.Sprintf("/suites/%s/runs", suite.Suite.Name)) } class="flex gap-x-2">
<span class="truncate">Staging</span>
<span class="text-gray-400">/</span>
<span class="whitespace-nowrap text-gray-900">{ suite.Suite.Name }</span>
<span class="absolute inset-0"></span>
</a>
</h2>
</div>
<div class="mt-3 flex items-center gap-x-2.5 text-xs/5 text-gray-400">
<p class="truncate">{ fmt.Sprintf("%d tests in suite", len(suite.Suite.Tests)) }</p>
<svg viewBox="0 0 2 2" class="size-0.5 flex-none fill-gray-300">
<circle cx="1" cy="1" r="1"></circle>
</svg>
<p class="whitespace-nowrap">Initiated 1m 32s ago</p>
</div>
</div>
<!-- <div class="flex-none rounded-full bg-gray-400/10 px-2 py-1 text-xs font-medium text-gray-400 ring-1 ring-inset ring-gray-400/20">Preview</div> -->
<!-- <svg class="size-5 flex-none text-gray-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-slot="icon"> -->
<!-- <path fill-rule="evenodd" d="M8.22 5.22a.75.75 0 0 1 1.06 0l4.25 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.75.75 0 0 1-1.06-1.06L11.94 10 8.22 6.28a.75.75 0 0 1 0-1.06Z" clip-rule="evenodd"></path> -->
<!-- </svg> -->
</li>
}
</ul>
</main>
<aside class="bg-white lg:fixed lg:bottom-0 lg:right-0 lg:top-0 lg:w-2/6 lg:overflow-y-auto lg:border-l lg:border-gray/5">
<header class="flex items-center justify-between border-b border-white/5 px-4 py-4 sm:px-6 sm:py-6 lg:px-8">
<h2 class="text-base/7 font-semibold text-gray-900">Runs</h2>
<a href="#" class="text-sm/6 font-semibold text-indigo-400">View all</a>
</header>
<div class="divide-y divide-white/5 border-t p-5">
@RunActivity()
</div>
</aside>
}
98 changes: 98 additions & 0 deletions internal/html/component/test_suites_with_runs_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions internal/html/test-run.templ
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ templ RenderTestSuites(suites []model.TestSuite) {
@component.TestSuites(suites)
}
}

templ RenderTestSuitesWithRuns(suites []model.TestSuiteWithRuns) {
@body() {
@component.TestSuitesWithRuns(suites)
}
}
47 changes: 47 additions & 0 deletions internal/html/test-run_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions internal/model/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d4256e1

Please sign in to comment.