github.com/abayer/test-infra@v0.0.5/prow/cmd/hook/main_test.go (about)

     1  /*
     2  Copyright 2016 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 main
    18  
    19  import (
    20  	"testing"
    21  
    22  	"k8s.io/test-infra/prow/plugins"
    23  )
    24  
    25  // Make sure that our plugins are valid.
    26  func TestPlugins(t *testing.T) {
    27  	pa := &plugins.PluginAgent{}
    28  	if err := pa.Load("../../plugins.yaml"); err != nil {
    29  		t.Fatalf("Could not load plugins: %v.", err)
    30  	}
    31  }
    32  
    33  func TestOptions_Validate(t *testing.T) {
    34  	var testCases = []struct {
    35  		name        string
    36  		opt         options
    37  		expectedErr bool
    38  	}{
    39  		{
    40  			name: "all ok without dry-run",
    41  			opt: options{
    42  				dryRun: false,
    43  			},
    44  			expectedErr: false,
    45  		},
    46  		{
    47  			name: "all ok with dry-run",
    48  			opt: options{
    49  				dryRun:  true,
    50  				deckURL: "internet",
    51  			},
    52  			expectedErr: false,
    53  		},
    54  		{
    55  			name: "missing deck endpoint with dry-run",
    56  			opt: options{
    57  				dryRun: true,
    58  			},
    59  			expectedErr: true,
    60  		},
    61  	}
    62  
    63  	for _, testCase := range testCases {
    64  		err := testCase.opt.Validate()
    65  		if testCase.expectedErr && err == nil {
    66  			t.Errorf("%s: expected an error but got none", testCase.name)
    67  		}
    68  		if !testCase.expectedErr && err != nil {
    69  			t.Errorf("%s: expected no error but got one: %v", testCase.name, err)
    70  		}
    71  	}
    72  }