github.com/argoproj/argo-events@v1.9.1/eventsources/common/fsevent/fileevent_test.go (about)

     1  package fsevent
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestOpString(t *testing.T) {
    10  	tests := []struct {
    11  		op       Op
    12  		expected string
    13  	}{
    14  		{Create, "CREATE"},
    15  		{Remove, "REMOVE"},
    16  		{Write, "WRITE"},
    17  		{Rename, "RENAME"},
    18  		{Chmod, "CHMOD"},
    19  		{Create | Write, "CREATE|WRITE"},
    20  	}
    21  
    22  	for _, tt := range tests {
    23  		assert.Equal(t, tt.expected, tt.op.String(), "Op.String() for op %d", tt.op)
    24  	}
    25  }
    26  
    27  func TestNewOp(t *testing.T) {
    28  	tests := []struct {
    29  		input    string
    30  		expected Op
    31  	}{
    32  		{"CREATE", Create},
    33  		{"REMOVE", Remove},
    34  		{"WRITE", Write},
    35  		{"RENAME", Rename},
    36  		{"CHMOD", Chmod},
    37  		{"CREATE|WRITE", Create | Write},
    38  	}
    39  
    40  	for _, tt := range tests {
    41  		assert.Equal(t, tt.expected, NewOp(tt.input), "NewOp(%q)", tt.input)
    42  	}
    43  }
    44  
    45  func TestEventString(t *testing.T) {
    46  	tests := []struct {
    47  		event    Event
    48  		expected string
    49  	}{
    50  		{Event{Name: "file1", Op: Create}, `"file1": CREATE`},
    51  		{Event{Name: "file2", Op: Remove | Write}, `"file2": REMOVE|WRITE`},
    52  	}
    53  
    54  	for _, tt := range tests {
    55  		assert.Equal(t, tt.expected, tt.event.String(), "Event.String() for event %#v", tt.event)
    56  	}
    57  }