public void testCreateRolesIfNecessaryWithDefaultValues() { ImmutableList.Builder<Statement> statements = ImmutableList.builder(); ChefSolo solo = ChefSolo.builder().build(); solo.createRolesIfNecessary(statements); ImmutableList<Statement> statementList = statements.build(); assertTrue(statementList.isEmpty()); }
public void testCreateDatabagsIfNecessaryWithDefaultValues() { ImmutableList.Builder<Statement> statements = ImmutableList.builder(); ChefSolo solo = ChefSolo.builder().build(); solo.createDatabagsIfNecessary(statements); ImmutableList<Statement> statementList = statements.build(); assertTrue(statementList.isEmpty()); }
public void testCreateDefaultNodeConfiguration() { ImmutableList.Builder<Statement> statements = ImmutableList.builder(); ChefSolo solo = ChefSolo.builder().build(); solo.createNodeConfiguration(statements); ImmutableList<Statement> statementList = statements.build(); Statement expected = createOrOverwriteFile(ChefSolo.DEFAULT_SOLO_PATH + "/node.json", ImmutableSet.of("{\"run_list\":[]}")); assertEquals(statementList.size(), 1); assertEquals(statementList.get(0).render(OsFamily.UNIX), expected.render(OsFamily.UNIX)); }
public void testCreateNodeConfigurationWithJsonAttributes() { ImmutableList.Builder<Statement> statements = ImmutableList.builder(); ChefSolo solo = ChefSolo.builder().jsonAttributes("{\"foo\":\"bar\"}").build(); solo.createNodeConfiguration(statements); ImmutableList<Statement> statementList = statements.build(); Statement expected = createOrOverwriteFile(ChefSolo.DEFAULT_SOLO_PATH + "/node.json", ImmutableSet.of("{\"foo\":\"bar\",\"run_list\":[]}")); assertEquals(statementList.size(), 1); assertEquals(statementList.get(0).render(OsFamily.UNIX), expected.render(OsFamily.UNIX)); }
public void testCreateNodeConfigurationWithRunList() { ImmutableList.Builder<Statement> statements = ImmutableList.builder(); RunList runlist = RunList.builder().recipe("foo").role("bar").build(); ChefSolo solo = ChefSolo.builder().runlist(runlist).build(); solo.createNodeConfiguration(statements); ImmutableList<Statement> statementList = statements.build(); Statement expected = createOrOverwriteFile(ChefSolo.DEFAULT_SOLO_PATH + "/node.json", ImmutableSet.of("{\"run_list\":[\"recipe[foo]\",\"role[bar]\"]}")); assertEquals(statementList.size(), 1); assertEquals(statementList.get(0).render(OsFamily.UNIX), expected.render(OsFamily.UNIX)); }
public void testCreateDatabagsIfNecessaryWithOneDatabagAndCustomPath() { ImmutableList.Builder<Statement> statements = ImmutableList.builder(); DataBag databag = DataBag.builder().name("foo").item("item", "{\"foo\":\"bar\"}").build(); ChefSolo solo = ChefSolo.builder().dataBagPath("/tmp/databags").defineDataBag(databag).build(); solo.createDatabagsIfNecessary(statements); ImmutableList<Statement> statementList = statements.build(); Statement expected = createOrOverwriteFile("/tmp/databags/foo/item.json", ImmutableSet.of("{\"foo\":\"bar\"}")); assertEquals(statementList.size(), 3); assertEquals(statementList.get(0), exec("{md} /tmp/databags")); assertEquals(statementList.get(1), exec("{md} /tmp/databags/" + databag.getName())); assertEquals(statementList.get(2).render(OsFamily.UNIX), expected.render(OsFamily.UNIX)); }
public void testCreateNodeConfigurationWithJsonAttributesAndRunList() { ImmutableList.Builder<Statement> statements = ImmutableList.builder(); RunList runlist = RunList.builder().recipe("foo").role("bar").build(); ChefSolo solo = ChefSolo.builder().jsonAttributes("{\"foo\":\"bar\"}").runlist(runlist).build(); solo.createNodeConfiguration(statements); ImmutableList<Statement> statementList = statements.build(); Statement expected = createOrOverwriteFile(ChefSolo.DEFAULT_SOLO_PATH + "/node.json", ImmutableSet.of("{\"foo\":\"bar\",\"run_list\":[\"recipe[foo]\",\"role[bar]\"]}")); assertEquals(statementList.size(), 1); assertEquals(statementList.get(0).render(OsFamily.UNIX), expected.render(OsFamily.UNIX)); }
public void testChefWoloWithDefaultConfiguration() throws IOException { String script = ChefSolo.builder().build().render(OsFamily.UNIX); assertEquals(script, installChefGems() + createConfigFile() + createNodeFile() + "chef-solo -c /var/chef/solo.rb -j /var/chef/node.json -N `hostname`\n"); }
public void testCreateRolesIfNecessaryWithOneRoleAndCustomPath() { ImmutableList.Builder<Statement> statements = ImmutableList.builder(); RunList runlist = RunList.builder().recipe("bar").build(); Role role = Role.builder().name("foo").runlist(runlist).build(); ChefSolo solo = ChefSolo.builder().rolePath("/tmp/roles").defineRole(role).build(); solo.createRolesIfNecessary(statements); ImmutableList<Statement> statementList = statements.build(); Statement expected = createOrOverwriteFile("/tmp/roles/" + role.getName() + ".json", ImmutableSet.of(role.toJsonString())); assertEquals(statementList.size(), 2); assertEquals(statementList.get(0), exec("{md} /tmp/roles")); assertEquals(statementList.get(1).render(OsFamily.UNIX), expected.render(OsFamily.UNIX)); }
public void testChefSoloWithCookbooksLocation() throws IOException { String script = ChefSolo.builder().cookbooksArchiveLocation("/tmp/cookbooks").build().render(OsFamily.UNIX); assertEquals(script, installChefGems() + createConfigFile() + createNodeFile() + "chef-solo -c /var/chef/solo.rb -j /var/chef/node.json -N `hostname` -r /tmp/cookbooks\n"); }
public void testChefWoloWithNodeName() throws IOException { String script = ChefSolo.builder().nodeName("foo").build().render(OsFamily.UNIX); assertEquals(script, installChefGems() + createConfigFile() + createNodeFile() + "chef-solo -c /var/chef/solo.rb -j /var/chef/node.json -N foo\n"); }
public void testChefSoloWithLogFile() throws IOException { String script = ChefSolo.builder().logFile("/var/log/solo.log").build().render(OsFamily.UNIX); assertEquals(script, installChefGems() + createConfigFile() + createNodeFile() + "chef-solo -c /var/chef/solo.rb -j /var/chef/node.json -N `hostname` -L /var/log/solo.log\n"); }
public void testChefSoloWithInterval() throws IOException { String script = ChefSolo.builder().interval(15).build().render(OsFamily.UNIX); assertEquals(script, installChefGems() + createConfigFile() + createNodeFile() + "chef-solo -c /var/chef/solo.rb -j /var/chef/node.json -N `hostname` -i 15\n"); }
public void testChefSoloWithGroup() throws IOException { String script = ChefSolo.builder().group("foo").build().render(OsFamily.UNIX); assertEquals(script, installChefGems() + createConfigFile() + createNodeFile() + "chef-solo -c /var/chef/solo.rb -j /var/chef/node.json -N `hostname` -g foo\n"); }
public void testChefSoloWithSplay() throws IOException { String script = ChefSolo.builder().splay(15).build().render(OsFamily.UNIX); assertEquals(script, installChefGems() + createConfigFile() + createNodeFile() + "chef-solo -c /var/chef/solo.rb -j /var/chef/node.json -N `hostname` -s 15\n"); }
public void testChefWoloWithNodeName() throws IOException { String script = ChefSolo.builder().nodeName("foo").build().render(OsFamily.UNIX); assertEquals(script, checkSoloExists() + createConfigFile() + createNodeFile() + "chef-solo -c /var/chef/solo.rb -j /var/chef/node.json -N foo\n"); }
public void testChefSoloWithLogLevel() throws IOException { String script = ChefSolo.builder().logLevel("debug").build().render(OsFamily.UNIX); assertEquals(script, installChefGems() + createConfigFile() + createNodeFile() + "chef-solo -c /var/chef/solo.rb -j /var/chef/node.json -N `hostname` -l debug\n"); }
public void testChefSoloWithUser() throws IOException { String script = ChefSolo.builder().user("foo").build().render(OsFamily.UNIX); assertEquals(script, installChefGems() + createConfigFile() + createNodeFile() + "chef-solo -c /var/chef/solo.rb -j /var/chef/node.json -N `hostname` -u foo\n"); }
public void testChefSoloWithChefGemVersion() throws IOException { String script = ChefSolo.builder().chefVersion(">= 0.10.8").build().render(OsFamily.UNIX); assertEquals(script, installChefGems(">= 0.10.8") + createConfigFile() + createNodeFile() + "chef-solo -c /var/chef/solo.rb -j /var/chef/node.json -N `hostname`\n"); }
public void testChefSoloWithInterval() throws IOException { String script = ChefSolo.builder().interval(15).build().render(OsFamily.UNIX); assertEquals(script, checkSoloExists() + createConfigFile() + createNodeFile() + "chef-solo -c /var/chef/solo.rb -j /var/chef/node.json -N `hostname` -i 15\n"); }