gitlab.com/beacon-software/gadget@v0.0.0-20181217202115-54565ea1ed5e/log/cloudwatch/output_test.go (about)

     1  package cloudwatch
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  
     9  	"gitlab.com/beacon-software/gadget/log"
    10  )
    11  
    12  func Test_EnsureGroupNameIsValid(t *testing.T) {
    13  	assert := assert.New(t)
    14  	tests := []struct {
    15  		name     string
    16  		input    string
    17  		expected string
    18  	}{
    19  		{
    20  			name:     "Test Emtpy Input",
    21  			input:    "",
    22  			expected: "EmptyLogGroupName",
    23  		},
    24  		{
    25  			name:     "Test Safe Input",
    26  			input:    "asdf_-/.",
    27  			expected: "asdf_-/.",
    28  		},
    29  		{
    30  			name:     "Test Emoji Input",
    31  			input:    "asdf😜",
    32  			expected: "asdf",
    33  		},
    34  		{
    35  			name:     "Test results in whitespace",
    36  			input:    "😜",
    37  			expected: "EmptyLogGroupName",
    38  		},
    39  	}
    40  	for _, test := range tests {
    41  		actual := EnsureGroupNameIsValid(test.input)
    42  		assert.Equal(test.expected, actual, "(%s) EnsureGroupNameIsValid('%s') = '%s', Expected '%s'",
    43  			test.name, test.input, actual, test.expected)
    44  	}
    45  }
    46  
    47  func Test_EnsureStreamNameIsValid(t *testing.T) {
    48  	assert := assert.New(t)
    49  	tests := []struct {
    50  		name     string
    51  		input    string
    52  		expected string
    53  	}{
    54  		{
    55  			name:     "Test Emtpy Input",
    56  			input:    "",
    57  			expected: "EmptyLogStreamName",
    58  		},
    59  		{
    60  			name:     "Test Safe Input",
    61  			input:    "asdf_-/.",
    62  			expected: "asdf_-/.",
    63  		},
    64  		{
    65  			name:     "Test Emoji Input",
    66  			input:    "asdf😜",
    67  			expected: "asdf😜",
    68  		},
    69  		{
    70  			name:     "Test results in whitespace",
    71  			input:    "*:",
    72  			expected: "EmptyLogStreamName",
    73  		},
    74  	}
    75  	for _, test := range tests {
    76  		actual := EnsureStreamNameIsValid(test.input)
    77  		assert.Equal(test.expected, actual, "(%s) EnsureGroupNameIsValid('%s') = '%s', Expected '%s'",
    78  			test.name, test.input, actual, test.expected)
    79  	}
    80  }
    81  
    82  func Test_Skip(t *testing.T) {
    83  	// we are not testing the actual integration with cloudwatch since the API is too big to replicate
    84  	// and the tests would be testing the framework.
    85  	// Run this if you make changes and check that the messages make it
    86  	// into cloudwatch.
    87  	t.SkipNow()
    88  	assert := assert.New(t)
    89  	admin, err := GetAdministration()
    90  	if !assert.NoError(err) {
    91  		return
    92  	}
    93  	output, err := admin.GetOutput("testGroup", "testStream", log.FlagAll)
    94  	if !assert.NoError(err) {
    95  		return
    96  	}
    97  	message := log.Message{Message: "some riot text", TimestampUnix: time.Now().UTC().Unix()}
    98  	output.Log(message)
    99  	message = log.Message{Message: "some riot text", TimestampUnix: time.Now().UTC().Unix()}
   100  	output.Log(message)
   101  	message = log.Message{Message: "some riot text", TimestampUnix: time.Now().UTC().Unix()}
   102  	output.Log(message)
   103  	time.Sleep(1)
   104  	assert.Fail("adsf")
   105  }