github.com/nats-io/nsc/v2@v2.8.7-0.20240307184528-efd7023c6896/cmd/natsresolverconfigbuilder_test.go (about) 1 /* 2 * Copyright 2018-2023 The NATS Authors 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 16 package cmd 17 18 import ( 19 "bytes" 20 "fmt" 21 "os" 22 "path/filepath" 23 "testing" 24 25 "github.com/nats-io/nats-server/v2/server" 26 "github.com/stretchr/testify/require" 27 ) 28 29 func Test_NatsResolverServerParse(t *testing.T) { 30 ts := NewEmptyStore(t) 31 defer ts.Done(t) 32 _, _, err := ExecuteCmd(createAddOperatorCmd(), "--name", "OP", "--sys") 33 require.NoError(t, err) 34 serverconf := filepath.Join(ts.Dir, "server.conf") 35 _, _, err = ExecuteCmd(createServerConfigCmd(), "--nats-resolver", "--config-file", serverconf) 36 require.NoError(t, err) 37 // modify the generated file so the jwt directory does not get created where the test is running 38 data, err := os.ReadFile(serverconf) 39 require.NoError(t, err) 40 dir := ts.AddSubDir(t, "resolver") 41 data = bytes.ReplaceAll(data, []byte(`dir: './jwt'`), []byte(fmt.Sprintf(`dir: '%s'`, dir))) 42 err = os.WriteFile(serverconf, data, 0660) 43 require.NoError(t, err) 44 // test parsing 45 var opts server.Options 46 require.NoError(t, opts.ProcessConfigFile(serverconf)) 47 require.NotEmpty(t, opts.SystemAccount) 48 require.NotEmpty(t, opts.TrustedOperators) 49 }