package p.studio.api.automation; import org.junit.jupiter.api.Test; import java.math.BigInteger; import java.util.*; import static org.junit.jupiter.api.Assertions.*; class GuestTestsTest { GuestTests.Target target(String id) {return new GuestTests.Target(id,"tests/"+id+"/main.pbs",List.of("src","tests/"+id),List.of("tests/support"),List.of("src/main.pbs"),List.of("first","second"),41000);} @Test void twoTargetsAndOmittedProductionSelectionDoNotChangeProjectMachineIdentity() { var catalog=new GuestTests.Catalog(1,List.of(target("life"),target("shop-save"))); assertEquals(2,catalog.targets().size());assertTrue(new GuestTests.Selection(null).production());assertFalse(new GuestTests.Selection("life").production()); assertThrows(IllegalArgumentException.class,()->new GuestTests.Catalog(1,List.of(target("life"),target("life")))); assertThrows(IllegalArgumentException.class,()->target("production"));assertThrows(IllegalArgumentException.class,()->new GuestTests.Catalog(2,List.of())); assertThrows(IllegalArgumentException.class,()->new GuestTests.Target("escape","../main.pbs",List.of("src"),List.of(),List.of(),List.of(),1)); } @Test void provenanceAndSequenceZeroThroughUint64MaximumAreImmutableAndLossless() { var hashes=new HashMap();hashes.put("src/main.pbs","a".repeat(64)); var provenance=new GuestTests.BuildProvenance("life","build","tests/life/main.pbs",hashes,Map.of(),Map.of(),Map.of("target","Game"),"revision"); hashes.clear();assertEquals(1,provenance.sourceSha256().size()); var zero=new GuestTests.LogEvent(BigInteger.ZERO,BigInteger.ZERO,BigInteger.ZERO,"info","app",3L,41000,"{}"); var max=new BigInteger("18446744073709551615");var last=new GuestTests.LogEvent(max,max,max,"info","app",3L,41000,"{}"); var page=new GuestTests.LogPage("session",BigInteger.ZERO,List.of(zero),BigInteger.ZERO,BigInteger.ZERO,BigInteger.ZERO,false,false); var finalPage=new GuestTests.LogPage("session",BigInteger.ONE,List.of(last),max,max,max,true,true); assertEquals(BigInteger.ZERO,page.events().getFirst().sequence());assertEquals(max,finalPage.nextAfterSequence()); assertThrows(IllegalArgumentException.class,()->new GuestTests.LogPage("session",BigInteger.ZERO,List.of(last,zero),BigInteger.ZERO,max,max,false,false)); } @Test void everyCaseStateIsRepresentableButEmptyIncompleteOrFailedAssertionsCannotPass() { for(var state:GuestTests.CaseState.values())assertEquals(state,new GuestTests.CaseResult("case",state,List.of(),List.of()).state()); assertThrows(IllegalArgumentException.class,()->result(GuestTests.Completion.completed,false,List.of())); var passed=new GuestTests.CaseResult("case",GuestTests.CaseState.passed,List.of(new GuestTests.Assertion("health","public API",10,10,true)),List.of()); assertEquals(GuestTests.CaseState.passed,result(GuestTests.Completion.completed,true,List.of(passed)).verdict()); assertThrows(IllegalArgumentException.class,()->result(GuestTests.Completion.timed_out,true,List.of(passed))); assertThrows(IllegalArgumentException.class,()->result(GuestTests.Completion.cancelled,true,List.of(passed))); var failed=new GuestTests.CaseResult("case",GuestTests.CaseState.failed,List.of(new GuestTests.Assertion("health","mismatch",10,9,false)),List.of()); assertThrows(IllegalArgumentException.class,()->result(GuestTests.Completion.completed,true,List.of(failed))); } GuestTests.RunResult result(GuestTests.Completion completion,boolean complete,List cases) { return new GuestTests.RunResult("run","life","build","session","operation","request",completion,GuestTests.CaseState.passed,complete,false,cases,List.of(),null); } }