Browse Source

Use JSON as canonical config format

Uses the github.com/ghodss/yaml library to convert YAML to JSON before
unmarshaling for the purposes of supporting YAML and JSON input while
converting to only support JSON internally.

Bug: T207694
Change-Id: I00668014907e9ea54917f5d5067cac08d0668053
Tyler Cipriani 10 months ago
parent
commit
56e830f641
100 changed files with 1026 additions and 12195 deletions
  1. 1
    0
      .gitignore
  2. 1
    1
      .pipeline/blubber.yaml
  3. 2
    2
      CONTRIBUTING.md
  4. 45
    3
      Gopkg.lock
  5. 8
    0
      Gopkg.toml
  6. 1
    1
      cmd/blubberoid/main.go
  7. 1
    1
      config/apt.go
  8. 1
    1
      config/apt_test.go
  9. 3
    3
      config/artifacts.go
  10. 4
    4
      config/artifacts_test.go
  11. 2
    2
      config/builder.go
  12. 1
    1
      config/builder_test.go
  13. 8
    8
      config/common.go
  14. 1
    1
      config/common_test.go
  15. 3
    3
      config/config.go
  16. 1
    1
      config/config_test.go
  17. 6
    3
      config/flag.go
  18. 1
    1
      config/flag_test.go
  19. 2
    2
      config/lives.go
  20. 2
    2
      config/lives_test.go
  21. 2
    2
      config/node.go
  22. 1
    1
      config/node_test.go
  23. 25
    14
      config/policy.go
  24. 3
    3
      config/policy_test.go
  25. 2
    2
      config/python.go
  26. 3
    3
      config/python_test.go
  27. 32
    17
      config/reader.go
  28. 9
    11
      config/reader_test.go
  29. 3
    3
      config/runs.go
  30. 1
    1
      config/runs_test.go
  31. 3
    3
      config/user.go
  32. 3
    3
      config/validation.go
  33. 4
    4
      config/variant.go
  34. 7
    7
      config/variant_test.go
  35. 1
    1
      config/version.go
  36. 1
    1
      config/version_test.go
  37. 4
    4
      docker/compiler_test.go
  38. 0
    22
      vendor/github.com/davecgh/go-spew/.gitignore
  39. 0
    14
      vendor/github.com/davecgh/go-spew/.travis.yml
  40. 0
    205
      vendor/github.com/davecgh/go-spew/README.md
  41. 0
    22
      vendor/github.com/davecgh/go-spew/cov_report.sh
  42. 0
    298
      vendor/github.com/davecgh/go-spew/spew/common_test.go
  43. 0
    1042
      vendor/github.com/davecgh/go-spew/spew/dump_test.go
  44. 0
    99
      vendor/github.com/davecgh/go-spew/spew/dumpcgo_test.go
  45. 0
    26
      vendor/github.com/davecgh/go-spew/spew/dumpnocgo_test.go
  46. 0
    226
      vendor/github.com/davecgh/go-spew/spew/example_test.go
  47. 0
    1558
      vendor/github.com/davecgh/go-spew/spew/format_test.go
  48. 0
    87
      vendor/github.com/davecgh/go-spew/spew/internal_test.go
  49. 0
    102
      vendor/github.com/davecgh/go-spew/spew/internalunsafe_test.go
  50. 0
    320
      vendor/github.com/davecgh/go-spew/spew/spew_test.go
  51. 0
    61
      vendor/github.com/davecgh/go-spew/test_coverage.txt
  52. 0
    37
      vendor/github.com/docker/distribution/.gitignore
  53. 0
    19
      vendor/github.com/docker/distribution/.mailmap
  54. 0
    119
      vendor/github.com/docker/distribution/BUILDING.md
  55. 0
    114
      vendor/github.com/docker/distribution/CHANGELOG.md
  56. 0
    140
      vendor/github.com/docker/distribution/CONTRIBUTING.md
  57. 0
    18
      vendor/github.com/docker/distribution/Dockerfile
  58. 0
    58
      vendor/github.com/docker/distribution/MAINTAINERS
  59. 0
    109
      vendor/github.com/docker/distribution/Makefile
  60. 0
    131
      vendor/github.com/docker/distribution/README.md
  61. 0
    36
      vendor/github.com/docker/distribution/RELEASE-CHECKLIST.md
  62. 0
    267
      vendor/github.com/docker/distribution/ROADMAP.md
  63. 0
    257
      vendor/github.com/docker/distribution/blobs.go
  64. 0
    93
      vendor/github.com/docker/distribution/circle.yml
  65. 0
    7
      vendor/github.com/docker/distribution/coverpkg.sh
  66. 0
    82
      vendor/github.com/docker/distribution/digest/digest_test.go
  67. 0
    21
      vendor/github.com/docker/distribution/digest/digester_resumable_test.go
  68. 0
    368
      vendor/github.com/docker/distribution/digest/set_test.go
  69. 0
    49
      vendor/github.com/docker/distribution/digest/verifiers_test.go
  70. 0
    7
      vendor/github.com/docker/distribution/doc.go
  71. 0
    115
      vendor/github.com/docker/distribution/errors.go
  72. 0
    125
      vendor/github.com/docker/distribution/manifests.go
  73. 0
    661
      vendor/github.com/docker/distribution/reference/reference_test.go
  74. 0
    489
      vendor/github.com/docker/distribution/reference/regexp_test.go
  75. 0
    97
      vendor/github.com/docker/distribution/registry.go
  76. 0
    27
      vendor/github.com/docker/distribution/tags.go
  77. 50
    0
      vendor/github.com/ghodss/yaml/LICENSE
  78. 501
    0
      vendor/github.com/ghodss/yaml/fields.go
  79. 277
    0
      vendor/github.com/ghodss/yaml/yaml.go
  80. 0
    24
      vendor/github.com/go-playground/locales/.gitignore
  81. 0
    172
      vendor/github.com/go-playground/locales/README.md
  82. 0
    609
      vendor/github.com/go-playground/locales/cu/cu.go
  83. 0
    1120
      vendor/github.com/go-playground/locales/cu/cu_test.go
  84. BIN
      vendor/github.com/go-playground/locales/logo.png
  85. 0
    24
      vendor/github.com/go-playground/universal-translator/.gitignore
  86. 0
    90
      vendor/github.com/go-playground/universal-translator/README.md
  87. 0
    110
      vendor/github.com/go-playground/universal-translator/benchmarks_test.go
  88. 0
    789
      vendor/github.com/go-playground/universal-translator/import_export_test.go
  89. BIN
      vendor/github.com/go-playground/universal-translator/logo.png
  90. 0
    858
      vendor/github.com/go-playground/universal-translator/translator_test.go
  91. 0
    10
      vendor/github.com/pborman/getopt/CONTRIBUTING.md
  92. 0
    226
      vendor/github.com/pborman/getopt/README.md
  93. 0
    74
      vendor/github.com/pborman/getopt/bool.go
  94. 0
    106
      vendor/github.com/pborman/getopt/bool_test.go
  95. 0
    34
      vendor/github.com/pborman/getopt/breakup_test.go
  96. 0
    81
      vendor/github.com/pborman/getopt/counter.go
  97. 0
    91
      vendor/github.com/pborman/getopt/counter_test.go
  98. 0
    56
      vendor/github.com/pborman/getopt/duration.go
  99. 0
    73
      vendor/github.com/pborman/getopt/duration_test.go
  100. 0
    0
      vendor/github.com/pborman/getopt/enum.go

+ 1
- 0
.gitignore View File

@@ -2,5 +2,6 @@
2 2
 /.lint-*
3 3
 /bin
4 4
 /blubber
5
+/blubberoid
5 6
 /blubber.git
6 7
 /_release

+ 1
- 1
.pipeline/blubber.yaml View File

@@ -5,7 +5,7 @@ lives:
5 5
 
6 6
 variants:
7 7
   build:
8
-    base: golang:1.9-stretch
8
+    base: golang:1.10-stretch
9 9
   test:
10 10
     includes: [build]
11 11
     runs: { insecurely: true }

+ 2
- 2
CONTRIBUTING.md View File

@@ -51,13 +51,13 @@ at `localhost:9999/pkg/gerrit.wikimedia.org/r/blubber`.
51 51
 Dealing with Go project dependencies is kind of a moving target at the moment,
52 52
 but for now we've opted to commit a minimal `vendor` directory which contains
53 53
 all the required packages. It has been automatically populated by `dep
54
-ensure && dep prune` according to our `Gopkg.toml` and `Gopkg.lock` files.
54
+ensure` according to our `Gopkg.toml` and `Gopkg.lock` files.
55 55
 
56 56
 If you're not making any changes to `Gopkg.toml`, adding, updating, or
57 57
 removing dependencies, you should already be good to go.
58 58
 
59 59
 If you do update `Gopkg.toml` to add, update, or remove a dependency, simply
60
-run `dep ensure && dep prune` after doing so, and commit the resulting
60
+run `dep ensure` after doing so, and commit the resulting
61 61
 `vendor` directory changes.
62 62
 
63 63
 ## Running tests and linters

+ 45
- 3
Gopkg.lock View File

@@ -2,68 +2,110 @@
2 2
 
3 3
 
4 4
 [[projects]]
5
+  digest = "1:a2c1d0e43bd3baaa071d1b9ed72c27d78169b2b269f71c105ac4ba34b1be4a39"
5 6
   name = "github.com/davecgh/go-spew"
6 7
   packages = ["spew"]
8
+  pruneopts = "NUT"
7 9
   revision = "346938d642f2ec3594ed81d874461961cd0faa76"
8 10
   version = "v1.1.0"
9 11
 
10 12
 [[projects]]
13
+  digest = "1:3cabbabc9e0e4aa7e12b882bdc213f41cf8bd2b2ce2a7b5e0aceaf8a6a78049b"
11 14
   name = "github.com/docker/distribution"
12
-  packages = ["digest","reference"]
15
+  packages = [
16
+    "digest",
17
+    "reference",
18
+  ]
19
+  pruneopts = "NUT"
13 20
   revision = "48294d928ced5dd9b378f7fd7c6f5da3ff3f2c89"
14 21
   version = "v2.6.2"
15 22
 
16 23
 [[projects]]
24
+  digest = "1:81466b4218bf6adddac2572a30ac733a9255919bc2f470b4827a317bd4ee1756"
25
+  name = "github.com/ghodss/yaml"
26
+  packages = ["."]
27
+  pruneopts = "NUT"
28
+  revision = "0ca9ea5df5451ffdf184b4428c902747c2c11cd7"
29
+  version = "v1.0.0"
30
+
31
+[[projects]]
32
+  digest = "1:672bdbde3b59017aba3b328d0ec42dc30e0ab80ff48681947596785738c00ff1"
17 33
   name = "github.com/go-playground/locales"
18
-  packages = [".","currency"]
34
+  packages = [
35
+    ".",
36
+    "currency",
37
+  ]
38
+  pruneopts = "NUT"
19 39
   revision = "e4cbcb5d0652150d40ad0646651076b6bd2be4f6"
20 40
   version = "v0.11.2"
21 41
 
22 42
 [[projects]]
43
+  digest = "1:1683152827ebac377858b53a6ad0be90fb1711061c7e580c5dc719834a349162"
23 44
   name = "github.com/go-playground/universal-translator"
24 45
   packages = ["."]
46
+  pruneopts = "NUT"
25 47
   revision = "b32fa301c9fe55953584134cb6853a13c87ec0a1"
26 48
   version = "v0.16.0"
27 49
 
28 50
 [[projects]]
29 51
   branch = "v2"
52
+  digest = "1:981e58364d2283b4f5931e7a1c4a2c3c09f1336bacf2d64c63ca9356fd9a0099"
30 53
   name = "github.com/pborman/getopt"
31 54
   packages = ["v2"]
55
+  pruneopts = "NUT"
32 56
   revision = "0fd4e972e7f7285fbae5863470524ece4ae99d78"
33 57
 
34 58
 [[projects]]
59
+  digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe"
35 60
   name = "github.com/pmezard/go-difflib"
36 61
   packages = ["difflib"]
62
+  pruneopts = "NUT"
37 63
   revision = "792786c7400a136282c1664665ae0a8db921c6c2"
38 64
   version = "v1.0.0"
39 65
 
40 66
 [[projects]]
67
+  digest = "1:b5c8b4a0ad5f65a85eb2a9f89e30c638ef8b99f8a3f078467cea778869757666"
41 68
   name = "github.com/stretchr/testify"
42 69
   packages = ["assert"]
70
+  pruneopts = "NUT"
43 71
   revision = "69483b4bd14f5845b5a1e55bca19e954e827f1d0"
44 72
   version = "v1.1.4"
45 73
 
46 74
 [[projects]]
75
+  digest = "1:67eb9fdb94a67a723deaef120f1ec70cfdb1553ca6ccea38e0650d7b1747c6ac"
47 76
   name = "github.com/utahta/go-openuri"
48 77
   packages = ["."]
78
+  pruneopts = "NUT"
49 79
   revision = "e3e1c475535dd7256d67286b1c8c223721aafa05"
50 80
   version = "v0.1.0"
51 81
 
52 82
 [[projects]]
83
+  digest = "1:e396e0963c85b8a2b437e419b55aa0169a212eb06a7c88fd2bf16e5e5cfce2f2"
53 84
   name = "gopkg.in/go-playground/validator.v9"
54 85
   packages = ["."]
86
+  pruneopts = "NUT"
55 87
   revision = "1b8c8e19cd250435025214492d9a08411d760fdd"
56 88
   version = "v9.12.0"
57 89
 
58 90
 [[projects]]
59 91
   branch = "v2"
92
+  digest = "1:c85dc78b3426641ebf2a0bbf5b731b5c4613ddb5987dbe218f7e75468dcd56f5"
60 93
   name = "gopkg.in/yaml.v2"
61 94
   packages = ["."]
95
+  pruneopts = "NUT"
62 96
   revision = "eb3733d160e74a9c7e442f435eb3bea458e1d19f"
63 97
 
64 98
 [solve-meta]
65 99
   analyzer-name = "dep"
66 100
   analyzer-version = 1
67
-  inputs-digest = "8cdb40365412638a73ba10e3c82296098a85b4df74a25186aec4bd7b3a8c50e4"
101
+  input-imports = [
102
+    "github.com/docker/distribution/reference",
103
+    "github.com/ghodss/yaml",
104
+    "github.com/pborman/getopt/v2",
105
+    "github.com/stretchr/testify/assert",
106
+    "github.com/utahta/go-openuri",
107
+    "gopkg.in/go-playground/validator.v9",
108
+    "gopkg.in/yaml.v2",
109
+  ]
68 110
   solver-name = "gps-cdcl"
69 111
   solver-version = 1

+ 8
- 0
Gopkg.toml View File

@@ -1,5 +1,9 @@
1 1
 # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
2 2
 # for detailed Gopkg.toml documentation.
3
+[prune]
4
+  non-go = true
5
+  go-tests = true
6
+  unused-packages = true
3 7
 
4 8
 [[constraint]]
5 9
   name = "github.com/docker/distribution"
@@ -24,3 +28,7 @@
24 28
 [[constraint]]
25 29
   branch = "v2"
26 30
   name = "github.com/pborman/getopt"
31
+
32
+[[constraint]]
33
+  name = "github.com/ghodss/yaml"
34
+  version = "1.0.0"

+ 1
- 1
cmd/blubberoid/main.go View File

@@ -71,7 +71,7 @@ func blubberoid(res http.ResponseWriter, req *http.Request) {
71 71
 		return
72 72
 	}
73 73
 
74
-	cfg, err := config.ReadConfig(body)
74
+	cfg, err := config.ReadYAMLConfig(body)
75 75
 
76 76
 	if err != nil {
77 77
 		if config.IsValidationError(err) {

+ 1
- 1
config/apt.go View File

@@ -8,7 +8,7 @@ import (
8 8
 // existing APT sources.
9 9
 //
10 10
 type AptConfig struct {
11
-	Packages []string `yaml:"packages" validate:"dive,debianpackage"`
11
+	Packages []string `json:"packages" validate:"dive,debianpackage"`
12 12
 }
13 13
 
14 14
 // Merge takes another AptConfig and combines the packages declared within

+ 1
- 1
config/apt_test.go View File

@@ -11,7 +11,7 @@ import (
11 11
 )
12 12
 
13 13
 func TestAptConfigYAML(t *testing.T) {
14
-	cfg, err := config.ReadConfig([]byte(`---
14
+	cfg, err := config.ReadYAMLConfig([]byte(`---
15 15
     version: v3
16 16
     apt:
17 17
       packages:

+ 3
- 3
config/artifacts.go View File

@@ -15,9 +15,9 @@ import (
15 15
 // VariantConfig.Copies.
16 16
 //
17 17
 type ArtifactsConfig struct {
18
-	From        string `yaml:"from" validate:"required,variantref"` // source variant from which to copy
19
-	Source      string `yaml:"source" validate:"required"`          // source variant path from which to copy
20
-	Destination string `yaml:"destination" validate:"required"`     // destination path within current variant
18
+	From        string `json:"from" validate:"required,variantref"` // source variant from which to copy
19
+	Source      string `json:"source" validate:"required"`          // source variant path from which to copy
20
+	Destination string `json:"destination" validate:"required"`     // destination path within current variant
21 21
 }
22 22
 
23 23
 // InstructionsForPhase injects instructions into the given build phase that

+ 4
- 4
config/artifacts_test.go View File

@@ -10,7 +10,7 @@ import (
10 10
 )
11 11
 
12 12
 func TestArtifactsConfigYAML(t *testing.T) {
13
-	cfg, err := config.ReadConfig([]byte(`---
13
+	cfg, err := config.ReadYAMLConfig([]byte(`---
14 14
     version: v3
15 15
     base: foo
16 16
     variants:
@@ -79,7 +79,7 @@ func TestArtifactsConfigInstructions(t *testing.T) {
79 79
 func TestArtifactsConfigValidation(t *testing.T) {
80 80
 	t.Run("from", func(t *testing.T) {
81 81
 		t.Run("ok", func(t *testing.T) {
82
-			_, err := config.ReadConfig([]byte(`---
82
+			_, err := config.ReadYAMLConfig([]byte(`---
83 83
         version: v3
84 84
         variants:
85 85
           build: {}
@@ -93,7 +93,7 @@ func TestArtifactsConfigValidation(t *testing.T) {
93 93
 		})
94 94
 
95 95
 		t.Run("missing", func(t *testing.T) {
96
-			_, err := config.ReadConfig([]byte(`---
96
+			_, err := config.ReadYAMLConfig([]byte(`---
97 97
         version: v3
98 98
         variants:
99 99
           build: {}
@@ -111,7 +111,7 @@ func TestArtifactsConfigValidation(t *testing.T) {
111 111
 		})
112 112
 
113 113
 		t.Run("bad", func(t *testing.T) {
114
-			_, err := config.ReadConfig([]byte(`---
114
+			_, err := config.ReadYAMLConfig([]byte(`---
115 115
         version: v3
116 116
         variants:
117 117
           build: {}

+ 2
- 2
config/builder.go View File

@@ -8,8 +8,8 @@ import (
8 8
 // build command and the files required to successfully execute the command.
9 9
 //
10 10
 type BuilderConfig struct {
11
-	Command      []string `yaml:"command"`
12
-	Requirements []string `yaml:"requirements"`
11
+	Command      []string `json:"command"`
12
+	Requirements []string `json:"requirements"`
13 13
 }
14 14
 
15 15
 // Merge takes another BuilderConfig and merges its fields into this one's,

+ 1
- 1
config/builder_test.go View File

@@ -10,7 +10,7 @@ import (
10 10
 )
11 11
 
12 12
 func TestBuilderConfigYAML(t *testing.T) {
13
-	cfg, err := config.ReadConfig([]byte(`---
13
+	cfg, err := config.ReadYAMLConfig([]byte(`---
14 14
     version: v3
15 15
     base: foo
16 16
     builder:

+ 8
- 8
config/common.go View File

@@ -8,14 +8,14 @@ import (
8 8
 // and each configured variant.
9 9
 //
10 10
 type CommonConfig struct {
11
-	Base       string        `yaml:"base" validate:"omitempty,baseimage"` // name/path to base image
12
-	Apt        AptConfig     `yaml:"apt"`                                 // APT related
13
-	Node       NodeConfig    `yaml:"node"`                                // Node related
14
-	Python     PythonConfig  `yaml:"python"`                              // Python related
15
-	Builder    BuilderConfig `yaml:"builder"`                             // Builder related
16
-	Lives      LivesConfig   `yaml:"lives"`                               // application owner/dir
17
-	Runs       RunsConfig    `yaml:"runs"`                                // runtime environment
18
-	EntryPoint []string      `yaml:"entrypoint"`                          // entry-point executable
11
+	Base       string        `json:"base" validate:"omitempty,baseimage"` // name/path to base image
12
+	Apt        AptConfig     `json:"apt"`                                 // APT related
13
+	Node       NodeConfig    `json:"node"`                                // Node related
14
+	Python     PythonConfig  `json:"python"`                              // Python related
15
+	Builder    BuilderConfig `json:"builder"`                             // Builder related
16
+	Lives      LivesConfig   `json:"lives"`                               // application owner/dir
17
+	Runs       RunsConfig    `json:"runs"`                                // runtime environment
18
+	EntryPoint []string      `json:"entrypoint"`                          // entry-point executable
19 19
 }
20 20
 
21 21
 // Merge takes another CommonConfig and merges its fields this one's.

+ 1
- 1
config/common_test.go View File

@@ -9,7 +9,7 @@ import (
9 9
 )
10 10
 
11 11
 func TestCommonConfigYAML(t *testing.T) {
12
-	cfg, err := config.ReadConfig([]byte(`---
12
+	cfg, err := config.ReadYAMLConfig([]byte(`---
13 13
     version: v3
14 14
     base: fooimage
15 15
     entrypoint: ["/bin/foo"]

+ 3
- 3
config/config.go View File

@@ -7,7 +7,7 @@ package config
7 7
 // Config holds the root fields of a Blubber configuration.
8 8
 //
9 9
 type Config struct {
10
-	CommonConfig  `yaml:",inline"`
11
-	Variants      map[string]VariantConfig `yaml:"variants" validate:"variants,dive"`
12
-	VersionConfig `yaml:",inline"`
10
+	CommonConfig  `json:",inline"`
11
+	Variants      map[string]VariantConfig `json:"variants" validate:"variants,dive"`
12
+	VersionConfig `json:",inline"`
13 13
 }

+ 1
- 1
config/config_test.go View File

@@ -9,7 +9,7 @@ import (
9 9
 )
10 10
 
11 11
 func TestConfigYAML(t *testing.T) {
12
-	cfg, err := config.ReadConfig([]byte(`---
12
+	cfg, err := config.ReadYAMLConfig([]byte(`---
13 13
     version: v3
14 14
     variants:
15 15
       foo: {}`))

+ 6
- 3
config/flag.go View File

@@ -1,4 +1,5 @@
1 1
 package config
2
+import "strconv"
2 3
 
3 4
 // Flag represents a nullable boolean value that is considered null until
4 5
 // either parsed from YAML or merged in from another Flag value.
@@ -8,11 +9,13 @@ type Flag struct {
8 9
 	set  bool
9 10
 }
10 11
 
11
-// UnmarshalYAML implements yaml.Unmarshaler to parse the underlying boolean
12
+// UnmarshalJSON implements json.Unmarshaler to parse the underlying boolean
12 13
 // value and detect that the Flag should no longer be considered null.
13 14
 //
14
-func (flag *Flag) UnmarshalYAML(unmarshal func(interface{}) error) error {
15
-	if err := unmarshal(&flag.True); err != nil {
15
+func (flag *Flag) UnmarshalJSON(unmarshal []byte) error {
16
+	var err error
17
+	flag.True, err = strconv.ParseBool(string(unmarshal))
18
+	if err != nil {
16 19
 		return err
17 20
 	}
18 21
 

+ 1
- 1
config/flag_test.go View File

@@ -9,7 +9,7 @@ import (
9 9
 )
10 10
 
11 11
 func TestFlagMerge(t *testing.T) {
12
-	cfg, err := config.ReadConfig([]byte(`---
12
+	cfg, err := config.ReadYAMLConfig([]byte(`---
13 13
     version: v3
14 14
     base: foo
15 15
     runs: { insecurely: true }

+ 2
- 2
config/lives.go View File

@@ -13,8 +13,8 @@ const LocalLibPrefix = "/opt/lib"
13 13
 // installed dependencies and application files.
14 14
 //
15 15
 type LivesConfig struct {
16
-	In         string `yaml:"in" validate:"omitempty,abspath"` // application directory
17
-	UserConfig `yaml:",inline"`
16
+	In         string `json:"in" validate:"omitempty,abspath"` // application directory
17
+	UserConfig `json:",inline"`
18 18
 }
19 19
 
20 20
 // Merge takes another LivesConfig and overwrites this struct's fields.

+ 2
- 2
config/lives_test.go View File

@@ -10,7 +10,7 @@ import (
10 10
 )
11 11
 
12 12
 func TestLivesConfigYAML(t *testing.T) {
13
-	cfg, err := config.ReadConfig([]byte(`---
13
+	cfg, err := config.ReadYAMLConfig([]byte(`---
14 14
     version: v3
15 15
     base: foo
16 16
     lives:
@@ -39,7 +39,7 @@ func TestLivesConfigYAML(t *testing.T) {
39 39
 }
40 40
 
41 41
 func TestLivesConfigDefaults(t *testing.T) {
42
-	cfg, err := config.ReadConfig([]byte(`---
42
+	cfg, err := config.ReadYAMLConfig([]byte(`---
43 43
     version: v3
44 44
     base: foo`))
45 45
 

+ 2
- 2
config/node.go View File

@@ -8,8 +8,8 @@ import (
8 8
 // whether/how to install NPM packages.
9 9
 //
10 10
 type NodeConfig struct {
11
-	Requirements []string `yaml:"requirements"`                     // install requirements from given files
12
-	Env          string   `yaml:"env" validate:"omitempty,nodeenv"` // environment name ("production" install)
11
+	Requirements []string `json:"requirements"`                     // install requirements from given files
12
+	Env          string   `json:"env" validate:"omitempty,nodeenv"` // environment name ("production" install)
13 13
 }
14 14
 
15 15
 // Merge takes another NodeConfig and merges its fields into this one's,

+ 1
- 1
config/node_test.go View File

@@ -10,7 +10,7 @@ import (
10 10
 )
11 11
 
12 12
 func TestNodeConfigYAML(t *testing.T) {
13
-	cfg, err := config.ReadConfig([]byte(`---
13
+	cfg, err := config.ReadYAMLConfig([]byte(`---
14 14
     version: v3
15 15
     base: foo
16 16
     node:

+ 25
- 14
config/policy.go View File

@@ -2,19 +2,20 @@ package config
2 2
 
3 3
 import (
4 4
 	"errors"
5
+	"encoding/json"
5 6
 	"fmt"
6 7
 	"io/ioutil"
7 8
 	"reflect"
8 9
 	"strings"
9 10
 
10 11
 	"github.com/utahta/go-openuri"
11
-	"gopkg.in/yaml.v2"
12
+	"github.com/ghodss/yaml"
12 13
 )
13 14
 
14 15
 // Policy validates a number of rules against a given configuration.
15 16
 //
16 17
 type Policy struct {
17
-	Enforcements []Enforcement `yaml:"enforcements"`
18
+	Enforcements []Enforcement `json:"enforcements"`
18 19
 }
19 20
 
20 21
 // Validate checks the given config against all policy enforcements.
@@ -23,7 +24,7 @@ func (pol Policy) Validate(config Config) error {
23 24
 	validate := newValidator()
24 25
 
25 26
 	for _, enforcement := range pol.Enforcements {
26
-		cfg, err := ResolveYAMLPath(enforcement.Path, config)
27
+		cfg, err := ResolveJSONPath(enforcement.Path, config)
27 28
 
28 29
 		if err != nil {
29 30
 			// If the path resolved nothing, there's nothing to enforce
@@ -52,16 +53,26 @@ func (pol Policy) Validate(config Config) error {
52 53
 // Enforcement represents a policy rule and config path on which to apply it.
53 54
 //
54 55
 type Enforcement struct {
55
-	Path string `yaml:"path"`
56
-	Rule string `yaml:"rule"`
56
+	Path string `json:"path"`
57
+	Rule string `json:"rule"`
57 58
 }
58 59
 
59
-// ReadPolicy unmarshals the given YAML bytes into a new Policy struct.
60
+// ReadYAMLPolicy converts YAML input to JSON and returns a new Policy struct.
61
+//
62
+func ReadYAMLPolicy(data []byte) (*Policy, error) {
63
+	jsonData, err := yaml.YAMLToJSON(data)
64
+	if err != nil {
65
+		return nil, err
66
+	}
67
+
68
+	return ReadPolicy(jsonData)
69
+}
70
+
71
+// ReadPolicy unmarshals the given YAML/json bytes into a new Policy struct.
60 72
 //
61 73
 func ReadPolicy(data []byte) (*Policy, error) {
62 74
 	var policy Policy
63
-
64
-	err := yaml.Unmarshal(data, &policy)
75
+	err := json.Unmarshal(data, &policy)
65 76
 
66 77
 	if err != nil {
67 78
 		return nil, err
@@ -88,13 +99,13 @@ func ReadPolicyFromURI(uri string) (*Policy, error) {
88 99
 		return nil, err
89 100
 	}
90 101
 
91
-	return ReadPolicy(data)
102
+	return ReadYAMLPolicy(data)
92 103
 }
93 104
 
94
-// ResolveYAMLPath returns the config value found at the given YAML-ish
105
+// ResolveJSONPath returns the config value found at the given JSON-ish
95 106
 // namespace/path (e.g. "variants.production.runs.as").
96 107
 //
97
-func ResolveYAMLPath(path string, cfg interface{}) (interface{}, error) {
108
+func ResolveJSONPath(path string, cfg interface{}) (interface{}, error) {
98 109
 	parts := strings.SplitN(path, ".", 2)
99 110
 	name := parts[0]
100 111
 
@@ -107,12 +118,12 @@ func ResolveYAMLPath(path string, cfg interface{}) (interface{}, error) {
107 118
 	case reflect.Struct:
108 119
 		for i := 0; i < t.NumField(); i++ {
109 120
 			if t.Field(i).Anonymous {
110
-				if subsubcfg, err := ResolveYAMLPath(path, v.Field(i).Interface()); err == nil {
121
+				if subsubcfg, err := ResolveJSONPath(path, v.Field(i).Interface()); err == nil {
111 122
 					return subsubcfg, nil
112 123
 				}
113 124
 			}
114 125
 
115
-			if name == resolveYAMLTagName(t.Field(i)) {
126
+			if name == resolveJSONTagName(t.Field(i)) {
116 127
 				subcfg = v.Field(i).Interface()
117 128
 				break
118 129
 			}
@@ -134,7 +145,7 @@ func ResolveYAMLPath(path string, cfg interface{}) (interface{}, error) {
134 145
 	}
135 146
 
136 147
 	if len(parts) > 1 {
137
-		return ResolveYAMLPath(parts[1], subcfg)
148
+		return ResolveJSONPath(parts[1], subcfg)
138 149
 	}
139 150
 
140 151
 	return subcfg, nil

+ 3
- 3
config/policy_test.go View File

@@ -9,7 +9,7 @@ import (
9 9
 )
10 10
 
11 11
 func TestPolicyRead(t *testing.T) {
12
-	policy, err := config.ReadPolicy([]byte(`---
12
+	policy, err := config.ReadYAMLPolicy([]byte(`---
13 13
     enforcements:
14 14
       - path: variants.production.runs.as
15 15
         rule: ne=root
@@ -94,7 +94,7 @@ func TestEnforcementOnFlag(t *testing.T) {
94 94
 
95 95
 }
96 96
 
97
-func TestResolveYAMLPath(t *testing.T) {
97
+func TestResolveJSONPath(t *testing.T) {
98 98
 	cfg := config.Config{
99 99
 		Variants: map[string]config.VariantConfig{
100 100
 			"foo": config.VariantConfig{
@@ -109,7 +109,7 @@ func TestResolveYAMLPath(t *testing.T) {
109 109
 		},
110 110
 	}
111 111
 
112
-	val, err := config.ResolveYAMLPath("variants.foo.runs.as", cfg)
112
+	val, err := config.ResolveJSONPath("variants.foo.runs.as", cfg)
113 113
 
114 114
 	if assert.NoError(t, err) {
115 115
 		assert.Equal(t, "root", val)

+ 2
- 2
config/python.go View File

@@ -20,8 +20,8 @@ const PythonSiteBin = PythonSitePackages + "/bin"
20 20
 // dependencies via PIP.
21 21
 //
22 22
 type PythonConfig struct {
23
-	Version      string   `yaml:"version"`      // Python binary to use when installing dependencies
24
-	Requirements []string `yaml:"requirements"` // install requirements from given files
23
+	Version      string   `json:"version"`      // Python binary to use when installing dependencies
24
+	Requirements []string `json:"requirements"` // install requirements from given files
25 25
 }
26 26
 
27 27
 // Merge takes another PythonConfig and merges its fields into this one's,

+ 3
- 3
config/python_test.go View File

@@ -10,7 +10,7 @@ import (
10 10
 )
11 11
 
12 12
 func TestPythonConfigYAMLMerge(t *testing.T) {
13
-	cfg, err := config.ReadConfig([]byte(`---
13
+	cfg, err := config.ReadYAMLConfig([]byte(`---
14 14
     version: v3
15 15
     base: foo
16 16
     python:
@@ -36,7 +36,7 @@ func TestPythonConfigYAMLMerge(t *testing.T) {
36 36
 }
37 37
 
38 38
 func TestPythonConfigYAMLMergeEmpty(t *testing.T) {
39
-	cfg, err := config.ReadConfig([]byte(`---
39
+	cfg, err := config.ReadYAMLConfig([]byte(`---
40 40
     version: v3
41 41
     base: foo
42 42
     python:
@@ -58,7 +58,7 @@ func TestPythonConfigYAMLMergeEmpty(t *testing.T) {
58 58
 }
59 59
 
60 60
 func TestPythonConfigYAMLDoNotMergeNil(t *testing.T) {
61
-	cfg, err := config.ReadConfig([]byte(`---
61
+	cfg, err := config.ReadYAMLConfig([]byte(`---
62 62
     version: v3
63 63
     base: foo
64 64
     python:

+ 32
- 17
config/reader.go View File

@@ -1,26 +1,29 @@
1 1
 package config
2 2
 
3 3
 import (
4
+	"bytes"
4 5
 	"errors"
6
+	"encoding/json"
5 7
 	"fmt"
6 8
 	"io/ioutil"
7 9
 
8
-	"gopkg.in/yaml.v2"
10
+	"github.com/ghodss/yaml"
9 11
 )
10 12
 
11 13
 // DefaultConfig contains YAML that is applied before the user's
12 14
 // configuration.
13 15
 //
14
-const DefaultConfig = `---
15
-lives:
16
-  in: /srv/app
17
-  as: somebody
18
-  uid: 65533
19
-  gid: 65533
20
-runs:
21
-  as: runuser
22
-  uid: 900
23
-  gid: 900`
16
+const DefaultConfig = `{
17
+"lives": {
18
+  "in": "/srv/app",
19
+  "as": "somebody",
20
+  "uid": 65533,
21
+  "gid": 65533
22
+},
23
+"runs": {
24
+  "as": "runuser",
25
+  "uid": 900,
26
+  "gid": 900}}`
24 27
 
25 28
 // ResolveIncludes iterates over and recurses through a given variant's
26 29
 // includes to build a flat slice of variant names in the correct order by
@@ -87,6 +90,16 @@ func ExpandVariant(config *Config, name string) (*VariantConfig, error) {
87 90
 
88 91
 	return expanded, nil
89 92
 }
93
+// ReadYAMLConfig converts YAML bytes to json and returns new Config struct.
94
+//
95
+func ReadYAMLConfig(data []byte) (*Config, error) {
96
+	jsonData, err := yaml.YAMLToJSON(data)
97
+	if err != nil {
98
+		return nil, err
99
+	}
100
+
101
+	return ReadConfig(jsonData)
102
+}
90 103
 
91 104
 // ReadConfig unmarshals the given YAML bytes into a new Config struct.
92 105
 //
@@ -96,8 +109,8 @@ func ReadConfig(data []byte) (*Config, error) {
96 109
 		config  Config
97 110
 	)
98 111
 
99
-	// Unmarshal (un-strictly) config version first for pre-validation
100
-	err := yaml.Unmarshal(data, &version)
112
+	// Unmarshal config version first for pre-validation
113
+	err := json.Unmarshal(data, &version)
101 114
 
102 115
 	if err != nil {
103 116
 		return nil, err
@@ -108,10 +121,12 @@ func ReadConfig(data []byte) (*Config, error) {
108 121
 	}
109 122
 
110 123
 	// Unmarshal the default config
111
-	yaml.Unmarshal([]byte(DefaultConfig), &config)
124
+	json.Unmarshal([]byte(DefaultConfig), &config)
112 125
 
113
-	// And finally strictly unmarshal the entire user-provided config
114
-	err = yaml.UnmarshalStrict(data, &config)
126
+	// And finally strictly decode the entire user-provided config
127
+	dec := json.NewDecoder(bytes.NewReader(data))
128
+	dec.DisallowUnknownFields()
129
+	err = dec.Decode(&config)
115 130
 
116 131
 	if err != nil {
117 132
 		return nil, err
@@ -132,5 +147,5 @@ func ReadConfigFile(path string) (*Config, error) {
132 147
 		return nil, err
133 148
 	}
134 149
 
135
-	return ReadConfig(data)
150
+	return ReadYAMLConfig(data)
136 151
 }

+ 9
- 11
config/reader_test.go View File

@@ -10,7 +10,7 @@ import (
10 10
 )
11 11
 
12 12
 func ExampleResolveIncludes() {
13
-	cfg, _ := config.ReadConfig([]byte(`---
13
+	cfg, _ := config.ReadYAMLConfig([]byte(`---
14 14
     version: v3
15 15
     variants:
16 16
       varA: { includes: [varB, varC] }
@@ -27,8 +27,8 @@ func ExampleResolveIncludes() {
27 27
 	// Output: [varF varD varE varB varC varA]
28 28
 }
29 29
 
30
-func TestReadConfigErrorsOnUnknownYAML(t *testing.T) {
31
-	_, err := config.ReadConfig([]byte(`---
30
+func TestReadYAMLConfigErrorsOnUnknownYAML(t *testing.T) {
31
+	_, err := config.ReadYAMLConfig([]byte(`---
32 32
     version: v3
33 33
     newphone: whodis
34 34
     variants:
@@ -36,13 +36,11 @@ func TestReadConfigErrorsOnUnknownYAML(t *testing.T) {
36 36
 
37 37
 	assert.EqualError(t,
38 38
 		err,
39
-		"yaml: unmarshal errors:\n"+
40
-			"  line 2: field newphone not found in struct config.Config",
41
-	)
39
+		`json: unknown field "newphone"`)
42 40
 }
43 41
 
44
-func TestReadConfigValidateVersionBeforeStrictUnmarshal(t *testing.T) {
45
-	_, err := config.ReadConfig([]byte(`---
42
+func TestReadYAMLConfigValidateVersionBeforeStrictUnmarshal(t *testing.T) {
43
+	_, err := config.ReadYAMLConfig([]byte(`---
46 44
     version: foo
47 45
     newphone: whodis
48 46
     variants:
@@ -56,7 +54,7 @@ func TestReadConfigValidateVersionBeforeStrictUnmarshal(t *testing.T) {
56 54
 }
57 55
 
58 56
 func TestResolveIncludesPreventsInfiniteRecursion(t *testing.T) {
59
-	cfg, err := config.ReadConfig([]byte(`---
57
+	cfg, err := config.ReadYAMLConfig([]byte(`---
60 58
     version: v3
61 59
     variants:
62 60
       varA: { includes: [varB] }
@@ -70,7 +68,7 @@ func TestResolveIncludesPreventsInfiniteRecursion(t *testing.T) {
70 68
 }
71 69
 
72 70
 func TestMultiLevelIncludes(t *testing.T) {
73
-	cfg, err := config.ReadConfig([]byte(`---
71
+	cfg, err := config.ReadYAMLConfig([]byte(`---
74 72
     version: v3
75 73
     base: foo-slim
76 74
     variants:
@@ -102,7 +100,7 @@ func TestMultiLevelIncludes(t *testing.T) {
102 100
 }
103 101
 
104 102
 func TestMultiIncludes(t *testing.T) {
105
-	cfg, err := config.ReadConfig([]byte(`---
103
+	cfg, err := config.ReadYAMLConfig([]byte(`---
106 104
     version: v3
107 105
     variants:
108 106
       mammal:

+ 3
- 3
config/runs.go View File

@@ -8,9 +8,9 @@ import (
8 8
 // runtime environment.
9 9
 //
10 10
 type RunsConfig struct {
11
-	UserConfig  `yaml:",inline"`
12
-	Insecurely  Flag              `yaml:"insecurely"`                     // runs user owns application files
13
-	Environment map[string]string `yaml:"environment" validate:"envvars"` // environment variables
11
+	UserConfig  `json:",inline"`
12
+	Insecurely  Flag              `json:"insecurely"`                     // runs user owns application files
13
+	Environment map[string]string `json:"environment" validate:"envvars"` // environment variables
14 14
 }
15 15
 
16 16
 // Merge takes another RunsConfig and overwrites this struct's fields. All

+ 1
- 1
config/runs_test.go View File

@@ -10,7 +10,7 @@ import (
10 10
 )
11 11
 
12 12
 func TestRunsConfigYAML(t *testing.T) {
13
-	cfg, err := config.ReadConfig([]byte(`---
13
+	cfg, err := config.ReadYAMLConfig([]byte(`---
14 14
     version: v3
15 15
     base: foo
16 16
     runs:

+ 3
- 3
config/user.go View File

@@ -3,9 +3,9 @@ package config
3 3
 // UserConfig holds configuration fields related to a user account.
4 4
 //
5 5
 type UserConfig struct {
6
-	As  string `yaml:"as" validate:"omitempty,username"` // user name
7
-	UID uint   `yaml:"uid"`                              // user ID
8
-	GID uint   `yaml:"gid"`                              // group ID
6
+	As  string `json:"as" validate:"omitempty,username"` // user name
7
+	UID uint   `json:"uid"`                              // user ID
8
+	GID uint   `json:"gid"`                              // group ID
9 9
 }
10 10
 
11 11
 // Merge takes another UserConfig and overwrites this struct's fields.

+ 3
- 3
config/validation.go View File

@@ -71,7 +71,7 @@ const rootCfgCtx ctxKey = iota
71 71
 func newValidator() *validator.Validate {
72 72
 	validate := validator.New()
73 73
 
74
-	validate.RegisterTagNameFunc(resolveYAMLTagName)
74
+	validate.RegisterTagNameFunc(resolveJSONTagName)
75 75
 
76 76
 	for name, tags := range validatorAliases {
77 77
 		validate.RegisterAlias(name, tags)
@@ -207,6 +207,6 @@ func isVariantReference(ctx context.Context, fl validator.FieldLevel) bool {
207 207
 	return false
208 208
 }
209 209
 
210
-func resolveYAMLTagName(field reflect.StructField) string {
211
-	return strings.SplitN(field.Tag.Get("yaml"), ",", 2)[0]
210
+func resolveJSONTagName(field reflect.StructField) string {
211
+	return strings.SplitN(field.Tag.Get("json"), ",", 2)[0]
212 212
 }

+ 4
- 4
config/variant.go View File

@@ -7,10 +7,10 @@ import (
7 7
 // VariantConfig holds configuration fields for each defined build variant.
8 8
 //
9 9
 type VariantConfig struct {
10
-	Includes     []string          `yaml:"includes" validate:"dive,variantref"`    // other variants
11
-	Copies       string            `yaml:"copies" validate:"omitempty,variantref"` // copy artifacts from variant
12
-	Artifacts    []ArtifactsConfig `yaml:"artifacts" validate:"dive"`              // artifact configuration
13
-	CommonConfig `yaml:",inline"`
10
+	Includes     []string          `json:"includes" validate:"dive,variantref"`    // other variants
11
+	Copies       string            `json:"copies" validate:"omitempty,variantref"` // copy artifacts from variant
12
+	Artifacts    []ArtifactsConfig `json:"artifacts" validate:"dive"`              // artifact configuration
13
+	CommonConfig `json:",inline"`
14 14
 }
15 15
 
16 16
 // Merge takes another VariantConfig and overwrites this struct's fields.

+ 7
- 7
config/variant_test.go View File

@@ -11,7 +11,7 @@ import (
11 11
 )
12 12
 
13 13
 func TestVariantConfigYAML(t *testing.T) {
14
-	cfg, err := config.ReadConfig([]byte(`---
14
+	cfg, err := config.ReadYAMLConfig([]byte(`---
15 15
     version: v3
16 16
     base: foo
17 17
     variants:
@@ -202,7 +202,7 @@ func TestVariantConfigInstructions(t *testing.T) {
202 202
 func TestVariantConfigValidation(t *testing.T) {
203 203
 	t.Run("includes", func(t *testing.T) {
204 204
 		t.Run("ok", func(t *testing.T) {
205
-			_, err := config.ReadConfig([]byte(`---
205
+			_, err := config.ReadYAMLConfig([]byte(`---
206 206
         version: v3
207 207
         variants:
208 208
           build: {}
@@ -212,7 +212,7 @@ func TestVariantConfigValidation(t *testing.T) {
212 212
 		})
213 213
 
214 214
 		t.Run("optional", func(t *testing.T) {
215
-			_, err := config.ReadConfig([]byte(`---
215
+			_, err := config.ReadYAMLConfig([]byte(`---
216 216
         version: v3
217 217
         variants:
218 218
           build: {}
@@ -222,7 +222,7 @@ func TestVariantConfigValidation(t *testing.T) {
222 222
 		})
223 223
 
224 224
 		t.Run("bad", func(t *testing.T) {
225
-			_, err := config.ReadConfig([]byte(`---
225
+			_, err := config.ReadYAMLConfig([]byte(`---
226 226
         version: v3
227 227
         variants:
228 228
           build: {}
@@ -242,7 +242,7 @@ func TestVariantConfigValidation(t *testing.T) {
242 242
 	t.Run("copies", func(t *testing.T) {
243 243
 
244 244
 		t.Run("ok", func(t *testing.T) {
245
-			_, err := config.ReadConfig([]byte(`---
245
+			_, err := config.ReadYAMLConfig([]byte(`---
246 246
         version: v3
247 247
         variants:
248 248
           build: {}
@@ -252,7 +252,7 @@ func TestVariantConfigValidation(t *testing.T) {
252 252
 		})
253 253
 
254 254
 		t.Run("optional", func(t *testing.T) {
255
-			_, err := config.ReadConfig([]byte(`---
255
+			_, err := config.ReadYAMLConfig([]byte(`---
256 256
         version: v3
257 257
         variants:
258 258
           build: {}
@@ -262,7 +262,7 @@ func TestVariantConfigValidation(t *testing.T) {
262 262
 		})
263 263
 
264 264
 		t.Run("bad", func(t *testing.T) {
265
-			_, err := config.ReadConfig([]byte(`---
265
+			_, err := config.ReadYAMLConfig([]byte(`---
266 266
         version: v3
267 267
         variants:
268 268
           build: {}

+ 1
- 1
config/version.go View File

@@ -8,5 +8,5 @@ const CurrentVersion string = "v3"
8 8
 // config version independent from an entire Config struct.
9 9
 //
10 10
 type VersionConfig struct {
11
-	Version string `yaml:"version" validate:"required,currentversion"`
11
+	Version string `json:"version" validate:"required,currentversion"`
12 12
 }

+ 1
- 1
config/version_test.go View File

@@ -9,7 +9,7 @@ import (
9 9
 )
10 10
 
11 11
 func TestVersionConfigYAML(t *testing.T) {
12
-	cfg, err := config.ReadConfig([]byte(`---
12
+	cfg, err := config.ReadYAMLConfig([]byte(`---
13 13
     version: v3
14 14
     variants:
15 15
       foo: {}`))

+ 4
- 4
docker/compiler_test.go View File

@@ -12,7 +12,7 @@ import (
12 12
 )
13 13
 
14 14
 func TestSingleStageHasNoName(t *testing.T) {
15
-	cfg, err := config.ReadConfig([]byte(`---
15
+	cfg, err := config.ReadYAMLConfig([]byte(`---
16 16
     version: v3
17 17
     base: foo/bar
18 18
     variants:
@@ -27,7 +27,7 @@ func TestSingleStageHasNoName(t *testing.T) {
27 27
 }
28 28
 
29 29
 func TestMultiStageIncludesStageNames(t *testing.T) {
30
-	cfg, err := config.ReadConfig([]byte(`---
30
+	cfg, err := config.ReadYAMLConfig([]byte(`---
31 31
     version: v3
32 32
     base: foo/bar
33 33
     variants:
@@ -51,7 +51,7 @@ func TestMultiStageIncludesStageNames(t *testing.T) {
51 51
 }
52 52
 
53 53
 func TestMultipleArtifactsFromSameStage(t *testing.T) {
54
-	cfg, err := config.ReadConfig([]byte(`---
54
+	cfg, err := config.ReadYAMLConfig([]byte(`---
55 55
     version: v3
56 56
     base: foo/bar
57 57
     variants:
@@ -78,7 +78,7 @@ func TestMultipleArtifactsFromSameStage(t *testing.T) {
78 78
 }
79 79
 
80 80
 func TestMetaDataLabels(t *testing.T) {
81
-	cfg, err := config.ReadConfig([]byte(`---
81
+	cfg, err := config.ReadYAMLConfig([]byte(`---
82 82
     version: v3
83 83
     base: foo/bar
84 84
     variants:

+ 0
- 22
vendor/github.com/davecgh/go-spew/.gitignore View File

@@ -1,22 +0,0 @@
1
-# Compiled Object files, Static and Dynamic libs (Shared Objects)
2
-*.o
3
-*.a
4
-*.so
5
-
6
-# Folders
7
-_obj
8
-_test
9
-
10
-# Architecture specific extensions/prefixes
11
-*.[568vq]
12
-[568vq].out
13
-
14
-*.cgo1.go
15
-*.cgo2.c
16
-_cgo_defun.c
17
-_cgo_gotypes.go
18
-_cgo_export.*
19
-
20
-_testmain.go
21
-
22
-*.exe

+ 0
- 14
vendor/github.com/davecgh/go-spew/.travis.yml View File

@@ -1,14 +0,0 @@
1
-language: go
2
-go:
3
-    - 1.5.4
4
-    - 1.6.3
5
-    - 1.7
6
-install:
7
-    - go get -v golang.org/x/tools/cmd/cover
8
-script:
9
-    - go test -v -tags=safe ./spew
10
-    - go test -v -tags=testcgo ./spew -covermode=count -coverprofile=profile.cov
11
-after_success:
12
-    - go get -v github.com/mattn/goveralls
13
-    - export PATH=$PATH:$HOME/gopath/bin
14
-    - goveralls -coverprofile=profile.cov -service=travis-ci

+ 0
- 205
vendor/github.com/davecgh/go-spew/README.md View File

@@ -1,205 +0,0 @@
1
-go-spew
2
-=======
3
-
4
-[![Build Status](https://img.shields.io/travis/davecgh/go-spew.svg)]
5
-(https://travis-ci.org/davecgh/go-spew) [![ISC License]
6
-(http://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org) [![Coverage Status]
7
-(https://img.shields.io/coveralls/davecgh/go-spew.svg)]
8
-(https://coveralls.io/r/davecgh/go-spew?branch=master)
9
-
10
-
11
-Go-spew implements a deep pretty printer for Go data structures to aid in
12
-debugging.  A comprehensive suite of tests with 100% test coverage is provided
13
-to ensure proper functionality.  See `test_coverage.txt` for the gocov coverage
14
-report.  Go-spew is licensed under the liberal ISC license, so it may be used in
15
-open source or commercial projects.
16
-
17
-If you're interested in reading about how this package came to life and some
18
-of the challenges involved in providing a deep pretty printer, there is a blog
19
-post about it
20
-[here](https://web.archive.org/web/20160304013555/https://blog.cyphertite.com/go-spew-a-journey-into-dumping-go-data-structures/).
21
-
22
-## Documentation
23
-
24
-[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)]
25
-(http://godoc.org/github.com/davecgh/go-spew/spew)
26
-
27
-Full `go doc` style documentation for the project can be viewed online without
28
-installing this package by using the excellent GoDoc site here:
29
-http://godoc.org/github.com/davecgh/go-spew/spew
30
-
31
-You can also view the documentation locally once the package is installed with
32
-the `godoc` tool by running `godoc -http=":6060"` and pointing your browser to
33
-http://localhost:6060/pkg/github.com/davecgh/go-spew/spew
34
-
35
-## Installation
36
-
37
-```bash
38
-$ go get -u github.com/davecgh/go-spew/spew
39
-```
40
-
41
-## Quick Start
42
-
43
-Add this import line to the file you're working in:
44
-
45
-```Go
46
-import "github.com/davecgh/go-spew/spew"
47
-```
48
-
49
-To dump a variable with full newlines, indentation, type, and pointer
50
-information use Dump, Fdump, or Sdump:
51
-
52
-```Go
53
-spew.Dump(myVar1, myVar2, ...)
54
-spew.Fdump(someWriter, myVar1, myVar2, ...)
55
-str := spew.Sdump(myVar1, myVar2, ...)
56
-```
57
-
58
-Alternatively, if you would prefer to use format strings with a compacted inline
59
-printing style, use the convenience wrappers Printf, Fprintf, etc with %v (most
60
-compact), %+v (adds pointer addresses), %#v (adds types), or %#+v (adds types
61
-and pointer addresses): 
62
-
63
-```Go
64
-spew.Printf("myVar1: %v -- myVar2: %+v", myVar1, myVar2)
65
-spew.Printf("myVar3: %#v -- myVar4: %#+v", myVar3, myVar4)
66
-spew.Fprintf(someWriter, "myVar1: %v -- myVar2: %+v", myVar1, myVar2)
67
-spew.Fprintf(someWriter, "myVar3: %#v -- myVar4: %#+v", myVar3, myVar4)
68
-```
69
-
70
-## Debugging a Web Application Example
71
-
72
-Here is an example of how you can use `spew.Sdump()` to help debug a web application. Please be sure to wrap your output using the `html.EscapeString()` function for safety reasons. You should also only use this debugging technique in a development environment, never in production.
73
-
74
-```Go
75
-package main
76
-
77
-import (
78
-    "fmt"
79
-    "html"
80
-    "net/http"
81
-
82
-    "github.com/davecgh/go-spew/spew"
83
-)
84
-
85
-func handler(w http.ResponseWriter, r *http.Request) {
86
-    w.Header().Set("Content-Type", "text/html")
87
-    fmt.Fprintf(w, "Hi there, %s!", r.URL.Path[1:])
88
-    fmt.Fprintf(w, "<!--\n" + html.EscapeString(spew.Sdump(w)) + "\n-->")
89
-}
90
-
91
-func main() {
92
-    http.HandleFunc("/", handler)
93
-    http.ListenAndServe(":8080", nil)
94
-}
95
-```
96
-
97
-## Sample Dump Output
98
-
99
-```
100
-(main.Foo) {
101
- unexportedField: (*main.Bar)(0xf84002e210)({
102
-  flag: (main.Flag) flagTwo,
103
-  data: (uintptr) <nil>
104
- }),
105
- ExportedField: (map[interface {}]interface {}) {
106
-  (string) "one": (bool) true
107
- }
108
-}
109
-([]uint8) {
110
- 00000000  11 12 13 14 15 16 17 18  19 1a 1b 1c 1d 1e 1f 20  |............... |
111
- 00000010  21 22 23 24 25 26 27 28  29 2a 2b 2c 2d 2e 2f 30  |!"#$%&'()*+,-./0|
112
- 00000020  31 32                                             |12|
113
-}
114
-```
115
-
116
-## Sample Formatter Output
117
-
118
-Double pointer to a uint8:
119
-```
120
-	  %v: <**>5
121
-	 %+v: <**>(0xf8400420d0->0xf8400420c8)5
122
-	 %#v: (**uint8)5
123
-	%#+v: (**uint8)(0xf8400420d0->0xf8400420c8)5
124
-```
125
-
126
-Pointer to circular struct with a uint8 field and a pointer to itself:
127
-```
128
-	  %v: <*>{1 <*><shown>}
129
-	 %+v: <*>(0xf84003e260){ui8:1 c:<*>(0xf84003e260)<shown>}
130
-	 %#v: (*main.circular){ui8:(uint8)1 c:(*main.circular)<shown>}
131
-	%#+v: (*main.circular)(0xf84003e260){ui8:(uint8)1 c:(*main.circular)(0xf84003e260)<shown>}
132
-```
133
-
134
-## Configuration Options
135
-
136
-Configuration of spew is handled by fields in the ConfigState type. For
137
-convenience, all of the top-level functions use a global state available via the
138
-spew.Config global.
139
-
140
-It is also possible to create a ConfigState instance that provides methods
141
-equivalent to the top-level functions. This allows concurrent configuration
142
-options. See the ConfigState documentation for more details.
143
-
144
-```
145
-* Indent
146
-	String to use for each indentation level for Dump functions.
147
-	It is a single space by default.  A popular alternative is "\t".
148
-
149
-* MaxDepth
150
-	Maximum number of levels to descend into nested data structures.
151
-	There is no limit by default.
152
-
153
-* DisableMethods
154
-	Disables invocation of error and Stringer interface methods.
155
-	Method invocation is enabled by default.
156
-
157
-* DisablePointerMethods
158
-	Disables invocation of error and Stringer interface methods on types
159
-	which only accept pointer receivers from non-pointer variables.  This option
160
-	relies on access to the unsafe package, so it will not have any effect when
161
-	running in environments without access to the unsafe package such as Google
162
-	App Engine or with the "safe" build tag specified.
163
-	Pointer method invocation is enabled by default.
164
-
165
-* DisablePointerAddresses
166
-	DisablePointerAddresses specifies whether to disable the printing of
167
-	pointer addresses. This is useful when diffing data structures in tests.
168
-
169
-* DisableCapacities
170
-	DisableCapacities specifies whether to disable the printing of capacities
171
-	for arrays, slices, maps and channels. This is useful when diffing data
172
-	structures in tests.
173
-
174
-* ContinueOnMethod
175
-	Enables recursion into types after invoking error and Stringer interface
176
-	methods. Recursion after method invocation is disabled by default.
177
-
178
-* SortKeys
179
-	Specifies map keys should be sorted before being printed. Use
180
-	this to have a more deterministic, diffable output.  Note that
181
-	only native types (bool, int, uint, floats, uintptr and string)
182
-	and types which implement error or Stringer interfaces are supported,
183
-	with other types sorted according to the reflect.Value.String() output
184
-	which guarantees display stability.  Natural map order is used by
185
-	default.
186
-
187
-* SpewKeys
188
-	SpewKeys specifies that, as a last resort attempt, map keys should be
189
-	spewed to strings and sorted by those strings.  This is only considered
190
-	if SortKeys is true.
191
-
192
-```
193
-
194
-## Unsafe Package Dependency
195
-
196
-This package relies on the unsafe package to perform some of the more advanced
197
-features, however it also supports a "limited" mode which allows it to work in
198
-environments where the unsafe package is not available.  By default, it will
199
-operate in this mode on Google App Engine and when compiled with GopherJS.  The
200
-"safe" build tag may also be specified to force the package to build without
201
-using the unsafe package.
202
-
203
-## License
204
-
205
-Go-spew is licensed under the [copyfree](http://copyfree.org) ISC License.

+ 0
- 22
vendor/github.com/davecgh/go-spew/cov_report.sh View File

@@ -1,22 +0,0 @@
1
-#!/bin/sh
2
-
3
-# This script uses gocov to generate a test coverage report.
4
-# The gocov tool my be obtained with the following command:
5
-#   go get github.com/axw/gocov/gocov
6
-#
7
-# It will be installed to $GOPATH/bin, so ensure that location is in your $PATH.
8
-
9
-# Check for gocov.
10
-if ! type gocov >/dev/null 2>&1; then
11
-	echo >&2 "This script requires the gocov tool."
12
-	echo >&2 "You may obtain it with the following command:"
13
-	echo >&2 "go get github.com/axw/gocov/gocov"
14
-	exit 1
15
-fi
16
-
17
-# Only run the cgo tests if gcc is installed.
18
-if type gcc >/dev/null 2>&1; then
19
-	(cd spew && gocov test -tags testcgo | gocov report)
20
-else
21
-	(cd spew && gocov test | gocov report)
22
-fi

+ 0
- 298
vendor/github.com/davecgh/go-spew/spew/common_test.go View File

@@ -1,298 +0,0 @@
1
-/*
2
- * Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
3
- *
4
- * Permission to use, copy, modify, and distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
-package spew_test
18
-
19
-import (
20
-	"fmt"
21
-	"reflect"
22
-	"testing"
23
-
24
-	"github.com/davecgh/go-spew/spew"
25
-)
26
-
27
-// custom type to test Stinger interface on non-pointer receiver.
28
-type stringer string
29
-
30
-// String implements the Stringer interface for testing invocation of custom
31
-// stringers on types with non-pointer receivers.
32
-func (s stringer) String() string {
33
-	return "stringer " + string(s)
34
-}
35
-
36
-// custom type to test Stinger interface on pointer receiver.
37
-type pstringer string
38
-
39
-// String implements the Stringer interface for testing invocation of custom
40
-// stringers on types with only pointer receivers.
41
-func (s *pstringer) String() string {
42
-	return "stringer " + string(*s)
43
-}
44
-
45
-// xref1 and xref2 are cross referencing structs for testing circular reference
46
-// detection.
47
-type xref1 struct {
48
-	ps2 *xref2
49
-}
50
-type xref2 struct {
51
-	ps1 *xref1
52
-}
53
-
54
-// indirCir1, indirCir2, and indirCir3 are used to generate an indirect circular
55
-// reference for testing detection.
56
-type indirCir1 struct {
57
-	ps2 *indirCir2
58
-}
59
-type indirCir2 struct {
60
-	ps3 *indirCir3
61
-}
62
-type indirCir3 struct {
63
-	ps1 *indirCir1
64
-}
65
-
66
-// embed is used to test embedded structures.
67
-type embed struct {
68
-	a string
69
-}
70
-
71
-// embedwrap is used to test embedded structures.
72
-type embedwrap struct {
73
-	*embed
74
-	e *embed
75
-}
76
-
77
-// panicer is used to intentionally cause a panic for testing spew properly
78
-// handles them
79
-type panicer int
80
-
81
-func (p panicer) String() string {
82
-	panic("test panic")
83
-}
84
-
85
-// customError is used to test custom error interface invocation.
86
-type customError int
87
-
88
-func (e customError) Error() string {
89
-	return fmt.Sprintf("error: %d", int(e))
90
-}
91
-
92
-// stringizeWants converts a slice of wanted test output into a format suitable
93
-// for a test error message.
94
-func stringizeWants(wants []string) string {
95
-	s := ""
96
-	for i, want := range wants {
97
-		if i > 0 {
98
-			s += fmt.Sprintf("want%d: %s", i+1, want)
99
-		} else {
100
-			s += "want: " + want
101
-		}
102
-	}
103
-	return s
104
-}
105
-
106
-// testFailed returns whether or not a test failed by checking if the result
107
-// of the test is in the slice of wanted strings.
108
-func testFailed(result string, wants []string) bool {
109
-	for _, want := range wants {
110
-		if result == want {
111
-			return false
112
-		}
113
-	}
114
-	return true
115
-}
116
-
117
-type sortableStruct struct {
118
-	x int
119
-}
120
-
121
-func (ss sortableStruct) String() string {
122
-	return fmt.Sprintf("ss.%d", ss.x)
123
-}
124
-
125
-type unsortableStruct struct {
126
-	x int
127
-}
128
-
129
-type sortTestCase struct {
130
-	input    []reflect.Value
131
-	expected []reflect.Value
132
-}
133
-
134
-func helpTestSortValues(tests []sortTestCase, cs *spew.ConfigState, t *testing.T) {
135
-	getInterfaces := func(values []reflect.Value) []interface{} {
136
-		interfaces := []interface{}{}
137
-		for _, v := range values {
138
-			interfaces = append(interfaces, v.Interface())
139
-		}
140
-		return interfaces
141
-	}
142
-
143
-	for _, test := range tests {
144
-		spew.SortValues(test.input, cs)
145
-		// reflect.DeepEqual cannot really make sense of reflect.Value,
146
-		// probably because of all the pointer tricks. For instance,
147
-		// v(2.0) != v(2.0) on a 32-bits system. Turn them into interface{}
148
-		// instead.
149
-		input := getInterfaces(test.input)
150
-		expected := getInterfaces(test.expected)
151
-		if !reflect.DeepEqual(input, expected) {
152
-			t.Errorf("Sort mismatch:\n %v != %v", input, expected)
153
-		}
154
-	}
155
-}
156
-
157
-// TestSortValues ensures the sort functionality for relect.Value based sorting
158
-// works as intended.
159
-func TestSortValues(t *testing.T) {
160
-	v := reflect.ValueOf
161
-
162
-	a := v("a")
163
-	b := v("b")
164
-	c := v("c")
165
-	embedA := v(embed{"a"})
166
-	embedB := v(embed{"b"})
167
-	embedC := v(embed{"c"})
168
-	tests := []sortTestCase{
169
-		// No values.
170
-		{
171
-			[]reflect.Value{},
172
-			[]reflect.Value{},
173
-		},
174
-		// Bools.
175
-		{
176
-			[]reflect.Value{v(false), v(true), v(false)},
177
-			[]reflect.Value{v(false), v(false), v(true)},
178
-		},
179
-		// Ints.
180
-		{
181
-			[]reflect.Value{v(2), v(1), v(3)},
182
-			[]reflect.Value{v(1), v(2), v(3)},
183
-		},
184
-		// Uints.
185
-		{
186
-			[]reflect.Value{v(uint8(2)), v(uint8(1)), v(uint8(3))},
187
-			[]reflect.Value{v(uint8(1)), v(uint8(2)), v(uint8(3))},
188
-		},
189
-		// Floats.
190
-		{
191
-			[]reflect.Value{v(2.0), v(1.0), v(3.0)},
192
-			[]reflect.Value{v(1.0), v(2.0), v(3.0)},
193
-		},
194
-		// Strings.
195
-		{
196
-			[]reflect.Value{b, a, c},
197
-			[]reflect.Value{a, b, c},
198
-		},
199
-		// Array
200
-		{
201
-			[]reflect.Value{v([3]int{3, 2, 1}), v([3]int{1, 3, 2}), v([3]int{1, 2, 3})},
202
-			[]reflect.Value{v([3]int{1, 2, 3}), v([3]int{1, 3, 2}), v([3]int{3, 2, 1})},
203
-		},
204
-		// Uintptrs.
205
-		{
206
-			[]reflect.Value{v(uintptr(2)), v(uintptr(1)), v(uintptr(3))},
207
-			[]reflect.Value{v(uintptr(1)), v(uintptr(2)), v(uintptr(3))},
208
-		},
209
-		// SortableStructs.
210
-		{
211
-			// Note: not sorted - DisableMethods is set.
212
-			[]reflect.Value{v(sortableStruct{2}), v(sortableStruct{1}), v(sortableStruct{3})},
213
-			[]reflect.Value{v(sortableStruct{2}), v(sortableStruct{1}), v(sortableStruct{3})},
214
-		},
215
-		// UnsortableStructs.
216
-		{
217
-			// Note: not sorted - SpewKeys is false.
218
-			[]reflect.Value{v(unsortableStruct{2}), v(unsortableStruct{1}), v(unsortableStruct{3})},
219
-			[]reflect.Value{v(unsortableStruct{2}), v(unsortableStruct{1}), v(unsortableStruct{3})},
220
-		},
221
-		// Invalid.
222
-		{
223
-			[]reflect.Value{embedB, embedA, embedC},
224
-			[]reflect.Value{embedB, embedA, embedC},
225
-		},
226
-	}
227
-	cs := spew.ConfigState{DisableMethods: true, SpewKeys: false}
228
-	helpTestSortValues(tests, &cs, t)
229
-}
230
-
231
-// TestSortValuesWithMethods ensures the sort functionality for relect.Value
232
-// based sorting works as intended when using string methods.
233
-func TestSortValuesWithMethods(t *testing.T) {
234
-	v := reflect.ValueOf
235
-
236
-	a := v("a")
237
-	b := v("b")
238
-	c := v("c")
239
-	tests := []sortTestCase{
240
-		// Ints.
241
-		{
242
-			[]reflect.Value{v(2), v(1), v(3)},
243
-			[]reflect.Value{v(1), v(2), v(3)},
244
-		},
245
-		// Strings.
246
-		{
247
-			[]reflect.Value{b, a, c},
248
-			[]reflect.Value{a, b, c},
249
-		},
250
-		// SortableStructs.
251
-		{
252
-			[]reflect.Value{v(sortableStruct{2}), v(sortableStruct{1}), v(sortableStruct{3})},
253
-			[]reflect.Value{v(sortableStruct{1}), v(sortableStruct{2}), v(sortableStruct{3})},
254
-		},
255
-		// UnsortableStructs.
256
-		{
257
-			// Note: not sorted - SpewKeys is false.
258
-			[]reflect.Value{v(unsortableStruct{2}), v(unsortableStruct{1}), v(unsortableStruct{3})},
259
-			[]reflect.Value{v(unsortableStruct{2}), v(unsortableStruct{1}), v(unsortableStruct{3})},
260
-		},
261
-	}
262
-	cs := spew.ConfigState{DisableMethods: false, SpewKeys: false}
263
-	helpTestSortValues(tests, &cs, t)
264
-}
265
-
266
-// TestSortValuesWithSpew ensures the sort functionality for relect.Value
267
-// based sorting works as intended when using spew to stringify keys.
268
-func TestSortValuesWithSpew(t *testing.T) {
269
-	v := reflect.ValueOf
270
-
271
-	a := v("a")
272
-	b := v("b")
273
-	c := v("c")
274
-	tests := []sortTestCase{
275
-		// Ints.
276
-		{
277
-			[]reflect.Value{v(2), v(1), v(3)},
278
-			[]reflect.Value{v(1), v(2), v(3)},
279
-		},
280
-		// Strings.
281
-		{
282
-			[]reflect.Value{b, a, c},
283
-			[]reflect.Value{a, b, c},
284
-		},
285
-		// SortableStructs.
286
-		{
287
-			[]reflect.Value{v(sortableStruct{2}), v(sortableStruct{1}), v(sortableStruct{3})},
288
-			[]reflect.Value{v(sortableStruct{1}), v(sortableStruct{2}), v(sortableStruct{3})},
289
-		},
290
-		// UnsortableStructs.
291
-		{
292
-			[]reflect.Value{v(unsortableStruct{2}), v(unsortableStruct{1}), v(unsortableStruct{3})},
293
-			[]reflect.Value{v(unsortableStruct{1}), v(unsortableStruct{2}), v(unsortableStruct{3})},
294
-		},
295
-	}
296
-	cs := spew.ConfigState{DisableMethods: true, SpewKeys: true}
297
-	helpTestSortValues(tests, &cs, t)
298
-}

+ 0
- 1042
vendor/github.com/davecgh/go-spew/spew/dump_test.go
File diff suppressed because it is too large
View File


+ 0
- 99
vendor/github.com/davecgh/go-spew/spew/dumpcgo_test.go View File

@@ -1,99 +0,0 @@
1
-// Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
2
-//
3
-// Permission to use, copy, modify, and distribute this software for any
4
-// purpose with or without fee is hereby granted, provided that the above
5
-// copyright notice and this permission notice appear in all copies.
6
-//
7
-// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
-// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
-// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
-// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
-// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
-// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
-// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
-
15
-// NOTE: Due to the following build constraints, this file will only be compiled
16
-// when both cgo is supported and "-tags testcgo" is added to the go test
17
-// command line.  This means the cgo tests are only added (and hence run) when
18
-// specifially requested.  This configuration is used because spew itself
19
-// does not require cgo to run even though it does handle certain cgo types
20
-// specially.  Rather than forcing all clients to require cgo and an external
21
-// C compiler just to run the tests, this scheme makes them optional.
22
-// +build cgo,testcgo
23
-
24
-package spew_test
25
-
26
-import (
27
-	"fmt"
28
-
29
-	"github.com/davecgh/go-spew/spew/testdata"
30
-)
31
-
32
-func addCgoDumpTests() {
33
-	// C char pointer.
34
-	v := testdata.GetCgoCharPointer()
35
-	nv := testdata.GetCgoNullCharPointer()
36
-	pv := &v
37
-	vcAddr := fmt.Sprintf("%p", v)
38
-	vAddr := fmt.Sprintf("%p", pv)
39
-	pvAddr := fmt.Sprintf("%p", &pv)
40
-	vt := "*testdata._Ctype_char"
41
-	vs := "116"
42
-	addDumpTest(v, "("+vt+")("+vcAddr+")("+vs+")\n")
43
-	addDumpTest(pv, "(*"+vt+")("+vAddr+"->"+vcAddr+")("+vs+")\n")
44
-	addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+"->"+vcAddr+")("+vs+")\n")
45
-	addDumpTest(nv, "("+vt+")(<nil>)\n")
46
-
47
-	// C char array.
48
-	v2, v2l, v2c := testdata.GetCgoCharArray()
49
-	v2Len := fmt.Sprintf("%d", v2l)
50
-	v2Cap := fmt.Sprintf("%d", v2c)
51
-	v2t := "[6]testdata._Ctype_char"
52
-	v2s := "(len=" + v2Len + " cap=" + v2Cap + ") " +
53
-		"{\n 00000000  74 65 73 74 32 00                               " +
54
-		"  |test2.|\n}"
55
-	addDumpTest(v2, "("+v2t+") "+v2s+"\n")
56
-
57
-	// C unsigned char array.
58
-	v3, v3l, v3c := testdata.GetCgoUnsignedCharArray()
59
-	v3Len := fmt.Sprintf("%d", v3l)
60
-	v3Cap := fmt.Sprintf("%d", v3c)
61
-	v3t := "[6]testdata._Ctype_unsignedchar"
62
-	v3t2 := "[6]testdata._Ctype_uchar"
63
-	v3s := "(len=" + v3Len + " cap=" + v3Cap + ") " +
64
-		"{\n 00000000  74 65 73 74 33 00                               " +
65
-		"  |test3.|\n}"
66
-	addDumpTest(v3, "("+v3t+") "+v3s+"\n", "("+v3t2+") "+v3s+"\n")
67
-
68
-	// C signed char array.
69
-	v4, v4l, v4c := testdata.GetCgoSignedCharArray()
70
-	v4Len := fmt.Sprintf("%d", v4l)
71
-	v4Cap := fmt.Sprintf("%d", v4c)
72
-	v4t := "[6]testdata._Ctype_schar"
73
-	v4t2 := "testdata._Ctype_schar"
74
-	v4s := "(len=" + v4Len + " cap=" + v4Cap + ") " +
75
-		"{\n (" + v4t2 + ") 116,\n (" + v4t2 + ") 101,\n (" + v4t2 +
76
-		") 115,\n (" + v4t2 + ") 116,\n (" + v4t2 + ") 52,\n (" + v4t2 +
77
-		") 0\n}"
78
-	addDumpTest(v4, "("+v4t+") "+v4s+"\n")
79
-
80
-	// C uint8_t array.
81
-	v5, v5l, v5c := testdata.GetCgoUint8tArray()
82
-	v5Len := fmt.Sprintf("%d", v5l)
83
-	v5Cap := fmt.Sprintf("%d", v5c)
84
-	v5t := "[6]testdata._Ctype_uint8_t"
85
-	v5s := "(len=" + v5Len + " cap=" + v5Cap + ") " +
86
-		"{\n 00000000  74 65 73 74 35 00                               " +
87
-		"  |test5.|\n}"
88
-	addDumpTest(v5, "("+v5t+") "+v5s+"\n")
89
-
90
-	// C typedefed unsigned char array.
91
-	v6, v6l, v6c := testdata.GetCgoTypdefedUnsignedCharArray()
92
-	v6Len := fmt.Sprintf("%d", v6l)
93
-	v6Cap := fmt.Sprintf("%d", v6c)
94
-	v6t := "[6]testdata._Ctype_custom_uchar_t"
95
-	v6s := "(len=" + v6Len + " cap=" + v6Cap + ") " +
96
-		"{\n 00000000  74 65 73 74 36 00                               " +
97
-		"  |test6.|\n}"
98
-	addDumpTest(v6, "("+v6t+") "+v6s+"\n")
99
-}

+ 0
- 26
vendor/github.com/davecgh/go-spew/spew/dumpnocgo_test.go View File

@@ -1,26 +0,0 @@
1
-// Copyright (c) 2013 Dave Collins <dave@davec.name>
2
-//
3
-// Permission to use, copy, modify, and distribute this software for any
4
-// purpose with or without fee is hereby granted, provided that the above
5
-// copyright notice and this permission notice appear in all copies.
6
-//
7
-// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
-// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
-// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
-// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
-// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
-// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
-// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
-
15
-// NOTE: Due to the following build constraints, this file will only be compiled
16
-// when either cgo is not supported or "-tags testcgo" is not added to the go
17
-// test command line.  This file intentionally does not setup any cgo tests in
18
-// this scenario.
19
-// +build !cgo !testcgo
20
-
21
-package spew_test
22
-
23
-func addCgoDumpTests() {
24
-	// Don't add any tests for cgo since this file is only compiled when
25
-	// there should not be any cgo tests.
26
-}

+ 0
- 226
vendor/github.com/davecgh/go-spew/spew/example_test.go View File

@@ -1,226 +0,0 @@
1
-/*
2
- * Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
3
- *
4
- * Permission to use, copy, modify, and distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
-package spew_test
18
-
19
-import (
20
-	"fmt"
21
-
22
-	"github.com/davecgh/go-spew/spew"
23
-)
24
-
25
-type Flag int
26
-
27
-const (
28
-	flagOne Flag = iota
29
-	flagTwo
30
-)
31
-
32
-var flagStrings = map[Flag]string{
33
-	flagOne: "flagOne",
34
-	flagTwo: "flagTwo",
35
-}
36
-
37
-func (f Flag) String() string {
38
-	if s, ok := flagStrings[f]; ok {
39
-		return s
40
-	}
41
-	return fmt.Sprintf("Unknown flag (%d)", int(f))
42
-}
43
-
44
-type Bar struct {
45
-	data uintptr
46
-}
47
-
48
-type Foo struct {
49
-	unexportedField Bar
50
-	ExportedField   map[interface{}]interface{}
51
-}
52
-
53
-// This example demonstrates how to use Dump to dump variables to stdout.
54
-func ExampleDump() {
55
-	// The following package level declarations are assumed for this example:
56
-	/*
57
-		type Flag int
58
-
59
-		const (
60
-			flagOne Flag = iota
61
-			flagTwo
62
-		)
63
-
64
-		var flagStrings = map[Flag]string{
65
-			flagOne: "flagOne",
66
-			flagTwo: "flagTwo",
67
-		}
68
-
69
-		func (f Flag) String() string {
70
-			if s, ok := flagStrings[f]; ok {
71
-				return s
72
-			}
73
-			return fmt.Sprintf("Unknown flag (%d)", int(f))
74
-		}
75
-
76
-		type Bar struct {
77
-			data uintptr
78
-		}
79
-
80
-		type Foo struct {
81
-			unexportedField Bar
82
-			ExportedField   map[interface{}]interface{}
83
-		}
84
-	*/
85
-
86
-	// Setup some sample data structures for the example.
87
-	bar := Bar{uintptr(0)}
88
-	s1 := Foo{bar, map[interface{}]interface{}{"one": true}}
89
-	f := Flag(5)
90
-	b := []byte{
91
-		0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
92
-		0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
93
-		0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
94
-		0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
95
-		0x31, 0x32,
96
-	}
97
-
98
-	// Dump!
99
-	spew.Dump(s1, f, b)
100
-
101
-	// Output:
102
-	// (spew_test.Foo) {
103
-	//  unexportedField: (spew_test.Bar) {
104
-	//   data: (uintptr) <nil>
105
-	//  },
106
-	//  ExportedField: (map[interface {}]interface {}) (len=1) {
107
-	//   (string) (len=3) "one": (bool) true
108
-	//  }
109
-	// }
110
-	// (spew_test.Flag) Unknown flag (5)
111
-	// ([]uint8) (len=34 cap=34) {
112
-	//  00000000  11 12 13 14 15 16 17 18  19 1a 1b 1c 1d 1e 1f 20  |............... |
113
-	//  00000010  21 22 23 24 25 26 27 28  29 2a 2b 2c 2d 2e 2f 30  |!"#$%&'()*+,-./0|
114
-	//  00000020  31 32                                             |12|
115
-	// }
116
-	//
117
-}
118
-
119
-// This example demonstrates how to use Printf to display a variable with a
120
-// format string and inline formatting.
121
-func ExamplePrintf() {
122
-	// Create a double pointer to a uint 8.
123
-	ui8 := uint8(5)
124
-	pui8 := &ui8
125
-	ppui8 := &pui8
126
-
127
-	// Create a circular data type.
128
-	type circular struct {
129
-		ui8 uint8
130
-		c   *circular
131
-	}
132
-	c := circular{ui8: 1}
133
-	c.c = &c
134
-
135
-	// Print!
136
-	spew.Printf("ppui8: %v\n", ppui8)
137
-	spew.Printf("circular: %v\n", c)
138
-
139
-	// Output:
140
-	// ppui8: <**>5
141
-	// circular: {1 <*>{1 <*><shown>}}
142
-}
143
-
144
-// This example demonstrates how to use a ConfigState.
145
-func ExampleConfigState() {
146
-	// Modify the indent level of the ConfigState only.  The global
147
-	// configuration is not modified.
148
-	scs := spew.ConfigState{Indent: "\t"}
149
-
150
-	// Output using the ConfigState instance.
151
-	v := map[string]int{"one": 1}
152
-	scs.Printf("v: %v\n", v)
153
-	scs.Dump(v)
154
-
155
-	// Output:
156
-	// v: map[one:1]
157
-	// (map[string]int) (len=1) {
158
-	// 	(string) (len=3) "one": (int) 1
159
-	// }
160
-}
161
-
162
-// This example demonstrates how to use ConfigState.Dump to dump variables to
163
-// stdout
164
-func ExampleConfigState_Dump() {
165
-	// See the top-level Dump example for details on the types used in this
166
-	// example.
167
-
168
-	// Create two ConfigState instances with different indentation.
169
-	scs := spew.ConfigState{Indent: "\t"}
170
-	scs2 := spew.ConfigState{Indent: " "}
171
-
172
-	// Setup some sample data structures for the example.
173
-	bar := Bar{uintptr(0)}
174
-	s1 := Foo{bar, map[interface{}]interface{}{"one": true}}
175
-
176
-	// Dump using the ConfigState instances.
177
-	scs.Dump(s1)
178
-	scs2.Dump(s1)
179
-
180
-	// Output:
181
-	// (spew_test.Foo) {
182
-	// 	unexportedField: (spew_test.Bar) {
183
-	// 		data: (uintptr) <nil>
184
-	// 	},
185
-	// 	ExportedField: (map[interface {}]interface {}) (len=1) {
186
-	//		(string) (len=3) "one": (bool) true
187
-	// 	}
188
-	// }
189
-	// (spew_test.Foo) {
190
-	//  unexportedField: (spew_test.Bar) {
191
-	//   data: (uintptr) <nil>
192
-	//  },
193
-	//  ExportedField: (map[interface {}]interface {}) (len=1) {
194
-	//   (string) (len=3) "one": (bool) true
195
-	//  }
196
-	// }
197
-	//
198
-}
199
-
200
-// This example demonstrates how to use ConfigState.Printf to display a variable
201
-// with a format string and inline formatting.
202
-func ExampleConfigState_Printf() {
203
-	// See the top-level Dump example for details on the types used in this
204
-	// example.
205
-
206
-	// Create two ConfigState instances and modify the method handling of the
207
-	// first ConfigState only.
208
-	scs := spew.NewDefaultConfig()
209
-	scs2 := spew.NewDefaultConfig()
210
-	scs.DisableMethods = true
211
-
212
-	// Alternatively
213
-	// scs := spew.ConfigState{Indent: " ", DisableMethods: true}
214
-	// scs2 := spew.ConfigState{Indent: " "}
215
-
216
-	// This is of type Flag which implements a Stringer and has raw value 1.
217
-	f := flagTwo
218
-
219
-	// Dump using the ConfigState instances.
220
-	scs.Printf("f: %v\n", f)
221
-	scs2.Printf("f: %v\n", f)
222
-
223
-	// Output:
224
-	// f: 1
225
-	// f: flagTwo
226
-}

+ 0
- 1558
vendor/github.com/davecgh/go-spew/spew/format_test.go
File diff suppressed because it is too large
View File


+ 0
- 87
vendor/github.com/davecgh/go-spew/spew/internal_test.go View File

@@ -1,87 +0,0 @@
1
-/*
2
- * Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
3
- *
4
- * Permission to use, copy, modify, and distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
-/*
18
-This test file is part of the spew package rather than than the spew_test
19
-package because it needs access to internals to properly test certain cases
20
-which are not possible via the public interface since they should never happen.
21
-*/
22
-
23
-package spew
24
-
25
-import (
26
-	"bytes"
27
-	"reflect"
28
-	"testing"
29
-)
30
-
31
-// dummyFmtState implements a fake fmt.State to use for testing invalid
32
-// reflect.Value handling.  This is necessary because the fmt package catches
33
-// invalid values before invoking the formatter on them.
34
-type dummyFmtState struct {
35
-	bytes.Buffer
36
-}
37
-
38
-func (dfs *dummyFmtState) Flag(f int) bool {
39
-	if f == int('+') {
40
-		return true
41
-	}
42
-	return false
43
-}
44
-
45
-func (dfs *dummyFmtState) Precision() (int, bool) {
46
-	return 0, false
47
-}
48
-
49
-func (dfs *dummyFmtState) Width() (int, bool) {
50
-	return 0, false
51
-}
52
-
53
-// TestInvalidReflectValue ensures the dump and formatter code handles an
54
-// invalid reflect value properly.  This needs access to internal state since it
55
-// should never happen in real code and therefore can't be tested via the public
56
-// API.
57
-func TestInvalidReflectValue(t *testing.T) {
58
-	i := 1
59
-
60
-	// Dump invalid reflect value.
61
-	v := new(reflect.Value)
62
-	buf := new(bytes.Buffer)
63
-	d := dumpState{w: buf, cs: &Config}
64
-	d.dump(*v)
65
-	s := buf.String()
66
-	want := "<invalid>"
67
-	if s != want {
68
-		t.Errorf("InvalidReflectValue #%d\n got: %s want: %s", i, s, want)
69
-	}
70
-	i++
71
-
72
-	// Formatter invalid reflect value.
73
-	buf2 := new(dummyFmtState)
74
-	f := formatState{value: *v, cs: &Config, fs: buf2}
75
-	f.format(*v)
76
-	s = buf2.String()
77
-	want = "<invalid>"
78
-	if s != want {
79
-		t.Errorf("InvalidReflectValue #%d got: %s want: %s", i, s, want)
80
-	}
81
-}
82
-
83
-// SortValues makes the internal sortValues function available to the test
84
-// package.
85
-func SortValues(values []reflect.Value, cs *ConfigState) {
86
-	sortValues(values, cs)
87
-}

+ 0
- 102
vendor/github.com/davecgh/go-spew/spew/internalunsafe_test.go View File

@@ -1,102 +0,0 @@
1
-// Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
2
-
3
-// Permission to use, copy, modify, and distribute this software for any
4
-// purpose with or without fee is hereby granted, provided that the above
5
-// copyright notice and this permission notice appear in all copies.
6
-
7
-// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
-// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
-// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
-// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
-// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
-// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
-// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
-
15
-// NOTE: Due to the following build constraints, this file will only be compiled
16
-// when the code is not running on Google App Engine, compiled by GopherJS, and
17
-// "-tags safe" is not added to the go build command line.  The "disableunsafe"
18
-// tag is deprecated and thus should not be used.
19
-// +build !js,!appengine,!safe,!disableunsafe
20
-
21
-/*
22
-This test file is part of the spew package rather than than the spew_test
23
-package because it needs access to internals to properly test certain cases
24
-which are not possible via the public interface since they should never happen.
25
-*/
26
-
27
-package spew
28
-
29
-import (
30
-	"bytes"
31
-	"reflect"
32
-	"testing"
33
-	"unsafe"
34
-)
35
-
36
-// changeKind uses unsafe to intentionally change the kind of a reflect.Value to
37
-// the maximum kind value which does not exist.  This is needed to test the
38
-// fallback code which punts to the standard fmt library for new types that
39
-// might get added to the language.
40
-func changeKind(v *reflect.Value, readOnly bool) {
41
-	rvf := (*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(v)) + offsetFlag))
42
-	*rvf = *rvf | ((1<<flagKindWidth - 1) << flagKindShift)
43
-	if readOnly {
44
-		*rvf |= flagRO
45
-	} else {
46
-		*rvf &= ^uintptr(flagRO)
47
-	}
48
-}
49
-
50
-// TestAddedReflectValue tests functionaly of the dump and formatter code which
51
-// falls back to the standard fmt library for new types that might get added to
52
-// the language.
53
-func TestAddedReflectValue(t *testing.T) {
54
-	i := 1
55
-
56
-	// Dump using a reflect.Value that is exported.
57
-	v := reflect.ValueOf(int8(5))
58
-	changeKind(&v, false)
59
-	buf := new(bytes.Buffer)
60
-	d := dumpState{w: buf, cs: &Config}
61
-	d.dump(v)
62
-	s := buf.String()
63
-	want := "(int8) 5"
64
-	if s != want {
65
-		t.Errorf("TestAddedReflectValue #%d\n got: %s want: %s", i, s, want)
66
-	}
67
-	i++
68
-
69
-	// Dump using a reflect.Value that is not exported.
70
-	changeKind(&v, true)
71
-	buf.Reset()
72
-	d.dump(v)
73
-	s = buf.String()
74
-	want = "(int8) <int8 Value>"
75
-	if s != want {
76
-		t.Errorf("TestAddedReflectValue #%d\n got: %s want: %s", i, s, want)
77
-	}
78
-	i++
79
-
80
-	// Formatter using a reflect.Value that is exported.
81
-	changeKind(&v, false)
82
-	buf2 := new(dummyFmtState)
83
-	f := formatState{value: v, cs: &Config, fs: buf2}
84
-	f.format(v)
85
-	s = buf2.String()
86
-	want = "5"
87
-	if s != want {
88
-		t.Errorf("TestAddedReflectValue #%d got: %s want: %s", i, s, want)
89
-	}
90
-	i++
91
-
92
-	// Formatter using a reflect.Value that is not exported.
93
-	changeKind(&v, true)
94
-	buf2.Reset()
95
-	f = formatState{value: v, cs: &Config, fs: buf2}
96
-	f.format(v)
97
-	s = buf2.String()
98
-	want = "<int8 Value>"
99
-	if s != want {
100
-		t.Errorf("TestAddedReflectValue #%d got: %s want: %s", i, s, want)
101
-	}
102
-}

+ 0
- 320
vendor/github.com/davecgh/go-spew/spew/spew_test.go View File

@@ -1,320 +0,0 @@
1
-/*
2
- * Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
3
- *
4
- * Permission to use, copy, modify, and distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
-package spew_test
18
-
19
-import (
20
-	"bytes"
21
-	"fmt"
22
-	"io/ioutil"
23
-	"os"
24
-	"testing"
25
-
26
-	"github.com/davecgh/go-spew/spew"
27
-)
28
-
29
-// spewFunc is used to identify which public function of the spew package or
30
-// ConfigState a test applies to.
31
-type spewFunc int
32
-
33
-const (
34
-	fCSFdump spewFunc = iota
35
-	fCSFprint
36
-	fCSFprintf
37
-	fCSFprintln
38
-	fCSPrint
39
-	fCSPrintln
40
-	fCSSdump
41
-	fCSSprint
42
-	fCSSprintf
43
-	fCSSprintln
44
-	fCSErrorf
45
-	fCSNewFormatter
46
-	fErrorf
47
-	fFprint
48
-	fFprintln
49
-	fPrint
50
-	fPrintln
51
-	fSdump
52
-	fSprint
53
-	fSprintf
54
-	fSprintln
55
-)
56
-
57
-// Map of spewFunc values to names for pretty printing.
58
-var spewFuncStrings = map[spewFunc]string{
59
-	fCSFdump:        "ConfigState.Fdump",
60
-	fCSFprint:       "ConfigState.Fprint",
61
-	fCSFprintf:      "ConfigState.Fprintf",
62
-	fCSFprintln:     "ConfigState.Fprintln",
63
-	fCSSdump:        "ConfigState.Sdump",
64
-	fCSPrint:        "ConfigState.Print",
65
-	fCSPrintln:      "ConfigState.Println",
66
-	fCSSprint:       "ConfigState.Sprint",
67
-	fCSSprintf:      "ConfigState.Sprintf",
68
-	fCSSprintln:     "ConfigState.Sprintln",
69
-	fCSErrorf:       "ConfigState.Errorf",
70
-	fCSNewFormatter: "ConfigState.NewFormatter",
71
-	fErrorf:         "spew.Errorf",
72
-	fFprint:         "spew.Fprint",
73
-	fFprintln:       "spew.Fprintln",
74
-	fPrint:          "spew.Print",
75
-	fPrintln:        "spew.Println",
76
-	fSdump:          "spew.Sdump",
77
-	fSprint:         "spew.Sprint",
78
-	fSprintf:        "spew.Sprintf",
79
-	fSprintln:       "spew.Sprintln",
80
-}
81
-
82
-func (f spewFunc) String() string {
83
-	if s, ok := spewFuncStrings[f]; ok {
84
-		return s
85
-	}
86
-	return fmt.Sprintf("Unknown spewFunc (%d)", int(f))
87
-}
88
-
89
-// spewTest is used to describe a test to be performed against the public
90
-// functions of the spew package or ConfigState.
91
-type spewTest struct {
92
-	cs     *spew.ConfigState
93
-	f      spewFunc
94
-	format string
95
-	in     interface{}
96
-	want   string
97
-}
98
-
99
-// spewTests houses the tests to be performed against the public functions of
100
-// the spew package and ConfigState.
101
-//
102
-// These tests are only intended to ensure the public functions are exercised
103
-// and are intentionally not exhaustive of types.  The exhaustive type
104
-// tests are handled in the dump and format tests.
105
-var spewTests []spewTest
106
-
107
-// redirStdout is a helper function to return the standard output from f as a
108
-// byte slice.
109
-func redirStdout(f func()) ([]byte, error) {
110
-	tempFile, err := ioutil.TempFile("", "ss-test")
111
-	if err != nil {
112
-		return nil, err
113
-	}
114
-	fileName := tempFile.Name()
115
-	defer os.Remove(fileName) // Ignore error
116
-
117
-	origStdout := os.Stdout
118
-	os.Stdout = tempFile
119
-	f()
120
-	os.Stdout = origStdout
121
-	tempFile.Close()
122
-
123
-	return ioutil.ReadFile(fileName)
124
-}
125
-
126
-func initSpewTests() {
127
-	// Config states with various settings.
128
-	scsDefault := spew.NewDefaultConfig()
129
-	scsNoMethods := &spew.ConfigState{Indent: " ", DisableMethods: true}
130
-	scsNoPmethods := &spew.ConfigState{Indent: " ", DisablePointerMethods: true}
131
-	scsMaxDepth := &spew.ConfigState{Indent: " ", MaxDepth: 1}
132
-	scsContinue := &spew.ConfigState{Indent: " ", ContinueOnMethod: true}
133
-	scsNoPtrAddr := &spew.ConfigState{DisablePointerAddresses: true}
134
-	scsNoCap := &spew.ConfigState{DisableCapacities: true}
135
-
136
-	// Variables for tests on types which implement Stringer interface with and
137
-	// without a pointer receiver.
138
-	ts := stringer("test")
139
-	tps := pstringer("test")
140
-
141
-	type ptrTester struct {
142
-		s *struct{}
143
-	}
144
-	tptr := &ptrTester{s: &struct{}{}}
145
-
146
-	// depthTester is used to test max depth handling for structs, array, slices
147
-	// and maps.
148
-	type depthTester struct {
149
-		ic    indirCir1
150
-		arr   [1]string
151
-		slice []string
152
-		m     map[string]int
153
-	}
154
-	dt := depthTester{indirCir1{nil}, [1]string{"arr"}, []string{"slice"},
155
-		map[string]int{"one": 1}}
156
-
157
-	// Variable for tests on types which implement error interface.
158
-	te := customError(10)
159
-
160
-	spewTests = []spewTest{
161
-		{scsDefault, fCSFdump, "", int8(127), "(int8) 127\n"},
162
-		{scsDefault, fCSFprint, "", int16(32767), "32767"},
163
-		{scsDefault, fCSFprintf, "%v", int32(2147483647), "2147483647"},
164
-		{scsDefault, fCSFprintln, "", int(2147483647), "2147483647\n"},
165
-		{scsDefault, fCSPrint, "", int64(9223372036854775807), "9223372036854775807"},
166
-		{scsDefault, fCSPrintln, "", uint8(255), "255\n"},
167
-		{scsDefault, fCSSdump, "", uint8(64), "(uint8) 64\n"},
168
-		{scsDefault, fCSSprint, "", complex(1, 2), "(1+2i)"},
169
-		{scsDefault, fCSSprintf, "%v", complex(float32(3), 4), "(3+4i)"},
170
-		{scsDefault, fCSSprintln, "", complex(float64(5), 6), "(5+6i)\n"},
171
-		{scsDefault, fCSErrorf, "%#v", uint16(65535), "(uint16)65535"},
172
-		{scsDefault, fCSNewFormatter, "%v", uint32(4294967295), "4294967295"},
173
-		{scsDefault, fErrorf, "%v", uint64(18446744073709551615), "18446744073709551615"},
174
-		{scsDefault, fFprint, "", float32(3.14), "3.14"},
175
-		{scsDefault, fFprintln, "", float64(6.28), "6.28\n"},
176
-		{scsDefault, fPrint, "", true, "true"},
177
-		{scsDefault, fPrintln, "", false, "false\n"},
178
-		{scsDefault, fSdump, "", complex(-10, -20), "(complex128) (-10-20i)\n"},
179
-		{scsDefault, fSprint, "", complex(-1, -2), "(-1-2i)"},
180
-		{scsDefault, fSprintf, "%v", complex(float32(-3), -4), "(-3-4i)"},
181
-		{scsDefault, fSprintln, "", complex(float64(-5), -6), "(-5-6i)\n"},
182
-		{scsNoMethods, fCSFprint, "", ts, "test"},
183
-		{scsNoMethods, fCSFprint, "", &ts, "<*>test"},
184
-		{scsNoMethods, fCSFprint, "", tps, "test"},
185
-		{scsNoMethods, fCSFprint, "", &tps, "<*>test"},
186
-		{scsNoPmethods, fCSFprint, "", ts, "stringer test"},
187
-		{scsNoPmethods, fCSFprint, "", &ts, "<*>stringer test"},
188
-		{scsNoPmethods, fCSFprint, "", tps, "test"},
189
-		{scsNoPmethods, fCSFprint, "", &tps, "<*>stringer test"},
190
-		{scsMaxDepth, fCSFprint, "", dt, "{{<max>} [<max>] [<max>] map[<max>]}"},
191
-		{scsMaxDepth, fCSFdump, "", dt, "(spew_test.depthTester) {\n" +
192
-			" ic: (spew_test.indirCir1) {\n  <max depth reached>\n },\n" +
193
-			" arr: ([1]string) (len=1 cap=1) {\n  <max depth reached>\n },\n" +
194
-			" slice: ([]string) (len=1 cap=1) {\n  <max depth reached>\n },\n" +
195
-			" m: (map[string]int) (len=1) {\n  <max depth reached>\n }\n}\n"},
196
-		{scsContinue, fCSFprint, "", ts, "(stringer test) test"},
197
-		{scsContinue, fCSFdump, "", ts, "(spew_test.stringer) " +
198
-			"(len=4) (stringer test) \"test\"\n"},
199
-		{scsContinue, fCSFprint, "", te, "(error: 10) 10"},
200
-		{scsContinue, fCSFdump, "", te, "(spew_test.customError) " +
201
-			"(error: 10) 10\n"},
202
-		{scsNoPtrAddr, fCSFprint, "", tptr, "<*>{<*>{}}"},
203
-		{scsNoPtrAddr, fCSSdump, "", tptr, "(*spew_test.ptrTester)({\ns: (*struct {})({\n})\n})\n"},
204
-		{scsNoCap, fCSSdump, "", make([]string, 0, 10), "([]string) {\n}\n"},
205
-		{scsNoCap, fCSSdump, "", make([]string, 1, 10), "([]string) (len=1) {\n(string) \"\"\n}\n"},
206
-	}
207
-}
208
-
209
-// TestSpew executes all of the tests described by spewTests.
210
-func TestSpew(t *testing.T) {
211
-	initSpewTests()
212
-
213
-	t.Logf("Running %d tests", len(spewTests))
214
-	for i, test := range spewTests {
215
-		buf := new(bytes.Buffer)
216
-		switch test.f {
217
-		case fCSFdump:
218
-			test.cs.Fdump(buf, test.in)
219
-
220
-		case fCSFprint:
221
-			test.cs.Fprint(buf, test.in)
222
-
223
-		case fCSFprintf:
224
-			test.cs.Fprintf(buf, test.format, test.in)
225
-
226
-		case fCSFprintln:
227
-			test.cs.Fprintln(buf, test.in)
228
-
229
-		case fCSPrint:
230
-			b, err := redirStdout(func() { test.cs.Print(test.in) })
231
-			if err != nil {
232
-				t.Errorf("%v #%d %v", test.f, i, err)
233
-				continue
234
-			}
235
-			buf.Write(b)
236
-
237
-		case fCSPrintln:
238
-			b, err := redirStdout(func() { test.cs.Println(test.in) })
239
-			if err != nil {
240
-				t.Errorf("%v #%d %v", test.f, i, err)
241
-				continue
242
-			}
243
-			buf.Write(b)
244
-
245
-		case fCSSdump:
246
-			str := test.cs.Sdump(test.in)
247
-			buf.WriteString(str)
248
-
249
-		case fCSSprint:
250
-			str := test.cs.Sprint(test.in)
251
-			buf.WriteString(str)
252
-
253
-		case fCSSprintf:
254
-			str := test.cs.Sprintf(test.format, test.in)
255
-			buf.WriteString(str)
256
-
257
-		case fCSSprintln:
258
-			str := test.cs.Sprintln(test.in)
259
-			buf.WriteString(str)
260
-
261
-		case fCSErrorf:
262
-			err := test.cs.Errorf(test.format, test.in)
263
-			buf.WriteString(err.Error())
264
-
265
-		case fCSNewFormatter:
266
-			fmt.Fprintf(buf, test.format, test.cs.NewFormatter(test.in))
267
-
268
-		case fErrorf:
269
-			err := spew.Errorf(test.format, test.in)
270
-			buf.WriteString(err.Error())
271
-
272
-		case fFprint:
273
-			spew.Fprint(buf, test.in)
274
-
275
-		case fFprintln:
276
-			spew.Fprintln(buf, test.in)
277
-
278
-		case fPrint:
279
-			b, err := redirStdout(func() { spew.Print(test.in) })
280
-			if err != nil {
281
-				t.Errorf("%v #%d %v", test.f, i, err)
282
-				continue
283
-			}
284
-			buf.Write(b)
285
-
286
-		case fPrintln:
287
-			b, err := redirStdout(func() { spew.Println(test.in) })
288
-			if err != nil {
289
-				t.Errorf("%v #%d %v", test.f, i, err)
290
-				continue
291
-			}
292
-			buf.Write(b)
293
-
294
-		case fSdump:
295
-			str := spew.Sdump(test.in)
296
-			buf.WriteString(str)
297
-
298
-		case fSprint:
299
-			str := spew.Sprint(test.in)
300
-			buf.WriteString(str)
301
-
302
-		case fSprintf:
303
-			str := spew.Sprintf(test.format, test.in)
304
-			buf.WriteString(str)
305
-
306
-		case fSprintln:
307
-			str := spew.Sprintln(test.in)
308
-			buf.WriteString(str)
309
-