...

Source file src/github.com/sigstore/timestamp-authority/cmd/timestamp-cli/app/pflags_test.go

Documentation: github.com/sigstore/timestamp-authority/cmd/timestamp-cli/app

     1  //
     2  // Copyright 2022 The Sigstore Authors.
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  
    16  package app
    17  
    18  import (
    19  	"testing"
    20  )
    21  
    22  func TestValidateTimestampServerURL(t *testing.T) {
    23  	type test struct {
    24  		caseDesc        string
    25  		timestampServer string
    26  		expectSuccess   bool
    27  	}
    28  
    29  	tests := []test{
    30  		{
    31  			caseDesc:      "value not specified",
    32  			expectSuccess: false,
    33  		},
    34  		{
    35  			caseDesc:        "valid timestamp_server value",
    36  			timestampServer: "http://localhost:3000",
    37  			expectSuccess:   true,
    38  		},
    39  		{
    40  			caseDesc:        "valid URL, invalid scheme",
    41  			timestampServer: "ldap://localhost:3000",
    42  			expectSuccess:   false,
    43  		},
    44  		{
    45  			caseDesc:        "invalid URL",
    46  			timestampServer: "hteeteepeeColonSlashSlashlocalhost:3000",
    47  			expectSuccess:   false,
    48  		},
    49  		{
    50  			caseDesc:        "local path",
    51  			timestampServer: "/localhost",
    52  			expectSuccess:   false,
    53  		},
    54  	}
    55  
    56  	for _, tc := range tests {
    57  		if err := rootCmd.PersistentFlags().Set("timestamp_server", tc.timestampServer); (err == nil) != tc.expectSuccess {
    58  			t.Errorf("unexpected result in '%v': %v", tc.caseDesc, err)
    59  		}
    60  	}
    61  }
    62  

View as plain text