code-intelligence.com/cifuzz@v0.40.0/internal/tokenstorage/tokenstorage_test.go (about) 1 package tokenstorage 2 3 import ( 4 "path/filepath" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 9 "code-intelligence.com/cifuzz/internal/testutil" 10 ) 11 12 func TestGetAndSet(t *testing.T) { 13 tempDir := testutil.MkdirTemp(t, "", "access-tokens-test-") 14 accessTokensFilePath = filepath.Join(tempDir, "access_tokens.json") 15 accessTokens = map[string]string{} 16 17 token := Get("http://localhost:8000") 18 require.Empty(t, token) 19 20 err = Set("http://localhost:8000", "token") 21 require.NoError(t, err) 22 23 token = Get("http://localhost:8000") 24 require.Equal(t, "token", token) 25 26 err = Set("http://localhost:8000", "token2") 27 require.NoError(t, err) 28 29 token = Get("http://localhost:8000") 30 require.NoError(t, err) 31 require.Equal(t, "token2", token) 32 } 33 34 func TestGet(t *testing.T) { 35 accessTokens = map[string]string{ 36 "app.example.com": "123", 37 "app.code-intelligence.com": "456", 38 "app.staging.code-intelligence.com/": "789", 39 } 40 41 // Test exact match 42 token := Get("app.example.com") 43 require.Equal(t, "123", token) 44 45 // Test target with trailing slash (should match the same as without) 46 token = Get("app.code-intelligence.com/") 47 require.Equal(t, "456", token) 48 49 // Test target without trailing slash (should match the same as with) 50 token = Get("app.staging.code-intelligence.com") 51 require.Equal(t, "789", token) 52 53 // Test non-existing target 54 token = Get("example.org") 55 require.Empty(t, token) 56 }