|
1 | 1 | package sqlite |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
4 | 5 | "context" |
5 | 6 | "database/sql" |
6 | 7 | "fmt" |
| 8 | + "io/ioutil" |
7 | 9 | "math/rand" |
8 | 10 | "os" |
| 11 | + "strings" |
9 | 12 | "testing" |
10 | 13 |
|
11 | 14 | "github.com/sirupsen/logrus" |
@@ -58,6 +61,34 @@ func TestConfigMapLoader(t *testing.T) { |
58 | 61 | require.NoError(t, loader.Populate()) |
59 | 62 | } |
60 | 63 |
|
| 64 | +func TestReplaceCycle(t *testing.T) { |
| 65 | + logrus.SetLevel(logrus.DebugLevel) |
| 66 | + |
| 67 | + db, cleanup := CreateTestDb(t) |
| 68 | + defer cleanup() |
| 69 | + store, err := NewSQLLiteLoader(db) |
| 70 | + require.NoError(t, err) |
| 71 | + |
| 72 | + path := "../../configmap.example.yaml" |
| 73 | + cmap, err := ioutil.ReadFile(path) |
| 74 | + |
| 75 | + require.NoError(t, err, "unable to load configmap from file %s", path) |
| 76 | + |
| 77 | + // Make etcdoperator.v0.9.0 in the example replace 0.9.2 to create a loop |
| 78 | + sReader := strings.NewReader(string(bytes.Replace(cmap, |
| 79 | + []byte("replaces: etcdoperator.v0.6.1"), |
| 80 | + []byte("replaces: etcdoperator.v0.9.2"), 1))) |
| 81 | + |
| 82 | + decoder := yaml.NewYAMLOrJSONDecoder(sReader, 30) |
| 83 | + manifest := v1.ConfigMap{} |
| 84 | + err = decoder.Decode(&manifest) |
| 85 | + require.NoError(t, err, "could not decode contents of file %s into configmap", path) |
| 86 | + |
| 87 | + loader := NewSQLLoaderForConfigMap(store, manifest) |
| 88 | + err = loader.Populate() |
| 89 | + require.Error(t, err, "Cycle detected, etcdoperator.v0.9.0 replaces etcdoperator.v0.9.2") |
| 90 | +} |
| 91 | + |
61 | 92 | func TestQuerierForConfigmap(t *testing.T) { |
62 | 93 | db, cleanup := CreateTestDb(t) |
63 | 94 | defer cleanup() |
|
0 commit comments