github.com/yrj2011/jx-test-infra@v0.0.0-20190529031832-7a2065ee98eb/prow/initupload/options_test.go (about)

     1  /*
     2  Copyright 2018 The Kubernetes 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  
    17  package initupload
    18  
    19  import (
    20  	"testing"
    21  
    22  	"k8s.io/test-infra/prow/gcsupload"
    23  	"k8s.io/test-infra/prow/kube"
    24  )
    25  
    26  func TestOptions_Validate(t *testing.T) {
    27  	var testCases = []struct {
    28  		name        string
    29  		input       Options
    30  		expectedErr bool
    31  	}{
    32  		{
    33  			name: "minimal set ok",
    34  			input: Options{
    35  				Log: "testing",
    36  				Options: &gcsupload.Options{
    37  					DryRun: true,
    38  					GCSConfiguration: &kube.GCSConfiguration{
    39  						PathStrategy: kube.PathStrategyExplicit,
    40  					},
    41  				},
    42  			},
    43  			expectedErr: false,
    44  		},
    45  		{
    46  			name: "missing clone log",
    47  			input: Options{
    48  				Options: &gcsupload.Options{
    49  					DryRun: true,
    50  					GCSConfiguration: &kube.GCSConfiguration{
    51  						PathStrategy: kube.PathStrategyExplicit,
    52  					},
    53  				},
    54  			},
    55  			expectedErr: false,
    56  		},
    57  		{
    58  			name: "missing path strategy",
    59  			input: Options{
    60  				Options: &gcsupload.Options{
    61  					DryRun:           true,
    62  					GCSConfiguration: &kube.GCSConfiguration{},
    63  				},
    64  			},
    65  			expectedErr: true,
    66  		},
    67  	}
    68  
    69  	for _, testCase := range testCases {
    70  		err := testCase.input.Validate()
    71  		if testCase.expectedErr && err == nil {
    72  			t.Errorf("%s: expected an error but got none", testCase.name)
    73  		}
    74  		if !testCase.expectedErr && err != nil {
    75  			t.Errorf("%s: expected no error but got one: %v", testCase.name, err)
    76  		}
    77  	}
    78  }