code.vegaprotocol.io/vega@v0.79.0/core/datasource/spec/validation/internal_test.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package validation_test
    17  
    18  import (
    19  	"testing"
    20  
    21  	"code.vegaprotocol.io/vega/core/datasource/spec/validation"
    22  
    23  	"github.com/stretchr/testify/require"
    24  )
    25  
    26  func TestCheckForInternalOracle(t *testing.T) {
    27  	type args struct {
    28  		data map[string]string
    29  	}
    30  	tests := []struct {
    31  		name    string
    32  		args    args
    33  		wantErr bool
    34  	}{
    35  		{
    36  			name: "Should return an error if there is any data that contains reserved prefix",
    37  			args: args{
    38  				data: map[string]string{
    39  					"aaaa":                      "aaaa",
    40  					"bbbb":                      "bbbb",
    41  					"cccc":                      "cccc",
    42  					"vegaprotocol.builtin.dddd": "dddd",
    43  				},
    44  			},
    45  			wantErr: true,
    46  		},
    47  		{
    48  			name: "Should pass validation if none of the data contains a reserved prefix",
    49  			args: args{
    50  				data: map[string]string{
    51  					"aaaa": "aaaa",
    52  					"bbbb": "bbbb",
    53  					"cccc": "cccc",
    54  					"dddd": "dddd",
    55  				},
    56  			},
    57  			wantErr: false,
    58  		},
    59  		{
    60  			name: "Should pass validation if reserved prefix is contained in key, but key doesn't start with the prefix",
    61  			args: args{
    62  				data: map[string]string{
    63  					"aaaa":                      "aaaa",
    64  					"bbbb":                      "bbbb",
    65  					"cccc":                      "cccc",
    66  					"dddd.vegaprotocol.builtin": "dddd",
    67  				},
    68  			},
    69  			wantErr: false,
    70  		},
    71  	}
    72  	for _, tc := range tests {
    73  		t.Run(tc.name, func(tt *testing.T) {
    74  			if err := validation.CheckForInternalOracle(tc.args.data); tc.wantErr {
    75  				require.Error(tt, err)
    76  			} else {
    77  				require.NoError(tt, err)
    78  			}
    79  		})
    80  	}
    81  }