Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package wget_test

import (
"encoding/json"
"fmt"

. "github.com/mandelsoft/goutils/testutils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"ocm.software/ocm/api/utils/runtime"
"ocm.software/ocm/cmds/ocm/commands/ocmcmds/common/inputs"
"ocm.software/ocm/cmds/ocm/commands/ocmcmds/common/inputs/types/wget"
)

const aliasURL = "https://example.com/file"

var _ = Describe("wget input type spellings", func() {
mkData := func(typ string) []byte {
return []byte(fmt.Sprintf(`{"type":%q,"url":%q}`, typ, aliasURL))
}

DescribeTable("decode and round-trip every accepted type spelling",
func(typ string) {
in := mkData(typ)

By("decoding via the default input type scheme")
spec := Must(inputs.DefaultInputTypeScheme.DecodeInputSpec(in, runtime.DefaultJSONEncoding))
Expect(spec).To(BeAssignableToTypeOf(&wget.Spec{}))
Expect(spec.GetType()).To(Equal(typ))
Expect(spec.(*wget.Spec).URL).To(Equal(aliasURL))

By("marshalling preserving the type token")
out := Must(json.Marshal(spec))
Expect(string(out)).To(ContainSubstring(fmt.Sprintf(`"type":%q`, typ)))

By("decoding the marshalled form again")
redecoded := Must(inputs.DefaultInputTypeScheme.DecodeInputSpec(out, runtime.DefaultJSONEncoding))
Expect(redecoded).To(BeAssignableToTypeOf(&wget.Spec{}))
Expect(redecoded.GetType()).To(Equal(typ))
Expect(redecoded.(*wget.Spec).URL).To(Equal(aliasURL))
},
Entry("wget", "wget"),
Entry("wget/v1", "wget/v1"),
Entry("Wget", "Wget"),
Entry("Wget/v1", "Wget/v1"),
Entry("http", "http"),
Entry("http/v1", "http/v1"),
Entry("HTTP", "HTTP"),
Entry("HTTP/v1", "HTTP/v1"),
)
})
10 changes: 9 additions & 1 deletion cmds/ocm/commands/ocmcmds/common/inputs/types/wget/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ import (
)

func ConfigHandler() flagsets.ConfigOptionTypeSetHandler {
return configHandler(TYPE)
}

func HTTPConfigHandler() flagsets.ConfigOptionTypeSetHandler {
return configHandler(HTTP_TYPE)
}

func configHandler(name string) flagsets.ConfigOptionTypeSetHandler {
return flagsets.NewConfigOptionTypeSetHandler(
TYPE, AddConfig,
name, AddConfig,
options.URLOption,
options.MediaTypeOption,
options.HTTPHeaderOption,
Expand Down
15 changes: 14 additions & 1 deletion cmds/ocm/commands/ocmcmds/common/inputs/types/wget/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,30 @@ const (
UPPER_TYPE_V1 = UPPER_TYPE + runtime.VersionSeparator + "v1"
)

// Alias type names for the wget input type.
const (
HTTP_TYPE = "http"
HTTP_TYPE_V1 = HTTP_TYPE + runtime.VersionSeparator + "v1"
UPPER_HTTP_TYPE = "HTTP"
UPPER_HTTP_TYPE_V1 = UPPER_HTTP_TYPE + runtime.VersionSeparator + "v1"
)

func init() {
inputs.DefaultInputTypeScheme.Register(inputs.NewInputType(TYPE, &Spec{}, usage, ConfigHandler()))
inputs.DefaultInputTypeScheme.Register(inputs.NewInputType(TypeV1, &Spec{}, "", ConfigHandler()))
inputs.DefaultInputTypeScheme.Register(inputs.NewInputType(UPPER_TYPE, &Spec{}, "", ConfigHandler()))
inputs.DefaultInputTypeScheme.Register(inputs.NewInputType(UPPER_TYPE_V1, &Spec{}, "", ConfigHandler()))

inputs.DefaultInputTypeScheme.Register(inputs.NewInputType(HTTP_TYPE, &Spec{}, "", HTTPConfigHandler()))
inputs.DefaultInputTypeScheme.Register(inputs.NewInputType(HTTP_TYPE_V1, &Spec{}, "", HTTPConfigHandler()))
inputs.DefaultInputTypeScheme.Register(inputs.NewInputType(UPPER_HTTP_TYPE, &Spec{}, "", HTTPConfigHandler()))
inputs.DefaultInputTypeScheme.Register(inputs.NewInputType(UPPER_HTTP_TYPE_V1, &Spec{}, "", HTTPConfigHandler()))
}

const usage = `
The <code>url</code> is the url pointing to the http endpoint from which a resource is
downloaded. The <code>mimeType</code> can be used to specify the MIME type of the
resource.
resource. The input type can also be declared as <code>http</code> or <code>HTTP</code>.

This blob type specification supports the following fields:
- **<code>url</code>** *string*
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/ocm_add_resource-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ lowercase types (e.g. <code>helm</code>). See the lowercase entry for full docum

The <code>url</code> is the url pointing to the http endpoint from which a resource is
downloaded. The <code>mimeType</code> can be used to specify the MIME type of the
resource.
resource. The input type can also be declared as <code>http</code> or <code>HTTP</code>.

This blob type specification supports the following fields:
- **<code>url</code>** *string*
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/ocm_add_resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ lowercase types (e.g. <code>helm</code>). See the lowercase entry for full docum

The <code>url</code> is the url pointing to the http endpoint from which a resource is
downloaded. The <code>mimeType</code> can be used to specify the MIME type of the
resource.
resource. The input type can also be declared as <code>http</code> or <code>HTTP</code>.

This blob type specification supports the following fields:
- **<code>url</code>** *string*
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/ocm_add_source-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ lowercase types (e.g. <code>helm</code>). See the lowercase entry for full docum

The <code>url</code> is the url pointing to the http endpoint from which a resource is
downloaded. The <code>mimeType</code> can be used to specify the MIME type of the
resource.
resource. The input type can also be declared as <code>http</code> or <code>HTTP</code>.

This blob type specification supports the following fields:
- **<code>url</code>** *string*
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/ocm_add_sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ lowercase types (e.g. <code>helm</code>). See the lowercase entry for full docum

The <code>url</code> is the url pointing to the http endpoint from which a resource is
downloaded. The <code>mimeType</code> can be used to specify the MIME type of the
resource.
resource. The input type can also be declared as <code>http</code> or <code>HTTP</code>.

This blob type specification supports the following fields:
- **<code>url</code>** *string*
Expand Down
Loading