github.com/uber/kraken@v0.1.4/lib/backend/namepath/pather_test.go (about) 1 // Copyright (c) 2016-2019 Uber Technologies, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 package namepath 15 16 import ( 17 "testing" 18 19 "github.com/stretchr/testify/require" 20 ) 21 22 func TestBlobPathConversion(t *testing.T) { 23 tests := []struct { 24 pather string 25 name string 26 expected string 27 }{ 28 { 29 DockerTag, 30 "repo-bar:latest", 31 "/root/docker/registry/v2/repositories/repo-bar/_manifests/tags/latest/current/link", 32 }, { 33 ShardedDockerBlob, 34 "ff85ceb9734a3c2fbb886e0f7cfc66b046eeeae953d8cb430dc5a7ace544b0e9", 35 "/root/docker/registry/v2/blobs/sha256/ff/ff85ceb9734a3c2fbb886e0f7cfc66b046eeeae953d8cb430dc5a7ace544b0e9/data", 36 }, { 37 Identity, 38 "foo/bar", 39 "/root/foo/bar", 40 }, 41 } 42 for _, test := range tests { 43 t.Run(test.pather, func(t *testing.T) { 44 require := require.New(t) 45 46 p, err := New("/root", test.pather) 47 require.NoError(err) 48 49 path, err := p.BlobPath(test.name) 50 require.NoError(err) 51 require.Equal(test.expected, path) 52 53 original, err := p.NameFromBlobPath(path) 54 require.NoError(err) 55 require.Equal(test.name, original) 56 }) 57 } 58 } 59 60 func TestDockerTagErrors(t *testing.T) { 61 for _, name := range []string{ 62 "4dfa0d38b99b774aabfde9a62421ac787ab168369e92421df968c7348893b60c", 63 ":", 64 "repo:", 65 ":tag", 66 } { 67 t.Run(name, func(t *testing.T) { 68 _, err := DockerTagPather{"/"}.BlobPath(name) 69 require.Error(t, err) 70 }) 71 } 72 } 73 74 func TestShardedDockerBlobErrors(t *testing.T) { 75 for _, name := range []string{ 76 "4d", 77 ":", 78 "", 79 } { 80 t.Run(name, func(t *testing.T) { 81 _, err := ShardedDockerBlobPather{"/"}.BlobPath(name) 82 require.Error(t, err) 83 }) 84 } 85 } 86 87 func TestNameFromBlobPathErrors(t *testing.T) { 88 // TODO(codyg): Write me! 89 }