Skip to content

Commit

Permalink
update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahrav committed Feb 9, 2024
1 parent e515eb1 commit 1475990
Show file tree
Hide file tree
Showing 2 changed files with 205 additions and 34 deletions.
6 changes: 3 additions & 3 deletions pkg/gitparse/gitparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, diffChan chan
latestState = CommitLine

// If there is a currentDiff, add it to currentCommit.
if currentDiff.Len() > 0 || currentDiff.IsBinary {
if currentDiff.Commit.Hash != "" || currentDiff.IsBinary {
if err := currentDiff.finalize(); err != nil {
ctx.Logger().Error(
err,
Expand Down Expand Up @@ -436,7 +436,7 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, diffChan chan
if currentCommit == nil {
currentCommit = &Commit{}
}
if currentDiff.Len() > 0 || currentDiff.IsBinary {
if currentDiff.Commit.Hash != "" || currentDiff.IsBinary {
if err := currentDiff.finalize(); err != nil {
ctx.Logger().Error(err,
"failed to finalize diff",
Expand Down Expand Up @@ -475,7 +475,7 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, diffChan chan
case isHunkLineNumberLine(latestState, line):
latestState = HunkLineNumberLine

if currentDiff.Len() > 0 || currentDiff.IsBinary {
if currentDiff.Commit.Hash != "" || currentDiff.IsBinary {
if err := currentDiff.finalize(); err != nil {
ctx.Logger().Error(
err,
Expand Down
233 changes: 202 additions & 31 deletions pkg/gitparse/gitparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ func TestCommitParsing(t *testing.T) {
}

if !diff.Equal(context.Background(), expected[i]) {
t.Errorf("Diff does not match.\nexpected: %+v\n%s\nactual : %+v\n%s", expected[i], expected[i].Commit.Message.String(), diff, diff.Commit.Message.String())
t.Errorf("Diff does not match.\nexpected: %+v\n%s\nactual : %+v\n%s", expected[i], expected[i].Commit.Hash, diff, diff.Commit.Hash)
}
i++
}
Expand Down Expand Up @@ -1538,42 +1538,105 @@ index 0000000..5af88a8
+The door of all subtleties!
`

func newTime(timestamp string) time.Time {
date, _ := time.Parse(defaultDateFormat, timestamp)
return date
}

func newStringBuilderValue(value string) strings.Builder {
builder := strings.Builder{}
builder.Write([]byte(value))
return builder
}

// This throws a nasty panic if it's a top-level var.
func expectedDiffs() []*Diff {
return []*Diff{
{
PathB: "components/item.lua",
LineStart: 9,
PathB: "components/item.lua",
LineStart: 9,
Commit: &Commit{
Hash: "fd6e99e7a80199b76a694603be57c5ade1de18e7",
Author: "Jaliborc <[email protected]>",
Date: newTime("Mon Apr 25 16:28:06 2011 +0100"),
Message: newStringBuilderValue("Added Unusable coloring\n"),
},
contentWriter: newBufferWithContent([]byte("\n\nlocal Unfit = LibStub('Unfit-1.0')\n\n\n")),
IsBinary: false,
},
{
PathB: "embeds.xml",
LineStart: 6,
contentWriter: newBufferWithContent([]byte("\n\n <Script file=\"libs\\Unfit-1.0\\Unfit-1.0.lua\"/>\n\n\n\n")),
IsBinary: false,
Commit: &Commit{
Hash: "fd6e99e7a80199b76a694603be57c5ade1de18e7",
Author: "Jaliborc <[email protected]>",
Date: newTime("Mon Apr 25 16:28:06 2011 +0100"),
Message: newStringBuilderValue("Added Unusable coloring\n"),
},
IsBinary: false,
},
{
PathB: "libs/Unfit-1.0",
LineStart: 1,
contentWriter: newBufferWithContent([]byte("Subproject commit 0000000000000000000000000000000000000000\n")),
IsBinary: false,
Commit: &Commit{
Hash: "fd6e99e7a80199b76a694603be57c5ade1de18e7",
Author: "Jaliborc <[email protected]>",
Date: newTime("Mon Apr 25 16:28:06 2011 +0100"),
Message: newStringBuilderValue("Added Unusable coloring\n"),
},
IsBinary: false,
},
{
Commit: &Commit{
Hash: "4727ffb7ad6dc5130bf4b4dd166e00705abdd018",
Author: "John Smith <[email protected]>",
Date: newTime("Tue Jul 11 22:26:11 2023 -0400"),
Message: strings.Builder{},
},
},
{
Commit: &Commit{
Hash: "c904e0f5cd9f30ae520c66bd5f70806219fe7ca2",
Author: "John Smith <[email protected]>",
Date: newTime("Mon Jul 10 10:17:11 2023 -0400"),
Message: newStringBuilderValue("Empty Commit\n"),
},
},
{
PathB: "sample.txt",
LineStart: 1,
contentWriter: newBufferWithContent([]byte("Hello, world!\n")),
IsBinary: false,
Commit: &Commit{
Hash: "3d76a97faad96e0f326afb61c232b9c2a18dca35",
Author: "John Smith <[email protected]>",
Date: newTime("Tue Jul 11 18:03:54 2023 -0400"),
Message: strings.Builder{},
},
IsBinary: false,
},
{
PathB: ".gitignore",
LineStart: 1,
contentWriter: newBufferWithContent([]byte("\n\n\n**/__pycache__/\n**/*.pyc\n")),
IsBinary: false,
Commit: &Commit{
Hash: "df393b4125c2aa217211b2429b8963d0cefcee27",
Author: "Stephen <[email protected]>",
Date: newTime("Wed Dec 06 14:44:41 2017 -0800"),
Message: newStringBuilderValue("Add travis testing\n"),
},
IsBinary: false,
},
{
PathB: ".travis.yml",
LineStart: 1,
Commit: &Commit{
Hash: "df393b4125c2aa217211b2429b8963d0cefcee27",
Author: "Stephen <[email protected]>",
Date: newTime("Wed Dec 06 14:44:41 2017 -0800"),
Message: newStringBuilderValue("Add travis testing\n"),
},
contentWriter: newBufferWithContent([]byte(`language: python
python:
- "2.6"
Expand All @@ -1593,6 +1656,12 @@ python:
{
PathB: "Makefile",
LineStart: 1,
Commit: &Commit{
Hash: "4218c39d99b5f30153f62471c1be1c1596f0a4d4",
Author: "Dustin Decker <[email protected]>",
Date: newTime("Thu Jan 13 12:02:24 2022 -0800"),
Message: newStringBuilderValue("Initial CLI w/ partially implemented Git source and demo detector (#1)\n"),
},
contentWriter: newBufferWithContent([]byte(`PROTOS_IMAGE=us-docker.pkg.dev/thog-artifacts/public/go-ci-1.17-1
.PHONY: check
Expand Down Expand Up @@ -1629,79 +1698,181 @@ protos:
IsBinary: false,
},
{
PathB: "plusLine.txt",
LineStart: 1,
PathB: "plusLine.txt",
LineStart: 1,
Commit: &Commit{
Hash: "934cf5d255fd8e28b33f5a6ba64276caf0b284bf",
Author: "John Smith <[email protected]>",
Date: newTime("Tue Jul 11 18:43:22 2023 -0400"),
Message: newStringBuilderValue("Test toFile/plusLine parsing\n"),
},
contentWriter: newBufferWithContent([]byte("-- test\n++ test\n\n")),
IsBinary: false,
},
{
PathB: "extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/BackChannelLogoutTokenCache.java",
LineStart: 45,
PathB: "extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/BackChannelLogoutTokenCache.java",
LineStart: 45,
Commit: &Commit{
Hash: "2a5d703b02b52d65c65ee9f7928f158b919ab741",
Author: "Sergey Beryozkin <[email protected]>",
Date: newTime("Fri Jul 7 17:44:26 2023 +0100"),
Message: newStringBuilderValue("Do not refresh OIDC session if the user is requesting logout\n"),
},
contentWriter: newBufferWithContent([]byte("\n\n public boolean containsTokenVerification(String token) {\n return cacheMap.containsKey(token);\n }\n\n\n\n\n")),
IsBinary: false,
},
{
PathB: "extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/CodeAuthenticationMechanism.java",
LineStart: 1023,
PathB: "extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/CodeAuthenticationMechanism.java",
LineStart: 1023,
Commit: &Commit{
Hash: "2a5d703b02b52d65c65ee9f7928f158b919ab741",
Author: "Sergey Beryozkin <[email protected]>",
Date: newTime("Fri Jul 7 17:44:26 2023 +0100"),
Message: newStringBuilderValue("Do not refresh OIDC session if the user is requesting logout\n"),
},
contentWriter: newBufferWithContent([]byte("\n\n private boolean isRpInitiatedLogout(RoutingContext context, TenantConfigContext configContext) {\n\n\n")),
IsBinary: false,
},
{
PathB: "extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/CodeAuthenticationMechanism.java",
LineStart: 1214,
PathB: "extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/CodeAuthenticationMechanism.java",
LineStart: 1214,
Commit: &Commit{
Hash: "2a5d703b02b52d65c65ee9f7928f158b919ab741",
Author: "Sergey Beryozkin <[email protected]>",
Date: newTime("Fri Jul 7 17:44:26 2023 +0100"),
Message: newStringBuilderValue("Do not refresh OIDC session if the user is requesting logout\n"),
},
contentWriter: newBufferWithContent([]byte("\n\n\n\n private class LogoutCall implements Function<SecurityIdentity, Uni<?>> {\n RoutingContext context;\n TenantConfigContext configContext;\n String idToken;\n\n LogoutCall(RoutingContext context, TenantConfigContext configContext, String idToken) {\n this.context = context;\n this.configContext = configContext;\n this.idToken = idToken;\n }\n\n @Override\n public Uni<Void> apply(SecurityIdentity identity) {\n if (isRpInitiatedLogout(context, configContext)) {\n LOG.debug(\"Performing an RP initiated logout\");\n fireEvent(SecurityEvent.Type.OIDC_LOGOUT_RP_INITIATED, identity);\n return buildLogoutRedirectUriUni(context, configContext, idToken);\n }\n if (isBackChannelLogoutPendingAndValid(configContext, identity)\n || isFrontChannelLogoutValid(context, configContext,\n identity)) {\n return removeSessionCookie(context, configContext.oidcConfig)\n .map(new Function<Void, Void>() {\n @Override\n public Void apply(Void t) {\n throw new LogoutException();\n }\n });\n\n }\n return VOID_UNI;\n }\n }\n\n")),
IsBinary: false,
},
{
PathB: "integration-tests/oidc-wiremock/src/main/resources/application.properties",
LineStart: 20,
PathB: "integration-tests/oidc-wiremock/src/main/resources/application.properties",
LineStart: 20,
Commit: &Commit{
Hash: "2a5d703b02b52d65c65ee9f7928f158b919ab741",
Author: "Sergey Beryozkin <[email protected]>",
Date: newTime("Fri Jul 7 17:44:26 2023 +0100"),
Message: newStringBuilderValue("Do not refresh OIDC session if the user is requesting logout\n"),
},
contentWriter: newBufferWithContent([]byte("\n\n\nquarkus.oidc.code-flow.token.refresh-expired=true\nquarkus.oidc.code-flow.token.refresh-token-time-skew=5M\n\n\n")),
IsBinary: false,
},
// WTF, shouldn't this be filtered out?
{
PathB: "integration-tests/oidc-wiremock/src/test/java/io/quarkus/it/keycloak/CodeFlowAuthorizationTest.java",
LineStart: 6,
PathB: "integration-tests/oidc-wiremock/src/test/java/io/quarkus/it/keycloak/CodeFlowAuthorizationTest.java",
LineStart: 6,
Commit: &Commit{
Hash: "2a5d703b02b52d65c65ee9f7928f158b919ab741",
Author: "Sergey Beryozkin <[email protected]>",
Date: newTime("Fri Jul 7 17:44:26 2023 +0100"),
Message: newStringBuilderValue("Do not refresh OIDC session if the user is requesting logout\n"),
},
contentWriter: newBufferWithContent([]byte("\n\n\n\n\n\n")),
IsBinary: false,
},
{
PathB: "integration-tests/oidc-wiremock/src/test/java/io/quarkus/it/keycloak/CodeFlowAuthorizationTest.java",
LineStart: 76,
PathB: "integration-tests/oidc-wiremock/src/test/java/io/quarkus/it/keycloak/CodeFlowAuthorizationTest.java",
LineStart: 76,
Commit: &Commit{
Hash: "2a5d703b02b52d65c65ee9f7928f158b919ab741",
Author: "Sergey Beryozkin <[email protected]>",
Date: newTime("Fri Jul 7 17:44:26 2023 +0100"),
Message: newStringBuilderValue("Do not refresh OIDC session if the user is requesting logout\n"),
},
contentWriter: newBufferWithContent([]byte("\n\n // Logout\n\n\n\n")),
IsBinary: false,
},
{
PathB: "core/runtime/src/main/java/io/quarkus/runtime/QuarkusApplication.java",
LineStart: 3,
PathB: "core/runtime/src/main/java/io/quarkus/runtime/QuarkusApplication.java",
LineStart: 3,
Commit: &Commit{
Hash: "2a057632d7f5fa3d1c77b9aa037263211c0e0290",
Author: "rjtmahinay <[email protected]>",
Date: newTime("Mon Jul 10 01:22:32 2023 +0800"),
Message: newStringBuilderValue("Add QuarkusApplication javadoc\n\n* Fix #34463\n"),
},
contentWriter: newBufferWithContent([]byte("/**\n * This is usually used for command mode applications with a startup logic. The logic is executed inside\n * {@link QuarkusApplication#run} method before the main application exits.\n */\n")),
IsBinary: false,
},
{
PathB: "trufflehog_3.42.0_linux_arm64.tar.gz",
Commit: &Commit{
Hash: "bca2d17491015ea1522f34517223b5a366aea73c",
Author: "John Smith <[email protected]>",
Date: newTime("Tue Jul 11 18:12:21 2023 -0400"),
Message: newStringBuilderValue("Delete binary file\n"),
},
},
{
PathB: "trufflehog_3.42.0_linux_arm64.tar.gz",
Commit: &Commit{
Hash: "afc6dc5d47f28366638da877ecb6b819c69e659b",
Author: "John Smith <[email protected]>",
Date: newTime("Mon Jul 10 12:21:33 2023 -0400"),
Message: newStringBuilderValue("Change binary file\n"),
},
contentWriter: newBufferWithContent([]byte("")),
IsBinary: true,
},
{
PathB: "trufflehog_3.42.0_linux_arm64.tar.gz",
PathB: "trufflehog_3.42.0_linux_arm64.tar.gz",
Commit: &Commit{
Hash: "638595917417c5c8a956937b28c5127719023363",
Author: "John Smith <[email protected]>",
Date: newTime("Mon Jul 10 12:20:35 2023 -0400"),
Message: newStringBuilderValue("Add binary file\n"),
},
contentWriter: newBufferWithContent([]byte("")),
IsBinary: true,
},
{
PathB: "tzu",
LineStart: 11,
Commit: &Commit{
Hash: "ce0f5d1fe0272f180ccb660196f439c0c2f4ec8e",
Author: "John Smith <[email protected]>",
Date: newTime("Tue Jul 11 18:08:52 2023 -0400"),
Message: newStringBuilderValue("Delete file\n"),
},
},
{
Commit: &Commit{
Hash: "d606a729383371558473b70a6a7b1ca264b0d205",
Author: "John Smith <[email protected]>",
Date: newTime("Mon Jul 10 14:17:04 2023 -0400"),
Message: newStringBuilderValue("Rename file\n"),
},
},
{
PathB: "tzu",
LineStart: 11,
Commit: &Commit{
Hash: "7bd16429f1f708746dabf970e54b05d2b4734997",
Author: "John Smith <[email protected]>",
Date: newTime("Tue Jul 11 18:10:49 2023 -0400"),
Message: newStringBuilderValue("Change file\n"),
},
contentWriter: newBufferWithContent([]byte("\n\n\n\nSource: https://www.gnu.org/software/diffutils/manual/diffutils.html#An-Example-of-Unified-Format\n")),
IsBinary: false,
},
{
PathB: "lao",
LineStart: 1,
PathB: "lao",
LineStart: 1,
Commit: &Commit{
Hash: "c7062674c17192caa284615ab2fa9778c6602164",
Author: "John Smith <[email protected]>",
Date: newTime("Mon Jul 10 10:15:18 2023 -0400"),
Message: newStringBuilderValue("Create files\n"),
},
contentWriter: newBufferWithContent([]byte("The Way that can be told of is not the eternal Way;\nThe name that can be named is not the eternal name.\nThe Nameless is the origin of Heaven and Earth;\nThe Named is the mother of all things.\nTherefore let there always be non-being,\n so we may see their subtlety,\nAnd let there always be being,\n so we may see their outcome.\nThe two are the same,\nBut after they are produced,\n they have different names.\n")),
IsBinary: false,
},
{
PathB: "tzu",
LineStart: 1,
PathB: "tzu",
LineStart: 1,
Commit: &Commit{
Hash: "c7062674c17192caa284615ab2fa9778c6602164",
Author: "John Smith <[email protected]>",
Date: newTime("Mon Jul 10 10:15:18 2023 -0400"),
Message: newStringBuilderValue("Create files\n"),
},
contentWriter: newBufferWithContent([]byte("The Nameless is the origin of Heaven and Earth;\nThe named is the mother of all things.\n\nTherefore let there always be non-being,\n so we may see their subtlety,\nAnd let there always be being,\n so we may see their outcome.\nThe two are the same,\nBut after they are produced,\n they have different names.\nThey both may be called deep and profound.\nDeeper and more profound,\nThe door of all subtleties!\n")),
IsBinary: false,
},
Expand Down

0 comments on commit 1475990

Please sign in to comment.