@@ -97,6 +97,54 @@ void testAssertMethodAcceptsCompatibleLibraryPrefix() {
9797 subject .assertCompatibleWith (DockerImageName .parse ("foo" ));
9898 }
9999
100+ @ Test
101+ void testLibraryPrefixedImageIsNotCompatibleWithDifferentImage () {
102+ DockerImageName subject = DockerImageName .parse ("library/foo:1.2.3" );
103+
104+ assertThat (subject .isCompatibleWith (DockerImageName .parse ("bar" ))).as ("library/foo:1.2.3 != bar" ).isFalse ();
105+ assertThat (subject .isCompatibleWith (DockerImageName .parse ("repo/bar" )))
106+ .as ("library/foo:1.2.3 != repo/bar" )
107+ .isFalse ();
108+ assertThat (subject .isCompatibleWith (DockerImageName .parse ("library/bar" )))
109+ .as ("library/foo:1.2.3 != library/bar" )
110+ .isFalse ();
111+ }
112+
113+ @ Test
114+ void testLibraryPrefixIsInterchangeable () {
115+ assertThat (DockerImageName .parse ("library/foo" ).isCompatibleWith (DockerImageName .parse ("foo" )))
116+ .as ("library/foo ~= foo" )
117+ .isTrue ();
118+ assertThat (DockerImageName .parse ("foo" ).isCompatibleWith (DockerImageName .parse ("library/foo" )))
119+ .as ("foo ~= library/foo" )
120+ .isTrue ();
121+ assertThat (DockerImageName .parse ("library/foo:1.2.3" ).isCompatibleWith (DockerImageName .parse ("foo" )))
122+ .as ("library/foo:1.2.3 ~= foo" )
123+ .isTrue ();
124+ assertThat (DockerImageName .parse ("foo:1.2.3" ).isCompatibleWith (DockerImageName .parse ("library/foo" )))
125+ .as ("foo:1.2.3 ~= library/foo" )
126+ .isTrue ();
127+ assertThat (DockerImageName .parse ("library/foo:1.2.3" ).isCompatibleWith (DockerImageName .parse ("foo:1.2.3" )))
128+ .as ("library/foo:1.2.3 ~= foo:1.2.3" )
129+ .isTrue ();
130+ assertThat (DockerImageName .parse ("library/foo:1.2.3" ).isCompatibleWith (DockerImageName .parse ("foo:4.5.6" )))
131+ .as ("library/foo:1.2.3 != foo:4.5.6" )
132+ .isFalse ();
133+ assertThat (DockerImageName .parse ("some.registry/foo" ).isCompatibleWith (DockerImageName .parse ("library/foo" )))
134+ .as ("some.registry/foo != library/foo" )
135+ .isFalse ();
136+ }
137+
138+ @ Test
139+ void testLibraryPrefixedImageWithClaimedCompatibility () {
140+ DockerImageName subject = DockerImageName .parse ("library/foo:1.2.3" ).asCompatibleSubstituteFor ("bar" );
141+
142+ assertThat (subject .isCompatibleWith (DockerImageName .parse ("bar" ))).as ("library/foo:1.2.3(bar) ~= bar" ).isTrue ();
143+ assertThat (subject .isCompatibleWith (DockerImageName .parse ("fizz" )))
144+ .as ("library/foo:1.2.3(bar) != fizz" )
145+ .isFalse ();
146+ }
147+
100148 @ Test
101149 void testAssertMethodRejectsIncompatible () {
102150 DockerImageName subject = DockerImageName .parse ("foo" );
0 commit comments