oauth2_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2014 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Package internal contains support packages for oauth2 package.
  5. package internal
  6. import (
  7. "reflect"
  8. "strings"
  9. "testing"
  10. )
  11. func TestParseINI(t *testing.T) {
  12. tests := []struct {
  13. ini string
  14. want map[string]map[string]string
  15. }{
  16. {
  17. `root = toor
  18. [foo]
  19. bar = hop
  20. ini = nin
  21. `,
  22. map[string]map[string]string{
  23. "": map[string]string{"root": "toor"},
  24. "foo": map[string]string{"bar": "hop", "ini": "nin"},
  25. },
  26. },
  27. {
  28. `[empty]
  29. [section]
  30. empty=
  31. `,
  32. map[string]map[string]string{
  33. "": map[string]string{},
  34. "empty": map[string]string{},
  35. "section": map[string]string{"empty": ""},
  36. },
  37. },
  38. {
  39. `ignore
  40. [invalid
  41. =stuff
  42. ;comment=true
  43. `,
  44. map[string]map[string]string{
  45. "": map[string]string{},
  46. },
  47. },
  48. }
  49. for _, tt := range tests {
  50. result, err := ParseINI(strings.NewReader(tt.ini))
  51. if err != nil {
  52. t.Errorf("ParseINI(%q) error %v, want: no error", tt.ini, err)
  53. continue
  54. }
  55. if !reflect.DeepEqual(result, tt.want) {
  56. t.Errorf("ParseINI(%q) = %#v, want: %#v", tt.ini, result, tt.want)
  57. }
  58. }
  59. }