github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/pkg/github/secret_test.go (about)

     1  //go:build unit
     2  // +build unit
     3  
     4  package github
     5  
     6  import (
     7  	"encoding/base64"
     8  	"testing"
     9  
    10  	"github.com/google/go-github/v45/github"
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  func TestRunGithubCreateEncryptedSecret(t *testing.T) {
    15  	t.Parallel()
    16  
    17  	t.Run("Success", func(t *testing.T) {
    18  		mockKeyID := "1"
    19  		mockB64Key := base64.StdEncoding.EncodeToString([]byte("testPublicKey"))
    20  		mockPubKey := github.PublicKey{KeyID: &mockKeyID, Key: &mockB64Key}
    21  
    22  		mockName := "testSecret"
    23  		mockValue := "testValue"
    24  
    25  		// test
    26  		githubSecret, err := CreateEncryptedSecret(mockName, mockValue, &mockPubKey)
    27  
    28  		// assert
    29  		assert.NoError(t, err)
    30  		assert.Equal(t, mockName, githubSecret.Name)
    31  		assert.Equal(t, mockKeyID, githubSecret.KeyID)
    32  	})
    33  }