github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/packages/container/metadata_test.go (about) 1 // Copyright 2023 The GitBundle Inc. All rights reserved. 2 // Copyright 2017 The Gitea Authors. All rights reserved. 3 // Use of this source code is governed by a MIT-style 4 // license that can be found in the LICENSE file. 5 6 package container 7 8 import ( 9 "strings" 10 "testing" 11 12 "github.com/gitbundle/modules/packages/container/helm" 13 "github.com/gitbundle/modules/packages/container/oci" 14 15 "github.com/stretchr/testify/assert" 16 ) 17 18 func TestParseImageConfig(t *testing.T) { 19 description := "Image Description" 20 author := "GitBundle" 21 license := "MIT" 22 projectURL := "https://gitea.io" 23 repositoryURL := "https://gitea.com/gitea" 24 documentationURL := "https://docs.gitea.io" 25 26 configOCI := `{"config": {"labels": {"` + labelAuthors + `": "` + author + `", "` + labelLicenses + `": "` + license + `", "` + labelURL + `": "` + projectURL + `", "` + labelSource + `": "` + repositoryURL + `", "` + labelDocumentation + `": "` + documentationURL + `", "` + labelDescription + `": "` + description + `"}}, "history": [{"created_by": "do it 1"}, {"created_by": "dummy #(nop) do it 2"}]}` 27 28 metadata, err := ParseImageConfig(oci.MediaType(oci.MediaTypeImageManifest), strings.NewReader(configOCI)) 29 assert.NoError(t, err) 30 31 assert.Equal(t, TypeOCI, metadata.Type) 32 assert.Equal(t, description, metadata.Description) 33 assert.ElementsMatch(t, []string{author}, metadata.Authors) 34 assert.Equal(t, license, metadata.Licenses) 35 assert.Equal(t, projectURL, metadata.ProjectURL) 36 assert.Equal(t, repositoryURL, metadata.RepositoryURL) 37 assert.Equal(t, documentationURL, metadata.DocumentationURL) 38 assert.Equal(t, []string{"do it 1", "do it 2"}, metadata.ImageLayers) 39 assert.Equal( 40 t, 41 map[string]string{ 42 labelAuthors: author, 43 labelLicenses: license, 44 labelURL: projectURL, 45 labelSource: repositoryURL, 46 labelDocumentation: documentationURL, 47 labelDescription: description, 48 }, 49 metadata.Labels, 50 ) 51 assert.Empty(t, metadata.MultiArch) 52 53 configHelm := `{"description":"` + description + `", "home": "` + projectURL + `", "sources": ["` + repositoryURL + `"], "maintainers":[{"name":"` + author + `"}]}` 54 55 metadata, err = ParseImageConfig(oci.MediaType(helm.ConfigMediaType), strings.NewReader(configHelm)) 56 assert.NoError(t, err) 57 58 assert.Equal(t, TypeHelm, metadata.Type) 59 assert.Equal(t, description, metadata.Description) 60 assert.ElementsMatch(t, []string{author}, metadata.Authors) 61 assert.Equal(t, projectURL, metadata.ProjectURL) 62 assert.Equal(t, repositoryURL, metadata.RepositoryURL) 63 }