github.com/criteo/command-launcher@v0.0.0-20230407142452-fb616f546e98/cmd/consent/consent_test.go (about)

     1  package consent
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/criteo/command-launcher/internal/context"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestAccessConsents(t *testing.T) {
    11  	// TODO: we shouldn't let the secret lib depends on the context
    12  	context.InitContext("test-vault", "1.0.0", "1")
    13  
    14  	err := saveCmdConsents("dev-group", "test-cmd", []string{
    15  		"USERNAME", "PASSWORD", "LOG_LEVEL",
    16  	}, 30)
    17  
    18  	assert.Nil(t, err)
    19  
    20  	consent, err := getCmdConsents("dev-group", "test-cmd")
    21  
    22  	assert.Nil(t, err)
    23  	assert.NotNil(t, consent)
    24  	assert.Equal(t, 3, len(consent.Consents))
    25  	assert.Equal(t, "USERNAME", consent.Consents[0])
    26  	assert.Equal(t, "PASSWORD", consent.Consents[1])
    27  	assert.Equal(t, "LOG_LEVEL", consent.Consents[2])
    28  }
    29  
    30  func TestEmptyConsents(t *testing.T) {
    31  	consent, err := GetConsents("non-exist-group", "no-exist-cmd", []string{}, true)
    32  	assert.Nil(t, err)
    33  	assert.Equal(t, 0, len(consent))
    34  }