diff options
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConfigTest.java')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConfigTest.java | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConfigTest.java index 6109d6cb4d..cbc1d546ac 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConfigTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017, David Pursehouse <david.pursehouse@gmail.com> and others + * Copyright (C) 2017, 2022 David Pursehouse <david.pursehouse@gmail.com> and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -14,10 +14,13 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import org.eclipse.jgit.lib.Config; +import org.eclipse.jgit.transport.PushConfig.PushDefault; import org.eclipse.jgit.transport.PushConfig.PushRecurseSubmodulesMode; import org.junit.Test; public class PushConfigTest { + @Test public void pushRecurseSubmoduleMatch() throws Exception { assertTrue(PushRecurseSubmodulesMode.CHECK.matchConfigValue("check")); @@ -52,4 +55,59 @@ public class PushConfigTest { assertEquals("check", PushRecurseSubmodulesMode.CHECK.toConfigValue()); assertEquals("false", PushRecurseSubmodulesMode.NO.toConfigValue()); } + + @Test + public void pushDefaultMatch() throws Exception { + assertTrue(PushDefault.NOTHING.matchConfigValue("nothing")); + assertTrue(PushDefault.NOTHING.matchConfigValue("NOTHING")); + assertTrue(PushDefault.CURRENT.matchConfigValue("current")); + assertTrue(PushDefault.CURRENT.matchConfigValue("CURRENT")); + assertTrue(PushDefault.UPSTREAM.matchConfigValue("upstream")); + assertTrue(PushDefault.UPSTREAM.matchConfigValue("UPSTREAM")); + assertTrue(PushDefault.UPSTREAM.matchConfigValue("tracking")); + assertTrue(PushDefault.UPSTREAM.matchConfigValue("TRACKING")); + assertTrue(PushDefault.SIMPLE.matchConfigValue("simple")); + assertTrue(PushDefault.SIMPLE.matchConfigValue("SIMPLE")); + assertTrue(PushDefault.MATCHING.matchConfigValue("matching")); + assertTrue(PushDefault.MATCHING.matchConfigValue("MATCHING")); + } + + @Test + public void pushDefaultNoMatch() throws Exception { + assertFalse(PushDefault.NOTHING.matchConfigValue("n")); + assertFalse(PushDefault.CURRENT.matchConfigValue("")); + assertFalse(PushDefault.UPSTREAM.matchConfigValue("track")); + } + + @Test + public void pushDefaultToConfigValue() throws Exception { + assertEquals("nothing", PushDefault.NOTHING.toConfigValue()); + assertEquals("current", PushDefault.CURRENT.toConfigValue()); + assertEquals("upstream", PushDefault.UPSTREAM.toConfigValue()); + assertEquals("simple", PushDefault.SIMPLE.toConfigValue()); + assertEquals("matching", PushDefault.MATCHING.toConfigValue()); + } + + @Test + public void testEmptyConfig() throws Exception { + PushConfig cfg = parse(""); + assertEquals(PushRecurseSubmodulesMode.NO, cfg.getRecurseSubmodules()); + assertEquals(PushDefault.SIMPLE, cfg.getPushDefault()); + } + + @Test + public void testConfig() throws Exception { + PushConfig cfg = parse( + "[push]\n\tdefault = tracking\n\trecurseSubmodules = on-demand\n"); + assertEquals(PushRecurseSubmodulesMode.ON_DEMAND, + cfg.getRecurseSubmodules()); + assertEquals(PushDefault.UPSTREAM, cfg.getPushDefault()); + } + + private static PushConfig parse(String content) throws Exception { + Config c = new Config(); + c.fromText(content); + return c.get(PushConfig::new); + } + } |