(t *testing.T)
| 142 | } |
| 143 | |
| 144 | func TestSetDefault(t *testing.T) { |
| 145 | file := getTempFile(t) |
| 146 | viper.SetConfigFile(file.Name()) |
| 147 | config := &Config{} |
| 148 | |
| 149 | err := config.Add(App{ |
| 150 | Name: "test1", |
| 151 | AccessKey: "test1", |
| 152 | AccessSecretKey: "test1", |
| 153 | ChatURL: DefaultChatEdgeURL, |
| 154 | }) |
| 155 | require.NoError(t, err) |
| 156 | |
| 157 | err = config.Add(App{ |
| 158 | Name: "test2", |
| 159 | AccessKey: "test2", |
| 160 | AccessSecretKey: "test2", |
| 161 | ChatURL: DefaultChatEdgeURL, |
| 162 | }) |
| 163 | require.NoError(t, err) |
| 164 | |
| 165 | require.True(t, config.Default == "test1") |
| 166 | |
| 167 | err = config.SetDefault("test2") |
| 168 | require.NoError(t, err) |
| 169 | |
| 170 | require.True(t, config.Default == "test2") |
| 171 | |
| 172 | expected := ` |
| 173 | apps: |
| 174 | - name: test1 |
| 175 | access-key: test1 |
| 176 | access-secret-key: test1 |
| 177 | chat-url: https://chat.stream-io-api.com |
| 178 | - name: test2 |
| 179 | access-key: test2 |
| 180 | access-secret-key: test2 |
| 181 | chat-url: https://chat.stream-io-api.com |
| 182 | default: test2 |
| 183 | ` |
| 184 | |
| 185 | content, err := os.ReadFile(file.Name()) |
| 186 | require.NoError(t, err) |
| 187 | require.Equal(t, getNormalizedString(expected), getNormalizedString(string(content))) |
| 188 | } |
| 189 | |
| 190 | func getNormalizedString(s string) string { |
| 191 | noSpace := strings.Replace(s, " ", "", -1) |
nothing calls this directly
no test coverage detected