Source file src/crypto/internal/impl/impl_test.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package impl
     6  
     7  import "testing"
     8  
     9  func TestResetRestoresAllImplementations(t *testing.T) {
    10  	defer func(saved []implementation) { allImplementations = saved }(allImplementations)
    11  
    12  	first, second, unavailable := true, true, false
    13  	Register("testpkg", "First", &first)
    14  	Register("testpkg", "Second", &second)
    15  	Register("testpkg", "Unavailable", &unavailable)
    16  
    17  	if !Select("testpkg", "First") {
    18  		t.Fatal("Select reported an available implementation as unavailable")
    19  	}
    20  	if second {
    21  		t.Error("Select left another implementation enabled")
    22  	}
    23  	Select("testpkg", "")
    24  
    25  	Reset("testpkg")
    26  	for _, tc := range []struct {
    27  		name string
    28  		got  bool
    29  		want bool
    30  	}{
    31  		{"First", first, true},
    32  		{"Second", second, true},
    33  		{"Unavailable", unavailable, false},
    34  	} {
    35  		if tc.got != tc.want {
    36  			t.Errorf("after Reset, %s is %v, want %v", tc.name, tc.got, tc.want)
    37  		}
    38  	}
    39  }
    40  

View as plain text