(t *testing.T)
| 112 | } |
| 113 | |
| 114 | func TestConfigLoadTOML(t *testing.T) { |
| 115 | tests := []struct { |
| 116 | name string |
| 117 | |
| 118 | toml string |
| 119 | |
| 120 | cfgFn func(*Config) |
| 121 | }{ |
| 122 | { |
| 123 | name: "defaults-empty", |
| 124 | |
| 125 | toml: "", |
| 126 | |
| 127 | cfgFn: func(cfg *Config) {}, |
| 128 | }, |
| 129 | { |
| 130 | name: "service-acme-example", |
| 131 | |
| 132 | toml: heredoc.Doc(` |
| 133 | [lcl-host] |
| 134 | realm-apid = "localhost" |
| 135 | |
| 136 | [org] |
| 137 | apid = "test-org" |
| 138 | |
| 139 | [service] |
| 140 | apid = "test-service" |
| 141 | category = "ruby" |
| 142 | cert-style = "acme" |
| 143 | `), |
| 144 | |
| 145 | cfgFn: func(cfg *Config) { |
| 146 | cfg.Lcl.RealmAPID = "localhost" |
| 147 | cfg.Org.APID = "test-org" |
| 148 | cfg.Service.APID = "test-service" |
| 149 | cfg.Service.Category = "ruby" |
| 150 | cfg.Service.CertStyle = "acme" |
| 151 | }, |
| 152 | }, |
| 153 | } |
| 154 | |
| 155 | for _, test := range tests { |
| 156 | t.Run(test.name, func(t *testing.T) { |
| 157 | fs := fstest.MapFS{ |
| 158 | "anchor.toml": &fstest.MapFile{ |
| 159 | Data: []byte(test.toml), |
| 160 | }, |
| 161 | } |
| 162 | |
| 163 | cfg := defaultConfig() |
| 164 | if err := cfg.loadTOML(fs); err != nil { |
| 165 | t.Fatal(err) |
| 166 | } |
| 167 | |
| 168 | expected := defaultConfig() |
| 169 | test.cfgFn(expected) |
| 170 | |
| 171 | if diff := deep.Equal(expected, cfg.Via.TOML); diff != nil { |
nothing calls this directly
no test coverage detected