get.pme.sh/pnats@v0.0.0-20240304004023-26bb5a137ed0/server/certidp/certidp_test.go (about)

     1  // Copyright 2023 The NATS Authors
     2  // Licensed under the Apache License, Version 2.0 (the "License");
     3  // you may not use this file except in compliance with the License.
     4  // You may obtain a copy of the License at
     5  //
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package certidp
    15  
    16  import "testing"
    17  
    18  // Checks the return values of the function GetStatusAssertionStr
    19  func TestGetStatusAssertionStr(t *testing.T) {
    20  	tests := []struct {
    21  		name     string
    22  		input    int
    23  		expected string
    24  	}{
    25  		{
    26  			name:     "GoodStatus",
    27  			input:    0,
    28  			expected: "good",
    29  		},
    30  		{
    31  			name:     "RevokedStatus",
    32  			input:    1,
    33  			expected: "revoked",
    34  		},
    35  		{
    36  			name:     "UnknownStatus",
    37  			input:    2,
    38  			expected: "unknown",
    39  		},
    40  		// Invalid status assertion value.
    41  		{
    42  			name:     "InvalidStatus",
    43  			input:    42,
    44  			expected: "unknown",
    45  		},
    46  	}
    47  
    48  	for _, tt := range tests {
    49  		t.Run(tt.name, func(t *testing.T) {
    50  			got := GetStatusAssertionStr(tt.input)
    51  			if got != tt.expected {
    52  				t.Errorf("Expected GetStatusAssertionStr: %v, got %v", tt.expected, got)
    53  			}
    54  		})
    55  	}
    56  }