Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(analyzer): Add a test for dangling embed directives / GoMod #7647

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
project:
id: "GoMod::gomod_dangling_embed:<REPLACE_REVISION>"
definition_file_path: "analyzer/src/funTest/assets/projects/synthetic/gomod-dangling-embed/go.mod"
declared_licenses: []
declared_licenses_processed: {}
vcs:
type: "Git"
url: "<REPLACE_URL_PROCESSED>"
revision: "<REPLACE_REVISION>"
path: "<REPLACE_PATH>"
vcs_processed:
type: "Git"
url: "<REPLACE_URL_PROCESSED>"
revision: "<REPLACE_REVISION>"
path: "<REPLACE_PATH>"
homepage_url: ""
scopes:
- name: "main"
dependencies: []
- name: "vendor"
dependencies: []
packages: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module gomod_dangling_embed

go 1.19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this also be 1.21.1?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why exactly should it be? (As-is it is consistent with the other test cases in GoModFunTest).

One aspect of the bug fix is in the tooling of version 1.21, but that tooling can be used with 1.19 projects, so I do not see an issue here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One aspect of the bug fix is in the tooling of version 1.21, but that tooling can be used with 1.19 projects

That was the missing piece of information for me here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the missing piece of information for me here.

Ok, so are we good to go?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that regard yes, but I does not make sense for me to approve before the commit message is fixed.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
_ "embed"
"fmt"
)

//go:generate touch file.txt
var(
//go:embed file.txt
file string
)

func main() {
fmt.Println(file)
fmt.Println("hello world")
}
9 changes: 9 additions & 0 deletions analyzer/src/funTest/kotlin/managers/GoModFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,13 @@ class GoModFunTest : StringSpec({

result.toYaml() should matchExpectedResult(expectedResultFile, definitionFile)
}

"Source files with dangling embed directives do not yield issues" {
val definitionFile = testDir.resolve("gomod-dangling-embed/go.mod")
val expectedResultFile = testDir.resolve("gomod-dangling-embed-expected-output.yml")

val result = create("GoMod").resolveSingleProject(definitionFile)

result.toYaml() should matchExpectedResult(expectedResultFile, definitionFile)
}
})
2 changes: 1 addition & 1 deletion analyzer/src/main/kotlin/managers/GoMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@

override fun transformVersion(output: String) = output.removePrefix("go version go").substringBefore(' ')

override fun getVersionRequirement(): RangesList = RangesListFactory.create(">=1.19.0")
override fun getVersionRequirement(): RangesList = RangesListFactory.create(">=1.21.1")

Check warning on line 103 in analyzer/src/main/kotlin/managers/GoMod.kt

View check run for this annotation

Codecov / codecov/patch

analyzer/src/main/kotlin/managers/GoMod.kt#L103

Added line #L103 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit message:

  • "this projects" -> "the projects"


override fun mapDefinitionFiles(definitionFiles: List<File>): List<File> =
definitionFiles.filterNot { definitionFile ->
Expand Down