github.com/matrixorigin/matrixone@v1.2.0/pkg/stream/connector/options_test.go (about)

     1  // Copyright 2021 - 2023 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package moconnector
    16  
    17  import (
    18  	"context"
    19  	"testing"
    20  
    21  	"github.com/stretchr/testify/assert"
    22  )
    23  
    24  func TestMakeStmtOpts(t *testing.T) {
    25  	empty := StmtOpts{}
    26  	o, err := MakeStmtOpts(context.Background(), nil)
    27  	assert.NoError(t, err)
    28  	assert.Equal(t, empty, o)
    29  
    30  	noTypeOpts := map[string]string{
    31  		"value": "json",
    32  	}
    33  	_, err = MakeStmtOpts(context.Background(), noTypeOpts)
    34  	assert.Error(t, err)
    35  
    36  	notSupportedOpts := map[string]string{
    37  		"abc": "abc",
    38  	}
    39  	_, err = MakeStmtOpts(context.Background(), notSupportedOpts)
    40  	assert.Error(t, err)
    41  
    42  	notSupportedOpts = map[string]string{
    43  		"type": "kafka",
    44  		"abc":  "abc",
    45  	}
    46  	_, err = MakeStmtOpts(context.Background(), notSupportedOpts)
    47  	assert.Error(t, err)
    48  
    49  	invalidValueOptList := []map[string]string{
    50  		{"type": ""},
    51  		{"type": "my"},
    52  		{"type": "kafka", "bootstrap.servers": "localhost"},
    53  		{"type": "kafka", "value": "a"},
    54  	}
    55  	for _, opt := range invalidValueOptList {
    56  		_, err = MakeStmtOpts(context.Background(), opt)
    57  		assert.Error(t, err)
    58  	}
    59  
    60  	lackOpts := map[string]string{"type": "kafka", "partition": "1"}
    61  	_, err = MakeStmtOpts(context.Background(), lackOpts)
    62  	assert.Error(t, err)
    63  
    64  	lackOpts = map[string]string{"type": "kafka1", "partition": "1"}
    65  	_, err = MakeStmtOpts(context.Background(), lackOpts)
    66  	assert.Error(t, err)
    67  
    68  	okOpts := map[string]string{
    69  		"type":              "kafka",
    70  		"bootstrap.servers": "localhost:9092",
    71  		"topic":             "t1",
    72  		"value":             "json",
    73  		"partition":         "1",
    74  	}
    75  	o, err = MakeStmtOpts(context.Background(), okOpts)
    76  	assert.NoError(t, err)
    77  	assert.Equal(t, o, StmtOpts(okOpts))
    78  }