github.com/instill-ai/component@v0.16.0-beta/pkg/operator/base64/v0/encoding_test.go (about)

     1  package base64
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestEncode(t *testing.T) {
    10  	tests := []struct {
    11  		Name           string
    12  		Input          string
    13  		ExpectedOutput string
    14  	}{
    15  		{
    16  			Name:           "positive test case",
    17  			Input:          "Hello, World!",
    18  			ExpectedOutput: "SGVsbG8sIFdvcmxkIQ==",
    19  		},
    20  	}
    21  
    22  	for _, test := range tests {
    23  		t.Run(test.Name, func(t *testing.T) {
    24  			assert.Equal(t, test.ExpectedOutput, Encode(test.Input))
    25  		})
    26  	}
    27  }
    28  
    29  func TestDecode(t *testing.T) {
    30  	tests := []struct {
    31  		Name           string
    32  		Input          string
    33  		ExpectedOutput string
    34  		ExpectedErr    error
    35  	}{
    36  		{
    37  			Name:           "positive test case",
    38  			Input:          "SGVsbG8sIFdvcmxkIQ==",
    39  			ExpectedOutput: "Hello, World!",
    40  		},
    41  	}
    42  
    43  	for _, test := range tests {
    44  		t.Run(test.Name, func(t *testing.T) {
    45  			res, err := Decode(test.Input)
    46  			assert.Equal(t, test.ExpectedOutput, res)
    47  			assert.Equal(t, test.ExpectedErr, err)
    48  		})
    49  	}
    50  }