github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/trigger/fsnotify/trigger_test.go (about)

     1  /*
     2  Copyright 2020 The Skaffold 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 fsnotify
    18  
    19  import (
    20  	"bytes"
    21  	"testing"
    22  
    23  	"github.com/GoogleContainerTools/skaffold/testutil"
    24  )
    25  
    26  func TestLogWatchToUser(t *testing.T) {
    27  	tests := []struct {
    28  		description string
    29  		isActive    bool
    30  		expected    string
    31  	}{
    32  		{
    33  			description: "active notify Trigger",
    34  			isActive:    true,
    35  			expected:    "Watching for changes...\n",
    36  		},
    37  		{
    38  			description: "inactive notify Trigger",
    39  			isActive:    false,
    40  			expected:    "Not watching for changes...\n",
    41  		},
    42  	}
    43  	for _, test := range tests {
    44  		out := new(bytes.Buffer)
    45  
    46  		trigger := &Trigger{
    47  			Interval: 10,
    48  			isActive: func() bool {
    49  				return test.isActive
    50  			},
    51  		}
    52  		trigger.LogWatchToUser(out)
    53  
    54  		got, want := out.String(), test.expected
    55  		testutil.CheckDeepEqual(t, want, got)
    56  	}
    57  }
    58  
    59  func Test_Debounce(t *testing.T) {
    60  	tr := &Trigger{}
    61  	got, want := tr.Debounce(), false
    62  	testutil.CheckDeepEqual(t, want, got)
    63  }
    64  
    65  func Test_Ignore(t *testing.T) {
    66  	tr := &Trigger{}
    67  	testutil.CheckDeepEqual(t, false, tr.Ignore(nil))
    68  }