mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-11-03 20:17:59 +00:00 
			
		
		
		
	* Sync up Agent and API's renewers. This introduces a new type, LifetimeWatcher, which can handle both renewable and non-renewable secrets, modeled after the version in Agent. It allows the user to select behavior, with the new style being the default when calling Start(), and old style if using the legacy Renew() call. No tests have been modified (except for reflect issues) and no other code has been modified to make sure the changes are backwards compatible. Once this is accepted I'll pull the Agent version out. * Move compat flags to NewRenewer * Port agent to shared lifetime watcher lib
		
			
				
	
	
		
			73 lines
		
	
	
		
			959 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			73 lines
		
	
	
		
			959 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package api
 | 
						|
 | 
						|
import (
 | 
						|
	"testing"
 | 
						|
 | 
						|
	"github.com/go-test/deep"
 | 
						|
)
 | 
						|
 | 
						|
func TestRenewer_NewRenewer(t *testing.T) {
 | 
						|
	t.Parallel()
 | 
						|
 | 
						|
	client, err := NewClient(DefaultConfig())
 | 
						|
	if err != nil {
 | 
						|
		t.Fatal(err)
 | 
						|
	}
 | 
						|
 | 
						|
	cases := []struct {
 | 
						|
		name string
 | 
						|
		i    *RenewerInput
 | 
						|
		e    *Renewer
 | 
						|
		err  bool
 | 
						|
	}{
 | 
						|
		{
 | 
						|
			"nil",
 | 
						|
			nil,
 | 
						|
			nil,
 | 
						|
			true,
 | 
						|
		},
 | 
						|
		{
 | 
						|
			"missing_secret",
 | 
						|
			&RenewerInput{
 | 
						|
				Secret: nil,
 | 
						|
			},
 | 
						|
			nil,
 | 
						|
			true,
 | 
						|
		},
 | 
						|
		{
 | 
						|
			"default_grace",
 | 
						|
			&RenewerInput{
 | 
						|
				Secret: &Secret{},
 | 
						|
			},
 | 
						|
			&Renewer{
 | 
						|
				secret: &Secret{},
 | 
						|
			},
 | 
						|
			false,
 | 
						|
		},
 | 
						|
	}
 | 
						|
 | 
						|
	for _, tc := range cases {
 | 
						|
		t.Run(tc.name, func(t *testing.T) {
 | 
						|
			v, err := client.NewRenewer(tc.i)
 | 
						|
			if (err != nil) != tc.err {
 | 
						|
				t.Fatal(err)
 | 
						|
			}
 | 
						|
 | 
						|
			if v == nil {
 | 
						|
				return
 | 
						|
			}
 | 
						|
 | 
						|
			// Zero-out channels because reflect
 | 
						|
			v.client = nil
 | 
						|
			v.random = nil
 | 
						|
			v.doneCh = nil
 | 
						|
			v.renewCh = nil
 | 
						|
			v.stopCh = nil
 | 
						|
 | 
						|
			if diff := deep.Equal(tc.e, v); diff != nil {
 | 
						|
				t.Error(diff)
 | 
						|
			}
 | 
						|
		})
 | 
						|
	}
 | 
						|
}
 |