func (s) TestStoreWithSingleProviderWithoutSharing(t *testing.T) {
	prov1, fp1 := makeProvider(t, fakeProvider1Name, fakeConfig+"1111")
	prov2, fp2 := makeProvider(t, fakeProvider1Name, fakeConfig+"2222")

	// Push the same key materials into the two providers.
	wantKM, err := loadKeyMaterials()
	if err != nil {
		t.Fatal(err)
	}
	fp1.kmCh <- wantKM
	fp2.kmCh <- wantKM

	// Get key materials from the fake provider1 and compare it to the ones we
	// pushed above.
	ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
	defer cancel()
	gotKM, err := prov1.KeyMaterial(ctx)
	if err != nil {
		t.Fatalf("provider.KeyMaterial() = %v", err)
	}
	if !reflect.DeepEqual(gotKM, wantKM) {
		t.Fatalf("provider.KeyMaterial() = %+v, want %+v", gotKM, wantKM)
	}

	// Get key materials from the fake provider2 and compare it to the ones we
	// pushed above.
	gotKM, err = prov2.KeyMaterial(ctx)
	if err != nil {
		t.Fatalf("provider.KeyMaterial() = %v", err)
	}
	if !reflect.DeepEqual(gotKM, wantKM) {
		t.Fatalf("provider.KeyMaterial() = %+v, want %+v", gotKM, wantKM)
	}

	// Update the key materials used by provider1, and make sure provider2 is
	// not affected.
	newKM, err := loadKeyMaterials()
	if err != nil {
		t.Fatal(err)
	}
	newKM.Roots = nil
	fp1.kmCh <- newKM

	gotKM, err = prov2.KeyMaterial(ctx)
	if err != nil {
		t.Fatalf("provider.KeyMaterial() = %v", err)
	}
	if !reflect.DeepEqual(gotKM, wantKM) {
		t.Fatalf("provider.KeyMaterial() = %+v, want %+v", gotKM, wantKM)
	}

	// Close the provider1 and retry the KeyMaterial() call on prov2, and expect
	// it to succeed.
	prov1.Close()
	if _, err := prov2.KeyMaterial(ctx); err != nil {
		t.Fatalf("provider.KeyMaterial() = %v", err)
	}

	prov2.Close()
	if _, err := prov2.KeyMaterial(ctx); err != errProviderClosed {
		t.Fatalf("provider.KeyMaterial() = %v, wantErr: %v", err, errProviderClosed)
	}
}
// TestStoreWithSingleProviderWithoutSharing creates multiple instances of the
// same type of provider through the store with different configs. The store
// would end up creating different provider instances for these and no sharing
// would take place.
TestStoreWithSingleProviderWithoutSharing creates multiple instances of the
same type of provider through the store with different configs. The store
would end up creating different provider instances for these and no sharing
would take place.
// TestStoreWithSingleProviderWithoutSharing creates multiple instances of the // same type of provider through the store with different configs . The store // would end up creating different provider instances for these and no sharing // would take place .
func (s) TestStoreWithSingleProviderWithoutSharing(t *testing.T) {
	prov1, fp1 := makeProvider(t, fakeProvider1Name, fakeConfig+"1111")
	prov2, fp2 := makeProvider(t, fakeProvider1Name, fakeConfig+"2222")
	wantKM, err := loadKeyMaterials()
	if err != nil {
		t.Fatal(err)
	}
	fp1.kmCh <- wantKM
	fp2.kmCh <- wantKM
	ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
	defer cancel()
	gotKM, err := prov1.KeyMaterial(ctx)
	if err != nil {
		t.Fatalf("provider.KeyMaterial() = %v", err)
	}
	if !reflect.DeepEqual(gotKM, wantKM) {
		t.Fatalf("provider.KeyMaterial() = %+v, want %+v", gotKM, wantKM)
	}
	gotKM, err = prov2.KeyMaterial(ctx)
	if err != nil {
		t.Fatalf("provider.KeyMaterial() = %v", err)
	}
	if !reflect.DeepEqual(gotKM, wantKM) {
		t.Fatalf("provider.KeyMaterial() = %+v, want %+v", gotKM, wantKM)
	}
	newKM, err := loadKeyMaterials()
	if err != nil {
		t.Fatal(err)
	}
	newKM.Roots = nil
	fp1.kmCh <- newKM
	gotKM, err = prov2.KeyMaterial(ctx)
	if err != nil {
		t.Fatalf("provider.KeyMaterial() = %v", err)
	}
	if !reflect.DeepEqual(gotKM, wantKM) {
		t.Fatalf("provider.KeyMaterial() = %+v, want %+v", gotKM, wantKM)
	}
	prov1.Close()
	if _, err := prov2.KeyMaterial(ctx); err != nil {
		t.Fatalf("provider.KeyMaterial() = %v", err)
	}
	prov2.Close()
	if _, err := prov2.KeyMaterial(ctx); err != errProviderClosed {
		t.Fatalf("provider.KeyMaterial() = %v, wantErr: %v", err, errProviderClosed)
	}
}
func ( s ) TestStoreWithSingleProviderWithoutSharing ( t * testing . T ) { prov1 , fp1 := makeProvider ( t , fakeProvider1Name , fakeConfig + " " ) prov2 , fp2 := makeProvider ( t , fakeProvider1Name , fakeConfig + " " ) wantKM , err := loadKeyMaterials ( ) if err != nil { t . Fatal ( err ) } fp1 . kmCh <- wantKM fp2 . kmCh <- wantKM ctx , cancel := context . WithTimeout ( context . Background ( ) , defaultTestTimeout ) defer cancel ( ) gotKM , err := prov1 . KeyMaterial ( ctx ) if err != nil { t . Fatalf ( " " , err ) } if ! reflect . DeepEqual ( gotKM , wantKM ) { t . Fatalf ( " " , gotKM , wantKM ) } gotKM , err = prov2 . KeyMaterial ( ctx ) if err != nil { t . Fatalf ( " " , err ) } if ! reflect . DeepEqual ( gotKM , wantKM ) { t . Fatalf ( " " , gotKM , wantKM ) } newKM , err := loadKeyMaterials ( ) if err != nil { t . Fatal ( err ) } newKM . Roots = nil fp1 . kmCh <- newKM gotKM , err = prov2 . KeyMaterial ( ctx ) if err != nil { t . Fatalf ( " " , err ) } if ! reflect . DeepEqual ( gotKM , wantKM ) { t . Fatalf ( " " , gotKM , wantKM ) } prov1 . Close ( ) if _ , err := prov2 . KeyMaterial ( ctx ) ; err != nil { t . Fatalf ( " " , err ) } prov2 . Close ( ) if _ , err := prov2 . KeyMaterial ( ctx ) ; err != errProviderClosed { t . Fatalf ( " " , err , errProviderClosed ) } }
TestStoreWithSingleProviderWithoutSharing creates multiple instances of the
same type of provider through the store with different configs.
TestStoreWithSingleProviderWithoutSharing creates multiple instances of the same type of provider through the store with different configs .
// Push the same key materials into the two providers. // Get key materials from the fake provider1 and compare it to the ones we // pushed above. // Get key materials from the fake provider2 and compare it to the ones we // pushed above. // Update the key materials used by provider1, and make sure provider2 is // not affected. // Close the provider1 and retry the KeyMaterial() call on prov2, and expect // it to succeed.