versionsapi: allow debug stream

Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
Paul Meyer 2022-12-02 16:59:09 +01:00
parent 9c9c8e3d46
commit 8c5fc7a890
2 changed files with 34 additions and 2 deletions

View File

@ -29,7 +29,7 @@ import (
// "v1.0" and a list of patch versions "v1.0.0", "v1.0.1", "v1.0.2" etc. // "v1.0" and a list of patch versions "v1.0.0", "v1.0.1", "v1.0.2" etc.
type List struct { type List struct {
// Stream is the update stream of the list. // Stream is the update stream of the list.
// Currently, only "stable" is supported. // Currently, only "stable" and "debug" are supported.
Stream string `json:"stream"` Stream string `json:"stream"`
// Granularity is the granularity of the base version of this list. // Granularity is the granularity of the base version of this list.
// It can be either "major" or "minor". // It can be either "major" or "minor".
@ -52,7 +52,7 @@ type List struct {
// - All versions in the list are valid semantic versions that are finer-grained than the base version. // - All versions in the list are valid semantic versions that are finer-grained than the base version.
func (l *List) Validate() error { func (l *List) Validate() error {
var issues []string var issues []string
if l.Stream != "stable" { if !IsValidStream(l.Stream) {
issues = append(issues, fmt.Sprintf("stream %q is not supported", l.Stream)) issues = append(issues, fmt.Sprintf("stream %q is not supported", l.Stream))
} }
if l.Granularity != "major" && l.Granularity != "minor" { if l.Granularity != "major" && l.Granularity != "minor" {
@ -178,6 +178,19 @@ func getFromURL(ctx context.Context, client httpc, stream, granularity, base, ki
return content, nil return content, nil
} }
// IsValidStream returns true if the given stream is a valid stream.
func IsValidStream(stream string) bool {
validStreams := []string{"stable", "debug"}
for _, validStream := range validStreams {
if stream == validStream {
return true
}
}
return false
}
type httpc interface { type httpc interface {
Do(req *http.Request) (*http.Response, error) Do(req *http.Request) (*http.Response, error)
} }

View File

@ -277,3 +277,22 @@ func minorList() *List {
}, },
} }
} }
func TestIsValidStream(t *testing.T) {
testCases := map[string]bool{
"stable": true,
"debug": true,
"beta": false,
"alpha": false,
"unknown": false,
"fast": false,
}
for name, want := range testCases {
t.Run(name, func(t *testing.T) {
assert := assert.New(t)
assert.Equal(want, IsValidStream(name))
})
}
}