MCPcopy Index your code
hub / github.com/coder/coder / TestParseCredentialsJSON

Function TestParseCredentialsJSON

cli/sessionstore/sessionstore_internal_test.go:68–98  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

66}
67
68func TestParseCredentialsJSON(t *testing.T) {
69 t.Parallel()
70
71 t.Run("Empty", func(t *testing.T) {
72 t.Parallel()
73 creds, err := parseCredentialsJSON(nil)
74 require.NoError(t, err)
75 require.NotNil(t, creds)
76 require.Empty(t, creds)
77 })
78
79 t.Run("NewFormat", func(t *testing.T) {
80 t.Parallel()
81 jsonData := []byte(`{
82 "coder1.example.com": {"coder_url": "coder1.example.com", "api_token": "token1"},
83 "coder2.example.com": {"coder_url": "coder2.example.com", "api_token": "token2"}
84 }`)
85 creds, err := parseCredentialsJSON(jsonData)
86 require.NoError(t, err)
87 require.Len(t, creds, 2)
88 require.Equal(t, "token1", creds["coder1.example.com"].APIToken)
89 require.Equal(t, "token2", creds["coder2.example.com"].APIToken)
90 })
91
92 t.Run("InvalidJSON", func(t *testing.T) {
93 t.Parallel()
94 jsonData := []byte(`{invalid json}`)
95 _, err := parseCredentialsJSON(jsonData)
96 require.Error(t, err)
97 })
98}
99
100func TestCredentialsMap_RoundTrip(t *testing.T) {
101 t.Parallel()

Callers

nothing calls this directly

Calls 6

parseCredentialsJSONFunction · 0.85
RunMethod · 0.65
EmptyMethod · 0.45
LenMethod · 0.45
EqualMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected