feat(cli): support bundle: show links to docs/admin/healthcheck (#12974)

This commit is contained in:
Cian Johnston
2024-04-16 16:21:09 +01:00
committed by GitHub
parent b598aef543
commit 8e1e0f04a4
5 changed files with 86 additions and 12 deletions
+30
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"strings"
"github.com/coder/coder/v2/buildinfo"
"github.com/coder/coder/v2/coderd/util/ptr"
)
@@ -44,6 +45,11 @@ const (
CodeProvisionerDaemonAPIMajorVersionDeprecated Code = `EPD03`
)
// Default docs URL
var (
docsURLDefault = "https://coder.com/docs/v2"
)
// @typescript-generate Severity
type Severity string
@@ -72,6 +78,30 @@ func (m Message) String() string {
return sb.String()
}
// URL returns a link to the admin/healthcheck docs page for the given Message.
// NOTE: if using a custom docs URL, specify base.
func (m Message) URL(base string) string {
var codeAnchor string
if m.Code == "" {
codeAnchor = strings.ToLower(string(CodeUnknown))
} else {
codeAnchor = strings.ToLower(string(m.Code))
}
if base == "" {
base = docsURLDefault
versionPath := buildinfo.Version()
if buildinfo.IsDev() {
// for development versions, just use latest
versionPath = "latest"
}
return fmt.Sprintf("%s/%s/admin/healthcheck#%s", base, versionPath, codeAnchor)
}
// We don't assume that custom docs URLs are versioned.
return fmt.Sprintf("%s/admin/healthcheck#%s", base, codeAnchor)
}
// Code is a stable identifier used to link to documentation.
// @typescript-generate Code
type Code string
+32
View File
@@ -0,0 +1,32 @@
package health_test
import (
"testing"
"github.com/coder/coder/v2/coderd/healthcheck/health"
"github.com/stretchr/testify/assert"
)
func Test_MessageURL(t *testing.T) {
t.Parallel()
for _, tt := range []struct {
name string
code health.Code
base string
expected string
}{
{"empty", "", "", "https://coder.com/docs/v2/latest/admin/healthcheck#eunknown"},
{"default", health.CodeAccessURLFetch, "", "https://coder.com/docs/v2/latest/admin/healthcheck#eacs03"},
{"custom docs base", health.CodeAccessURLFetch, "https://example.com/docs", "https://example.com/docs/admin/healthcheck#eacs03"},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
uut := health.Message{Code: tt.code}
actual := uut.URL(tt.base)
assert.Equal(t, tt.expected, actual)
})
}
}