Skip to content

Commit

Permalink
[gosrc2cpg] - Added Download Dependency Unit Test (joernio#3884)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankit-privado authored Dec 4, 2023
1 parent 0ab1978 commit 918572b
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,48 @@ class DownloadDependencyTest extends GoCodeToCpgSuite {
e.typeFullName shouldBe "github.com/rs/zerolog/log.Warn.<ReturnType>.<unknown>"
}
}

// Note: methodFullName of call node is not resolving as per DownloadDependency so ignoring
// the below unit tests, which tries to download the dependencies and resolve it.
"dependency resolution having type struct" ignore {
val config = Config().withFetchDependencies(true)
val cpg = code(
"""
|module joern.io/sample
|go 1.18
|
|require (
| github.com/redis/go-redis/v9 v9.2.1
|)
|""".stripMargin,
"go.mod"
).moreCode("""
|package main
|import "github.com/redis/go-redis/v9"
|
|type Client struct {
| rdb redis.UniversalClient
|}
|
|func (c *Client) setValue() {
| key := "key"
| value := "value"
| err := c.rdb.Set(key, value).Err()
|}
|""".stripMargin)
.withConfig(config)

"Test basic ast structure" in {
val List(typeDeclNode) = cpg.typeDecl.nameExact("Client").l
typeDeclNode.fullName shouldBe "main.Client"
typeDeclNode.member.size shouldBe 1
typeDeclNode.member.head.typeFullName shouldBe "github.com/redis/go-redis/v9.redis.UnversalClient.<ReturnType>.<unknown>"
}

"Test call node" in {
val List(callNode) = cpg.call.name("Set").l
callNode.typeFullName shouldBe "github.com/redis/go-redis/v9.redis.UnversalClient.Set.<ReturnType>.<unknown>"
callNode.methodFullName shouldBe "github.com/redis/go-redis/v9.redis.UnversalClient.Set"
}
}
}

0 comments on commit 918572b

Please sign in to comment.