public void TestBuilder_workingDirectory() { ContainerConfiguration configuration = ContainerConfiguration.CreateBuilder().SetWorkingDirectory(AbsoluteUnixPath.Get("/path")).Build(); Assert.AreEqual(AbsoluteUnixPath.Get("/path"), configuration.GetWorkingDirectory()); }
public void TestBuilder_environmentMapTypes() { // Can accept empty environment. ContainerConfiguration.CreateBuilder().SetEnvironment(ImmutableDictionary.Create <string, string>()).Build(); // Can handle other map types (https://github.com/GoogleContainerTools/fib/issues/632) ContainerConfiguration.CreateBuilder().SetEnvironment(new SortedDictionary <string, string>()); }
public void TestBuilder_nullValues() { // Java arguments element should not be null. try { ContainerConfiguration.CreateBuilder().SetProgramArguments(new[] { "first", null }); Assert.Fail("The IllegalArgumentException should be thrown."); } catch (ArgumentException ex) { Assert.That(ex.Message, Contains.Substring(Resources.NullProgramArgument)); } // Entrypoint element should not be null. try { ContainerConfiguration.CreateBuilder().SetEntrypoint(new[] { "first", null }); Assert.Fail("The IllegalArgumentException should be thrown."); } catch (ArgumentException ex) { Assert.That(ex.Message, Contains.Substring(Resources.NullEntrypointArgument)); } // Exposed ports element should not be null. ISet <Port> badPorts = new HashSet <Port> { Port.Tcp(1000), null }; try { ContainerConfiguration.CreateBuilder().SetExposedPorts(badPorts); Assert.Fail("The IllegalArgumentException should be thrown."); } catch (ArgumentException ex) { Assert.That(ex.Message, Contains.Substring(Resources.NullPort)); } // Volume element should not be null. ISet <AbsoluteUnixPath> badVolumes = new HashSet <AbsoluteUnixPath> { AbsoluteUnixPath.Get("/"), null }; try { ContainerConfiguration.CreateBuilder().SetVolumes(badVolumes); Assert.Fail("The IllegalArgumentException should be thrown."); } catch (ArgumentException ex) { Assert.That(ex.Message, Contains.Substring(Resources.NullVolume)); } }
public void TestBuilder() { const string expectedBaseImageServerUrl = "someserver"; const string expectedBaseImageName = "baseimage"; const string expectedBaseImageTag = "baseimagetag"; const string expectedTargetServerUrl = "someotherserver"; const string expectedTargetImageName = "targetimage"; const string expectedTargetTag = "targettag"; ISet <string> additionalTargetImageTags = ImmutableHashSet.Create("tag1", "tag2", "tag3"); ISet <string> expectedTargetImageTags = ImmutableHashSet.Create("targettag", "tag1", "tag2", "tag3"); IList <CredentialRetriever> credentialRetrievers = new List <CredentialRetriever> { () => Maybe.Of(Credential.From("username", "password")) }; Instant expectedCreationTime = Instant.FromUnixTimeSeconds(10000); IList <string> expectedEntrypoint = new[] { "some", "entrypoint" }; IList <string> expectedProgramArguments = new[] { "arg1", "arg2" }; IDictionary <string, string> expectedEnvironment = ImmutableDic.Of("key", "value"); ImmutableHashSet <Port> expectedExposedPorts = ImmutableHashSet.Create(Port.Tcp(1000), Port.Tcp(2000)); IDictionary <string, string> expectedLabels = ImmutableDic.Of("key1", "value1", "key2", "value2"); const ManifestFormat expectedTargetFormat = ManifestFormat.OCI; SystemPath expectedApplicationLayersCacheDirectory = Paths.Get("application/layers"); SystemPath expectedBaseImageLayersCacheDirectory = Paths.Get("base/image/layers"); IList <ILayerConfiguration> expectedLayerConfigurations = new List <ILayerConfiguration> { LayerConfiguration.CreateBuilder() .AddEntry(Paths.Get("sourceFile"), AbsoluteUnixPath.Get("/path/in/container")) .Build() }; const string expectedCreatedBy = "createdBy"; ImageConfiguration baseImageConfiguration = ImageConfiguration.CreateBuilder( ImageReference.Of( expectedBaseImageServerUrl, expectedBaseImageName, expectedBaseImageTag)) .Build(); ImageConfiguration targetImageConfiguration = ImageConfiguration.CreateBuilder( ImageReference.Of( expectedTargetServerUrl, expectedTargetImageName, expectedTargetTag)) .SetCredentialRetrievers(credentialRetrievers) .Build(); ContainerConfiguration containerConfiguration = ContainerConfiguration.CreateBuilder() .SetCreationTime(expectedCreationTime) .SetEntrypoint(expectedEntrypoint) .SetProgramArguments(expectedProgramArguments) .SetEnvironment(expectedEnvironment) .SetExposedPorts(expectedExposedPorts) .SetLabels(expectedLabels) .Build(); BuildConfiguration.Builder buildConfigurationBuilder = BuildConfiguration.CreateBuilder() .SetBaseImageConfiguration(baseImageConfiguration) .SetTargetImageConfiguration(targetImageConfiguration) .SetAdditionalTargetImageTags(additionalTargetImageTags) .SetContainerConfiguration(containerConfiguration) .SetApplicationLayersCacheDirectory(expectedApplicationLayersCacheDirectory) .SetBaseImageLayersCacheDirectory(expectedBaseImageLayersCacheDirectory) .SetTargetFormat(ImageFormat.OCI) .SetAllowInsecureRegistries(true) .SetLayerConfigurations(expectedLayerConfigurations) .SetToolName(expectedCreatedBy); BuildConfiguration buildConfiguration = buildConfigurationBuilder.Build(); Assert.IsNotNull(buildConfiguration.GetContainerConfiguration()); Assert.AreEqual( expectedCreationTime, buildConfiguration.GetContainerConfiguration().GetCreationTime()); Assert.AreEqual( expectedBaseImageServerUrl, buildConfiguration.GetBaseImageConfiguration().GetImageRegistry()); Assert.AreEqual( expectedBaseImageName, buildConfiguration.GetBaseImageConfiguration().GetImageRepository()); Assert.AreEqual( expectedBaseImageTag, buildConfiguration.GetBaseImageConfiguration().GetImageTag()); Assert.AreEqual( expectedTargetServerUrl, buildConfiguration.GetTargetImageConfiguration().GetImageRegistry()); Assert.AreEqual( expectedTargetImageName, buildConfiguration.GetTargetImageConfiguration().GetImageRepository()); Assert.AreEqual( expectedTargetTag, buildConfiguration.GetTargetImageConfiguration().GetImageTag()); Assert.AreEqual(expectedTargetImageTags, buildConfiguration.GetAllTargetImageTags()); Assert.AreEqual( Credential.From("username", "password"), buildConfiguration .GetTargetImageConfiguration() .GetCredentialRetrievers() [0] .Retrieve() .OrElseThrow(() => new AssertionException(""))); Assert.AreEqual( expectedProgramArguments, buildConfiguration.GetContainerConfiguration().GetProgramArguments()); Assert.AreEqual( expectedEnvironment, buildConfiguration.GetContainerConfiguration().GetEnvironmentMap()); Assert.AreEqual( expectedExposedPorts, buildConfiguration.GetContainerConfiguration().GetExposedPorts()); Assert.AreEqual(expectedLabels, buildConfiguration.GetContainerConfiguration().GetLabels()); Assert.AreEqual(expectedTargetFormat, buildConfiguration.GetTargetFormat()); Assert.AreEqual( expectedApplicationLayersCacheDirectory, buildConfigurationBuilder.GetApplicationLayersCacheDirectory()); Assert.AreEqual( expectedBaseImageLayersCacheDirectory, buildConfigurationBuilder.GetBaseImageLayersCacheDirectory()); Assert.IsTrue(buildConfiguration.GetAllowInsecureRegistries()); Assert.AreEqual(expectedLayerConfigurations, buildConfiguration.GetLayerConfigurations()); Assert.AreEqual( expectedEntrypoint, buildConfiguration.GetContainerConfiguration().GetEntrypoint()); Assert.AreEqual(expectedCreatedBy, buildConfiguration.GetToolName()); }
public void TestBuilder_user() { ContainerConfiguration configuration = ContainerConfiguration.CreateBuilder().SetUser("john").Build(); Assert.AreEqual("john", configuration.GetUser()); }