2024-12-16 08:15:49 +01:00
package main
import (
2024-12-16 18:12:54 +01:00
"errors"
2024-12-16 08:15:49 +01:00
"os"
"os/exec"
"path"
"testing"
2024-12-16 18:12:54 +01:00
"go.uber.org/mock/gomock"
"src.opensuse.org/autogits/common/gitea-generated/models"
mock_common "src.opensuse.org/autogits/common/mock"
2024-12-16 08:15:49 +01:00
)
func TestReview ( t * testing . T ) {
cwd , _ := os . Getwd ( )
cmd := exec . Command ( "/usr/bin/bash" , path . Join ( cwd , "test_repo_setup.sh" ) )
cmd . Dir = t . TempDir ( )
if out , err := cmd . CombinedOutput ( ) ; err != nil {
t . Fatal ( string ( out ) )
}
2024-12-16 18:12:54 +01:00
tests := [ ] struct {
name string
org string
repo string
pr_no int64
pr * models . PullRequest
err error
} {
{ name : "Error fetching ReviewSet if there are missing links" , org : "test" , repo : "repo" , pr_no : 42 , pr : & models . PullRequest { Body : "" } } ,
{ name : "Error fetching ReviewSet if there are missing links" , org : "test" , repo : "repo" , pr_no : 42 , pr : & models . PullRequest { Body : "" } , err : errors . New ( "Missing PR" ) } ,
}
2024-12-16 08:15:49 +01:00
2024-12-16 18:12:54 +01:00
for _ , test := range tests {
t . Run ( test . name , func ( t * testing . T ) {
ctl := gomock . NewController ( t )
mock := mock_common . NewMockGiteaPRReviewFetcher ( ctl )
mock . EXPECT ( ) . GetPullRequestAndReviews ( test . org , test . repo , test . pr_no ) . Return ( test . pr , nil , test . err )
_ , err := FetchReviewSet ( mock , "test" , "repo" , 42 )
if test . err != nil && err == nil {
t . Fatal ( "Expected" , test . err , "but got" , err )
}
} )
}
}