github.com/kbehouse/nsc@v0.0.6/cmd/wellknownoperator_test.go (about) 1 /* 2 * Copyright 2018-2019 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 "testing" 20 21 "github.com/stretchr/testify/require" 22 ) 23 24 func Test_ListWellKnownOperators(t *testing.T) { 25 wko, err := GetWellKnownOperators() 26 require.NoError(t, err) 27 require.NotNil(t, wko) 28 require.True(t, len(wko) >= 1) 29 30 s, err := FindKnownOperator("SYNADIA") 31 require.NoError(t, err) 32 require.NotNil(t, s) 33 34 s, err = FindKnownOperator("local") 35 require.NoError(t, err) 36 require.Nil(t, s) 37 } 38 39 func Test_FindEnvOperators(t *testing.T) { 40 env := []string{ 41 "one=1", 42 "nsc_opa_operator=http://localhost:1234", 43 "NSC_opb_operator=http://localhost:5678", 44 "NSC_HOME=x", 45 } 46 47 ops := findEnvOperators(env) 48 require.Len(t, ops, 2) 49 require.Equal(t, "opa", ops[0].Name) 50 require.Equal(t, "http://localhost:1234", ops[0].AccountServerURL) 51 require.Equal(t, "opb", ops[1].Name) 52 require.Equal(t, "http://localhost:5678", ops[1].AccountServerURL) 53 } 54 55 func Test_GetOperatorName(t *testing.T) { 56 wko, err := GetWellKnownOperators() 57 require.NoError(t, err) 58 require.NotNil(t, wko) 59 require.True(t, len(wko) >= 1) 60 61 n := GetOperatorName("test", "https://api.synadia.io/jwt/v2/synadia") 62 require.Equal(t, "synadia", n) 63 64 n = GetOperatorName("X", "http://something.io/jwt/v1/foobar") 65 require.Equal(t, "X", n) 66 }