Skip to content

Commit

Permalink
[chore]
Browse files Browse the repository at this point in the history
moved expected output of test in json file to neat the code.
  • Loading branch information
abmussani committed Aug 28, 2024
1 parent ca8ac04 commit 3b5b769
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 61 deletions.
59 changes: 59 additions & 0 deletions pkg/analyzer/analyzers/gitlab/expected_output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"AnalyzerType":5,
"Bindings":[
{
"Resource":{
"Name":"test-project-token",
"FullyQualifiedName":"test-project-token",
"Type":"access_token",
"Metadata":{
"created_at":"2024-08-15T06:33:00.337Z",
"expires_at":"2025-08-15",
"last_used_at":"2024-08-15T07:21:41.127Z",
"revoked":false
},
"Parent":null
},
"Permission":{
"Value":"read_api",
"Parent":null
}
},
{
"Resource":{
"Name":"test-project-token",
"FullyQualifiedName":"test-project-token",
"Type":"access_token",
"Metadata":{
"created_at":"2024-08-15T06:33:00.337Z",
"expires_at":"2025-08-15",
"last_used_at":"2024-08-15T07:21:41.127Z",
"revoked":false
},
"Parent":null
},
"Permission":{
"Value":"read_repository",
"Parent":null
}
},
{
"Resource":{
"Name":"truffletester / trufflehog",
"FullyQualifiedName":"truffletester / trufflehog",
"Type":"project",
"Metadata":null,
"Parent":null
},
"Permission":{
"Value":"Developer",
"Parent":null
}
}
],
"UnboundedResources":null,
"Metadata":{
"enterprise":true,
"version":"17.3.0-pre"
}
}
68 changes: 7 additions & 61 deletions pkg/analyzer/analyzers/gitlab/gitlab_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gitlab

import (
_ "embed"
"encoding/json"
"testing"
"time"
Expand All @@ -10,6 +11,9 @@ import (
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
)

//go:embed expected_output.json
var expectedOutput []byte

func TestAnalyzer_Analyze(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
Expand All @@ -25,67 +29,9 @@ func TestAnalyzer_Analyze(t *testing.T) {
wantErr bool
}{
{
name: "valid gitlab access token",
key: testSecrets.MustGetField("GITLABV2"),
want: `{
"AnalyzerType":5,
"Bindings":[
{
"Resource":{
"Name":"test-project-token",
"FullyQualifiedName":"test-project-token",
"Type":"access_token",
"Metadata":{
"created_at":"2024-08-15T06:33:00.337Z",
"expires_at":"2025-08-15",
"last_used_at":"2024-08-15T07:21:41.127Z",
"revoked":false
},
"Parent":null
},
"Permission":{
"Value":"read_api",
"Parent":null
}
},
{
"Resource":{
"Name":"test-project-token",
"FullyQualifiedName":"test-project-token",
"Type":"access_token",
"Metadata":{
"created_at":"2024-08-15T06:33:00.337Z",
"expires_at":"2025-08-15",
"last_used_at":"2024-08-15T07:21:41.127Z",
"revoked":false
},
"Parent":null
},
"Permission":{
"Value":"read_repository",
"Parent":null
}
},
{
"Resource":{
"Name":"truffletester / trufflehog",
"FullyQualifiedName":"truffletester / trufflehog",
"Type":"project",
"Metadata":null,
"Parent":null
},
"Permission":{
"Value":"Developer",
"Parent":null
}
}
],
"UnboundedResources":null,
"Metadata":{
"enterprise":true,
"version":"17.3.0-pre"
}
}`,
name: "valid gitlab access token",
key: testSecrets.MustGetField("GITLABV2"),
want: string(expectedOutput),
wantErr: false,
},
}
Expand Down

0 comments on commit 3b5b769

Please sign in to comment.