diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/alias_test.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/alias_test.go new file mode 100644 index 000000000..98f20605f --- /dev/null +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/alias_test.go @@ -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"), + ) +}) diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/cli.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/cli.go index e8e16f098..179779314 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/cli.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/cli.go @@ -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, diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/type.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/type.go index 6195b245c..0ab738700 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/type.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/type.go @@ -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 url is the url pointing to the http endpoint from which a resource is downloaded. The mimeType can be used to specify the MIME type of the -resource. +resource. The input type can also be declared as http or HTTP. This blob type specification supports the following fields: - **url** *string* diff --git a/docs/reference/ocm_add_resource-configuration.md b/docs/reference/ocm_add_resource-configuration.md index 407b9a0c0..791939459 100644 --- a/docs/reference/ocm_add_resource-configuration.md +++ b/docs/reference/ocm_add_resource-configuration.md @@ -590,7 +590,7 @@ lowercase types (e.g. helm). See the lowercase entry for full docum The url is the url pointing to the http endpoint from which a resource is downloaded. The mimeType can be used to specify the MIME type of the - resource. + resource. The input type can also be declared as http or HTTP. This blob type specification supports the following fields: - **url** *string* diff --git a/docs/reference/ocm_add_resources.md b/docs/reference/ocm_add_resources.md index eb2bdaa8a..54922b14a 100644 --- a/docs/reference/ocm_add_resources.md +++ b/docs/reference/ocm_add_resources.md @@ -602,7 +602,7 @@ lowercase types (e.g. helm). See the lowercase entry for full docum The url is the url pointing to the http endpoint from which a resource is downloaded. The mimeType can be used to specify the MIME type of the - resource. + resource. The input type can also be declared as http or HTTP. This blob type specification supports the following fields: - **url** *string* diff --git a/docs/reference/ocm_add_source-configuration.md b/docs/reference/ocm_add_source-configuration.md index 0ecdaa481..fa213cb00 100644 --- a/docs/reference/ocm_add_source-configuration.md +++ b/docs/reference/ocm_add_source-configuration.md @@ -590,7 +590,7 @@ lowercase types (e.g. helm). See the lowercase entry for full docum The url is the url pointing to the http endpoint from which a resource is downloaded. The mimeType can be used to specify the MIME type of the - resource. + resource. The input type can also be declared as http or HTTP. This blob type specification supports the following fields: - **url** *string* diff --git a/docs/reference/ocm_add_sources.md b/docs/reference/ocm_add_sources.md index 1f49c5601..54418142a 100644 --- a/docs/reference/ocm_add_sources.md +++ b/docs/reference/ocm_add_sources.md @@ -600,7 +600,7 @@ lowercase types (e.g. helm). See the lowercase entry for full docum The url is the url pointing to the http endpoint from which a resource is downloaded. The mimeType can be used to specify the MIME type of the - resource. + resource. The input type can also be declared as http or HTTP. This blob type specification supports the following fields: - **url** *string*