github.com/diggerhq/digger/libs@v0.0.0-20240604170430-9d61cdf01cc5/locking/locking_test.go (about)

     1  package locking
     2  
     3  import (
     4  	"github.com/diggerhq/digger/libs/comment_utils/reporting"
     5  	"github.com/diggerhq/digger/libs/orchestrator"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestLockingTwiceThrowsError(t *testing.T) {
    12  	mockDynamoDB := MockLock{MapLock: make(map[string]int)}
    13  	mockPrManager := orchestrator.MockGithubPullrequestManager{}
    14  	reporter := reporting.MockReporter{}
    15  	pl := PullRequestLock{
    16  		InternalLock:     &mockDynamoDB,
    17  		CIService:        &mockPrManager,
    18  		Reporter:         &reporter,
    19  		ProjectName:      "a",
    20  		ProjectNamespace: "",
    21  		PrNumber:         1,
    22  	}
    23  	state1, err1 := pl.Lock()
    24  	assert.True(t, state1)
    25  	assert.NoError(t, err1)
    26  
    27  	pl2 := PullRequestLock{
    28  		InternalLock:     &mockDynamoDB,
    29  		CIService:        &mockPrManager,
    30  		Reporter:         &reporter,
    31  		ProjectName:      "a",
    32  		ProjectNamespace: "",
    33  		PrNumber:         2,
    34  	}
    35  	state2, err2 := pl2.Lock()
    36  	assert.False(t, state2)
    37  	assert.Error(t, err2)
    38  }
    39  
    40  func TestGetLock(t *testing.T) {
    41  	// TODO: implement this test
    42  	lock, err := GetLock()
    43  	if err != nil {
    44  		print(err)
    45  	}
    46  	print(lock)
    47  }