forked from containers/toolbox
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/utils: Test ImageReferenceCanBeID
- Loading branch information
1 parent
781c433
commit b27b41e
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright © 2021 Red Hat Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestImageReferenceCanBeID(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
ref string | ||
ok bool | ||
}{ | ||
{ | ||
name: "Valid ID (random 6 chars)", | ||
ref: "34afbc", | ||
ok: true, | ||
}, | ||
{ | ||
name: "Valid ID (random 64 chars)", | ||
ref: "8215cb84fa588215cb84fa588215cb84fa588215cb84fa588215cb84fa58fbca", | ||
ok: true, | ||
}, | ||
{ | ||
name: "Valid ID (Podman short)", | ||
ref: "8215cb84fa58", | ||
ok: true, | ||
}, | ||
{ | ||
name: "Valid ID (Podman long)", | ||
ref: "8b9affd1dbc261a7f586ed06a8fd993d09449a5ac79ebc7e80e86efdf3c223f6", | ||
ok: true, | ||
}, | ||
{ | ||
name: "Invalid ID (random <6 chars)", | ||
ref: "acbdf", | ||
ok: false, | ||
}, | ||
{ | ||
name: "Invalid ID (random >64 chars)", | ||
ref: "8215cb84fa588215cb84fa588215cb84fa588215cb84fa588215cb84fa58fbcab", | ||
ok: false, | ||
}, | ||
{ | ||
name: "Invalid ID (image URI; whole alphabet + slash)", | ||
ref: "fedoraproject.org/fedora-toolbox:32", | ||
ok: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
ok := ImageReferenceCanBeID(tc.ref) | ||
assert.Equal(t, tc.ok, ok) | ||
}) | ||
} | ||
} |